From 4f44d57a6a13c2aeb9955dd99dcabf62e1897729 Mon Sep 17 00:00:00 2001 From: lan Date: Tue, 27 Dec 2022 22:45:44 +0800 Subject: [PATCH] =?UTF-8?q?update:=E5=88=A0=E9=99=A4=E8=BF=87=E6=9C=9F?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=A4=B9=E7=9A=84=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 2 +- storage.py | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/main.py b/main.py index c26526d..c6ec933 100644 --- a/main.py +++ b/main.py @@ -98,7 +98,7 @@ async def admin_delete(code: str, s: AsyncSession = Depends(get_session)): async def config(s: AsyncSession = Depends(get_session)): # 从数据库获取系统配置 data = (await s.execute(select(Values).filter(Values.key == 'config'))).scalar_one_or_none() - return {'detail': '获取成功', 'data': data.value} + return {'detail': '获取成功', 'data': data.value if data else {}} @app.get('/') diff --git a/storage.py b/storage.py index 5ee79f2..c9c587e 100644 --- a/storage.py +++ b/storage.py @@ -57,14 +57,14 @@ class FileSystemStorage: tasks = [self.delete_file(text) for text in texts] await asyncio.gather(*tasks) - async def judge_delete_folder(self, filepath): - currpath = os.path.dirname(filepath) - if os.listdir(currpath): - return - while str(currpath) != (str(os.path.join(self.DATA_ROOT, 'upload'))): - if not os.listdir(currpath): - os.rmdir(os.path.abspath(currpath)) - currpath = os.path.dirname(currpath) + def judge_delete_folder(self, filepath): + current = filepath.parent + while current != self.DATA_ROOT: + if not list(current.iterdir()): + os.rmdir(current) + current = current.parent + else: + break STORAGE_ENGINE = {