(
self,
file_code: FileCodes,
action: str,
now: datetime,
download_limit: Optional[int],
)
| 1296 | return int((end - start).total_seconds()) |
| 1297 | |
| 1298 | def _build_policy_action_update( |
| 1299 | self, |
| 1300 | file_code: FileCodes, |
| 1301 | action: str, |
| 1302 | now: datetime, |
| 1303 | download_limit: Optional[int], |
| 1304 | ) -> dict[str, Any]: |
| 1305 | if action == "extend_24h": |
| 1306 | return {"expired_at": self._extended_expiration(file_code.expired_at, now, hours=24)} |
| 1307 | if action == "extend_7d": |
| 1308 | return {"expired_at": self._extended_expiration(file_code.expired_at, now, days=7)} |
| 1309 | if action == "make_permanent": |
| 1310 | return {"expired_at": None, "expired_count": -1} |
| 1311 | if action == "reset_download_limit": |
| 1312 | next_limit = download_limit if download_limit is not None else 5 |
| 1313 | if next_limit < 1: |
| 1314 | raise HTTPException(status_code=400, detail="取件次数必须大于 0") |
| 1315 | return {"expired_count": next_limit} |
| 1316 | |
| 1317 | raise HTTPException(status_code=400, detail="不支持的策略动作") |
| 1318 | |
| 1319 | def _extended_expiration( |
| 1320 | self, |
no test coverage detected