File tree Expand file tree Collapse file tree 1 file changed +7
-1
lines changed Expand file tree Collapse file tree 1 file changed +7
-1
lines changed Original file line number Diff line number Diff line change 3
3
# @File : tasks.py
4
4
# @Software: PyCharm
5
5
import asyncio
6
+ import os
6
7
7
8
from tortoise .expressions import Q
8
9
9
10
from apps .base .models import FileCodes
10
11
from apps .base .utils import ip_limit
11
- from core .settings import settings
12
+ from core .settings import settings , data_root
12
13
from core .storage import FileStorageInterface , storages
13
14
from core .utils import get_now
14
15
@@ -17,6 +18,11 @@ async def delete_expire_files():
17
18
file_storage : FileStorageInterface = storages [settings .file_storage ]()
18
19
while True :
19
20
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 )
20
26
await ip_limit ['error' ].remove_expired_ip ()
21
27
await ip_limit ['upload' ].remove_expired_ip ()
22
28
expire_data = await FileCodes .filter (Q (expired_at__lt = await get_now ()) | Q (expired_count = 0 )).all ()
You can’t perform that action at this time.
0 commit comments