fix(jfile): 移除文件清理的前缀限制,清理所有过期文件
- 移除 FileCleaner 的前缀过滤逻辑 - 清理 files 目录下所有超过保留时间的文件 - 修复 split_ 前缀文件未被清理的问题
This commit is contained in:
parent
c27fbb19c2
commit
173f788ab7
@ -17,9 +17,8 @@ app.mount("/files", StaticFiles(directory="files"), name="files")
|
||||
|
||||
# 注册文件定时清理任务
|
||||
save_dir = "files"
|
||||
file_prefix = "upscaled_"
|
||||
retention_hours = settings.file_retention_hours
|
||||
cleaner = FileCleaner(save_dir, file_prefix, retention_hours)
|
||||
cleaner = FileCleaner(save_dir, retention_hours)
|
||||
|
||||
@app.on_event("startup")
|
||||
async def startup_event():
|
||||
|
||||
@ -3,9 +3,8 @@ import asyncio
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
class FileCleaner:
|
||||
def __init__(self, target_dir, prefix, retention_hours):
|
||||
def __init__(self, target_dir, retention_hours):
|
||||
self.target_dir = target_dir
|
||||
self.prefix = prefix
|
||||
self.retention_hours = retention_hours
|
||||
|
||||
async def periodic_cleanup(self):
|
||||
@ -21,9 +20,10 @@ class FileCleaner:
|
||||
return
|
||||
cutoff_time = datetime.now() - timedelta(hours=self.retention_hours)
|
||||
for filename in os.listdir(self.target_dir):
|
||||
if not filename.startswith(self.prefix):
|
||||
continue
|
||||
file_path = os.path.join(self.target_dir, filename)
|
||||
# 跳过目录
|
||||
if os.path.isdir(file_path):
|
||||
continue
|
||||
file_time = datetime.fromtimestamp(os.path.getctime(file_path))
|
||||
if file_time < cutoff_time:
|
||||
try:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user