fix: 皮肤包删除后被自动迁移逻辑复活,IPA 下载连击刷屏操作日志
_migrate_old_themes 之前每次 load_config() 都会重跑,只要证书仍引用某皮肤 且旧版 themes 目录还在,删除后会被立即重新生成;现改为仅首次执行一次并 在 config.json 中打标记跳过后续调用。 打包历史下载 IPA 按钮此前无连击防护,前端加 in-flight 禁用态,后端对同一 用户同一任务的下载操作日志增加 5 秒去重,避免连击刷屏审计日志。 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
84a2d3db01
commit
c17b7d5ad9
@@ -3,6 +3,7 @@ import os
|
||||
import json
|
||||
import shutil
|
||||
import tempfile
|
||||
import time
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
from typing import List
|
||||
@@ -18,6 +19,10 @@ from ..deps import get_current_user
|
||||
|
||||
router = APIRouter(prefix="/api/tasks", tags=["tasks"], dependencies=[Depends(get_current_user)])
|
||||
|
||||
# 同一用户对同一任务连击下载按钮时,短时间内只记一次操作日志,避免刷屏
|
||||
_DOWNLOAD_LOG_DEBOUNCE_SECONDS = 5
|
||||
_recent_download_logs: dict[str, float] = {}
|
||||
|
||||
|
||||
@router.post("", response_model=TaskResponse)
|
||||
async def create_task(task: TaskCreate, request: Request, user: dict = Depends(get_current_user), db: Session = Depends(get_db)):
|
||||
@@ -276,11 +281,22 @@ async def get_download_link(task_id: str, request: Request, user: dict = Depends
|
||||
)
|
||||
except (json.JSONDecodeError, DistributionError) as exc:
|
||||
raise HTTPException(status_code=502, detail=f"生成下载链接失败:{exc}") from exc
|
||||
from ..services.audit_log import record_operation
|
||||
record_operation(db, user, "ipa_download_requested", request=request, task=task,
|
||||
resource_type="ipa", resource_name=task.oss_url,
|
||||
detail={"controlled": True})
|
||||
db.commit()
|
||||
|
||||
debounce_key = f"{user.get('username')}:{task_id}"
|
||||
now = time.monotonic()
|
||||
last = _recent_download_logs.get(debounce_key)
|
||||
if last is None or now - last > _DOWNLOAD_LOG_DEBOUNCE_SECONDS:
|
||||
if len(_recent_download_logs) > 500:
|
||||
cutoff = now - _DOWNLOAD_LOG_DEBOUNCE_SECONDS
|
||||
for key, ts in list(_recent_download_logs.items()):
|
||||
if ts < cutoff:
|
||||
del _recent_download_logs[key]
|
||||
_recent_download_logs[debounce_key] = now
|
||||
from ..services.audit_log import record_operation
|
||||
record_operation(db, user, "ipa_download_requested", request=request, task=task,
|
||||
resource_type="ipa", resource_name=task.oss_url,
|
||||
detail={"controlled": True})
|
||||
db.commit()
|
||||
return {"url": download_url, "expires_in": DOWNLOAD_URL_EXPIRE_SECONDS}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user