From 40663b6ce70c2873f827cfb9284759c8121e8ba6 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Fri, 26 Jul 2024 22:04:50 +0800 Subject: [PATCH] fix local --- app/api/endpoints/storage.py | 11 ++++++----- app/db/systemconfig_oper.py | 5 ----- app/modules/filemanager/__init__.py | 4 ++-- app/modules/filemanager/storage/local.py | 2 +- app/utils/system.py | 7 ++++--- 5 files changed, 13 insertions(+), 16 deletions(-) diff --git a/app/api/endpoints/storage.py b/app/api/endpoints/storage.py index 5d0497e4..1497bc54 100644 --- a/app/api/endpoints/storage.py +++ b/app/api/endpoints/storage.py @@ -51,10 +51,11 @@ def list(fileitem: schemas.FileItem, :return: 所有目录和文件 """ file_list = StorageChain().list_files(fileitem) - if sort == "name": - file_list.sort(key=lambda x: x.name) - else: - file_list.sort(key=lambda x: x.modify_time, reverse=True) + if file_list: + if sort == "name": + file_list.sort(key=lambda x: x.name) + else: + file_list.sort(key=lambda x: x.modify_time, reverse=True) return file_list @@ -90,7 +91,7 @@ def delete(fileitem: schemas.FileItem, return schemas.Response(success=False) -@router.get("/download", summary="下载文件") +@router.post("/download", summary="下载文件") def download(fileitem: schemas.FileItem, _: schemas.TokenPayload = Depends(verify_uri_token)) -> Any: """ diff --git a/app/db/systemconfig_oper.py b/app/db/systemconfig_oper.py index 9b73d233..92af214a 100644 --- a/app/db/systemconfig_oper.py +++ b/app/db/systemconfig_oper.py @@ -31,11 +31,6 @@ class SystemConfigOper(DbOper, metaclass=Singleton): key = key.value # 更新内存 self.__SYSTEMCONF[key] = value - # 写入数据库 - if ObjectUtils.is_obj(value): - value = json.dumps(value) - elif value is None: - value = '' conf = SystemConfig.get_by_key(self._db, key) if conf: if value: diff --git a/app/modules/filemanager/__init__.py b/app/modules/filemanager/__init__.py index 368164f2..f785274a 100644 --- a/app/modules/filemanager/__init__.py +++ b/app/modules/filemanager/__init__.py @@ -38,7 +38,7 @@ class FileManagerModule(_ModuleBase): def init_module(self) -> None: # 加载模块 self._storage_schemas = ModuleHelper.load('app.modules.filemanager.storage', - filter_func=lambda _, obj: hasattr(obj, 'schema')) + filter_func=lambda _, obj: hasattr(obj, 'schema') and obj.schema) @staticmethod def get_name() -> str: @@ -264,7 +264,7 @@ class FileManagerModule(_ModuleBase): 获取存储操作对象 """ for storage_schema in self._storage_schemas: - if storage_schema.schema == _storage: + if storage_schema.schema and storage_schema.schema.value == _storage: return storage_schema() return None diff --git a/app/modules/filemanager/storage/local.py b/app/modules/filemanager/storage/local.py index 69f1f965..26437811 100644 --- a/app/modules/filemanager/storage/local.py +++ b/app/modules/filemanager/storage/local.py @@ -101,7 +101,7 @@ class LocalStorage(StorageBase): ret_items.append(self.__get_diritem(item)) # 遍历所有文件,不含子目录 - for item in SystemUtils.list_sub_all(path_obj): + for item in SystemUtils.list_sub_file(path_obj): ret_items.append(self.__get_fileitem(item)) return ret_items diff --git a/app/utils/system.py b/app/utils/system.py index caba5555..59513cfd 100644 --- a/app/utils/system.py +++ b/app/utils/system.py @@ -241,7 +241,7 @@ class SystemUtils: return dirs @staticmethod - def list_sub_all(directory: Path) -> List[Path]: + def list_sub_file(directory: Path) -> List[Path]: """ 列出当前目录下的所有子目录和文件(不递归) """ @@ -249,13 +249,14 @@ class SystemUtils: return [] if directory.is_file(): - return [] + return [directory] items = [] # 遍历目录 for path in directory.iterdir(): - items.append(path) + if path.is_file(): + items.append(path) return items