Skip to content

Commit 2bef407

Browse files
author
Lan
committed
feat:#183
1 parent 6c2f2ca commit 2bef407

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

core/tasks.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
# @File : tasks.py
44
# @Software: PyCharm
55
import asyncio
6+
import os
67

78
from tortoise.expressions import Q
89

910
from apps.base.models import FileCodes
1011
from apps.base.utils import ip_limit
11-
from core.settings import settings
12+
from core.settings import settings, data_root
1213
from core.storage import FileStorageInterface, storages
1314
from core.utils import get_now
1415

@@ -17,6 +18,11 @@ async def delete_expire_files():
1718
file_storage: FileStorageInterface = storages[settings.file_storage]()
1819
while True:
1920
try:
21+
# 遍历 share目录下的所有文件夹,删除空的文件夹,并判断父目录是否为空,如果为空也删除
22+
if settings.file_storage == 'local':
23+
for root, dirs, files in os.walk(f"{data_root}/share/data"):
24+
if not dirs and not files:
25+
os.rmdir(root)
2026
await ip_limit['error'].remove_expired_ip()
2127
await ip_limit['upload'].remove_expired_ip()
2228
expire_data = await FileCodes.filter(Q(expired_at__lt=await get_now()) | Q(expired_count=0)).all()

0 commit comments

Comments
 (0)