✨ 配置回收站默认保留期
This commit is contained in:
1 parent
5427c187d4
commit
07e362d341
4 files changed
+76
-8
No files matched your search
+36
-2
@@ -80,7 +80,7 @@ class FileService:
|
||||
"code",
|
||||
}
|
||||
|
||||
TRASH_DEFAULT_RETENTION_DAYS = 7
|
||||
TRASH_DEFAULT_RETENTION_DAYS = 30
|
||||
TRASH_MAX_RETENTION_DAYS = 365
|
||||
|
||||
def __init__(self):
|
||||
@@ -118,7 +118,9 @@ class FileService:
|
||||
@classmethod
|
||||
def _trash_expiry(cls, now: datetime, retention_days: Optional[int]):
|
||||
if retention_days is None:
|
||||
retention_days = cls.TRASH_DEFAULT_RETENTION_DAYS
|
||||
retention_days = int(
|
||||
getattr(settings, "trashRetentionDays", cls.TRASH_DEFAULT_RETENTION_DAYS)
|
||||
)
|
||||
if retention_days == 0:
|
||||
return None
|
||||
if not 1 <= retention_days <= cls.TRASH_MAX_RETENTION_DAYS:
|
||||
@@ -1726,6 +1728,7 @@ class FileService:
|
||||
class ConfigService:
|
||||
INT_FIELDS = {
|
||||
"adminSessionExpire",
|
||||
"trashRetentionDays",
|
||||
"enableChunk",
|
||||
"errorCount",
|
||||
"errorMinute",
|
||||
@@ -1804,6 +1807,28 @@ class ConfigService:
|
||||
)
|
||||
next_config["adminSessionExpire"] = session_expire
|
||||
|
||||
try:
|
||||
trash_retention_days = int(
|
||||
next_config.get("trashRetentionDays", FileService.TRASH_DEFAULT_RETENTION_DAYS)
|
||||
)
|
||||
except (TypeError, ValueError):
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail="trashRetentionDays 配置值格式错误",
|
||||
)
|
||||
if not 1 <= trash_retention_days <= FileService.TRASH_MAX_RETENTION_DAYS:
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail="trashRetentionDays 必须是 1 到 365 个整天",
|
||||
)
|
||||
next_config["trashRetentionDays"] = trash_retention_days
|
||||
retention_changed = (
|
||||
"trashRetentionDays" in update_data
|
||||
and trash_retention_days != int(
|
||||
current_config.get("trashRetentionDays", FileService.TRASH_DEFAULT_RETENTION_DAYS)
|
||||
)
|
||||
)
|
||||
|
||||
if int(next_config.get("storageLimit", 0)) < 0:
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
@@ -1816,6 +1841,15 @@ class ConfigService:
|
||||
await KeyValue.update_or_create(key="settings", defaults={"value": next_config})
|
||||
await refresh_settings()
|
||||
|
||||
if retention_changed:
|
||||
retention_now = await get_now()
|
||||
retention_expiry = FileService._trash_expiry(retention_now, trash_retention_days)
|
||||
await FileCodes.filter(
|
||||
is_trashed=True,
|
||||
trash_purged_at__isnull=True,
|
||||
trash_expires_at__isnull=False,
|
||||
).update(trash_expires_at=retention_expiry)
|
||||
|
||||
|
||||
class LocalFileService:
|
||||
async def list_files(self):
|
||||
|
||||
Reference in new issue
Block a user