调整文件删除方式

This commit is contained in:
veoco
2022-12-13 14:18:02 +08:00
parent dc353d624f
commit 9a190484bf
2 changed files with 19 additions and 15 deletions
+6 -9
View File
@@ -46,16 +46,13 @@ class FileSystemStorage:
filepath = await self.get_filepath(text)
await asyncio.to_thread(self._save, filepath, file.file)
async def delete_file(self, file):
# 是文件就删除
if file['type'] != 'text':
filepath = self.DATA_ROOT / file['text'].lstrip(self.STATIC_URL + '/')
await asyncio.to_thread(os.remove, filepath)
async def delete_file(self, text: str):
filepath = await self.get_filepath(text)
await asyncio.to_thread(os.remove, filepath)
async def delete_files(self, files):
for file in files:
if file['type'] != 'text':
await self.delete_file(file)
async def delete_files(self, texts):
tasks = [self.delete_file(text) for text in texts]
await asyncio.gather(*tasks)
STORAGE_ENGINE = {