✨ feat(core): 引入垃圾回收管理功能

* 新增垃圾回收管理逻辑,支持批量管理与清理功能
* 在数据模型中增加过期时间与保留天数验证逻辑
* 在 FileService 中集成垃圾回收管理模块
* 调整任务调度逻辑以适配新的垃圾回收规则
* 为垃圾回收功能补充相应的单元测试覆盖
This commit is contained in:
orion committed 2026-09-18 09:39:27 +08:00
1 parent 356f23bae1
commit b10113e5ab
6 files changed
+388 -46

No files matched your search

+24 -3
View File
@@ -1,7 +1,7 @@
import datetime
from typing import Any, Optional, Union
from typing import Annotated, Any, Literal, Optional, Union
from pydantic import BaseModel
from pydantic import BaseModel, Field, model_validator
class IDData(BaseModel):
@@ -59,7 +59,28 @@ class BatchFilePolicyActionData(BaseModel):
class TrashRetentionData(BaseModel):
id: int
retentionDays: int
retentionDays: Optional[int] = Field(default=None, ge=0, le=365)
expiresAt: Optional[datetime.datetime] = None
@model_validator(mode="after")
def one_deadline(self):
if (self.retentionDays is None) == (self.expiresAt is None):
raise ValueError("请选择保留天数或自动清理时间")
return self
class BatchTrashData(BaseModel):
ids: list[Annotated[int, Field(strict=True, gt=0)]] = Field(min_length=1, max_length=100)
action: Literal["restore", "purge", "retention"]
retentionDays: Optional[int] = Field(default=None, ge=0, le=365)
expiresAt: Optional[datetime.datetime] = None
@model_validator(mode="after")
def validate_action_payload(self):
provided = int(self.retentionDays is not None) + int(self.expiresAt is not None)
if (self.action == "retention" and provided != 1) or (self.action != "retention" and provided):
raise ValueError("清理时间参数与操作不匹配")
return self
class FileMetadataData(BaseModel):