update:删除过期文件夹的方式

This commit is contained in:
lan
2022-12-27 22:45:44 +08:00
parent 2269bd99e4
commit 4f44d57a6a
2 changed files with 9 additions and 9 deletions
+1 -1
View File
@@ -98,7 +98,7 @@ async def admin_delete(code: str, s: AsyncSession = Depends(get_session)):
async def config(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() 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('/') @app.get('/')
+8 -8
View File
@@ -57,14 +57,14 @@ class FileSystemStorage:
tasks = [self.delete_file(text) for text in texts] tasks = [self.delete_file(text) for text in texts]
await asyncio.gather(*tasks) await asyncio.gather(*tasks)
async def judge_delete_folder(self, filepath): def judge_delete_folder(self, filepath):
currpath = os.path.dirname(filepath) current = filepath.parent
if os.listdir(currpath): while current != self.DATA_ROOT:
return if not list(current.iterdir()):
while str(currpath) != (str(os.path.join(self.DATA_ROOT, 'upload'))): os.rmdir(current)
if not os.listdir(currpath): current = current.parent
os.rmdir(os.path.abspath(currpath)) else:
currpath = os.path.dirname(currpath) break
STORAGE_ENGINE = { STORAGE_ENGINE = {