Skip to content

Commit

Permalink
fix(auth): resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
InfinityPacer committed Oct 19, 2024
2 parents 1e781ba + 616b15e commit c7b2778
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 10 deletions.
1 change: 1 addition & 0 deletions app/api/endpoints/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ async def login_access_token(
),
token_type="bearer",
super_user=user_or_message.is_superuser,
user_id=user_or_message.id,
user_name=user_or_message.name,
avatar=user_or_message.avatar,
level=level
Expand Down
6 changes: 3 additions & 3 deletions app/api/endpoints/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ def save(name: str,


@router.post("/list", summary="所有目录和文件", response_model=List[schemas.FileItem])
def list(fileitem: schemas.FileItem,
sort: str = 'updated_at',
_: User = Depends(get_current_active_superuser)) -> Any:
def list_files(fileitem: schemas.FileItem,
sort: str = 'updated_at',
_: User = Depends(get_current_active_superuser)) -> Any:
"""
查询当前目录下所有目录和文件
:param fileitem: 文件项
Expand Down
6 changes: 3 additions & 3 deletions app/api/endpoints/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def set_config(key: str, value: Union[list, dict, bool, int, str] = None,


@router.delete("/id/{user_id}", summary="删除用户", response_model=schemas.Response)
def delete_user_from_user_id(
def delete_user_by_id(
*,
db: Session = Depends(get_db),
user_id: int,
Expand All @@ -191,7 +191,7 @@ def delete_user_from_user_id(


@router.delete("/name/{user_name}", summary="删除用户", response_model=schemas.Response)
def delete_user_from_user_id(
def delete_user_by_name(
*,
db: Session = Depends(get_db),
user_name: str,
Expand All @@ -208,7 +208,7 @@ def delete_user_from_user_id(


@router.get("/{username}", summary="用户详情", response_model=schemas.User)
def read_user_by_id(
def read_user_by_name(
username: str,
current_user: User = Depends(get_current_active_user),
db: Session = Depends(get_db),
Expand Down
4 changes: 3 additions & 1 deletion app/modules/filemanager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,9 @@ def media_files(self, mediainfo: MediaInfo) -> List[FileItem]:
continue
media_files = self.list_files(fileitem, True)
if media_files:
ret_fileitems.extend(media_files)
for media_file in media_files:
if f".{media_file.extension.lower()}" in settings.RMT_MEDIAEXT:
ret_fileitems.append(media_file)
return ret_fileitems

def media_exists(self, mediainfo: MediaInfo, **kwargs) -> Optional[ExistMediaInfo]:
Expand Down
16 changes: 14 additions & 2 deletions app/modules/filemanager/storages/alipan.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ def check_login(self, ck: str, t: str) -> Optional[Tuple[dict, str]]:
"updateTime": time.time(),
})
self.__update_params(data)
self.__update_drives()
self.__init_aligo()
except Exception as e:
return {}, f"bizExt 解码失败:{str(e)}"
Expand All @@ -181,6 +182,17 @@ def user_info(self) -> dict:
"""
return self.aligo.get_user()

def __update_drives(self):
"""
更新用户存储根目录
"""
drivers = self.aligo.list_my_drives()
for driver in drivers:
if driver.category == "resource":
self.__update_params({"resourceDriveId": driver.drive_id})
elif driver.category == "backup":
self.__update_params({"backDriveId": driver.drive_id})

def __get_fileitem(self, fileinfo: BaseFile, parent: str = "/") -> schemas.FileItem:
"""
获取文件信息
Expand Down Expand Up @@ -231,7 +243,7 @@ def list(self, fileitem: schemas.FileItem = None) -> List[schemas.FileItem]:
return [
schemas.FileItem(
storage=self.schema.value,
fileid=fileitem.fileid,
fileid="root",
drive_id=self.__auth_params.get("resourceDriveId"),
parent_fileid="root",
type="dir",
Expand All @@ -241,7 +253,7 @@ def list(self, fileitem: schemas.FileItem = None) -> List[schemas.FileItem]:
),
schemas.FileItem(
storage=self.schema.value,
fileid=fileitem.fileid,
fileid="root",
drive_id=self.__auth_params.get("backDriveId"),
parent_fileid="root",
type="dir",
Expand Down
2 changes: 1 addition & 1 deletion app/modules/filemanager/storages/rclone.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ def usage(self) -> Optional[schemas.StorageUsage]:
ret = subprocess.run(
[
'rclone', 'about',
'MP:/', '--json'
'/', '--json'
],
capture_output=True,
startupinfo=self.__get_hidden_shell()
Expand Down
2 changes: 2 additions & 0 deletions app/schemas/token.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class Token(BaseModel):
token_type: str
# 超级用户
super_user: bool
# 用户ID
user_id: int
# 用户名
user_name: str
# 头像
Expand Down

0 comments on commit c7b2778

Please sign in to comment.