()
| 18 | |
| 19 | |
| 20 | async def delete_expire_files(): |
| 21 | while True: |
| 22 | try: |
| 23 | await refresh_settings() |
| 24 | file_storage: FileStorageInterface = storages[settings.file_storage]() |
| 25 | # 遍历 share目录下的所有文件夹,删除空的文件夹,并判断父目录是否为空,如果为空也删除 |
| 26 | if settings.file_storage == "local": |
| 27 | for root, dirs, files in os.walk(f"{data_root}/share/data"): |
| 28 | if not dirs and not files: |
| 29 | os.rmdir(root) |
| 30 | await ip_limit["error"].remove_expired_ip() |
| 31 | await ip_limit["upload"].remove_expired_ip() |
| 32 | expire_data = await FileCodes.filter( |
| 33 | Q(expired_at__lt=await get_now()) | Q(expired_count=0) |
| 34 | ).all() |
| 35 | for exp in expire_data: |
| 36 | try: |
| 37 | await file_storage.delete_file(exp) |
| 38 | except Exception as e: |
| 39 | logging.error(f"删除过期文件失败 code={exp.code}: {e}") |
| 40 | try: |
| 41 | await exp.delete() |
| 42 | except Exception as e: |
| 43 | logging.error(f"删除记录失败 code={exp.code}: {e}") |
| 44 | except Exception as e: |
| 45 | logging.error(e) |
| 46 | finally: |
| 47 | await asyncio.sleep(600) |
| 48 | |
| 49 | |
| 50 | async def clean_incomplete_uploads(): |
no test coverage detected