feat: track designer downloads and notifications

This commit is contained in:
2026-03-08 23:42:18 +08:00
parent 5ff85debdc
commit 147fc58409
9 changed files with 119 additions and 37 deletions

View File

@@ -1,4 +1,4 @@
from fastapi import APIRouter, Depends, HTTPException, status, Query, Header
from fastapi import APIRouter, Depends, HTTPException, status, Query, Header, BackgroundTasks
from fastapi.responses import FileResponse
from sqlalchemy.orm import Session
from sqlalchemy import desc
@@ -13,6 +13,7 @@ from app.models.user import User
from app.core.security import decode_access_token
from app.core.config import settings
from app.schemas.work import WorkResponse, WorkListResponse
from app.services.download_tracker import notify_download
router = APIRouter(prefix="/works", tags=["作品"])
@@ -126,6 +127,7 @@ def get_current_user(authorization: str = Header(None), db: Session = Depends(ge
@router.get("/{work_id}/download", summary="下载作品原图")
def download_work(
work_id: int,
background_tasks: BackgroundTasks,
current_user: User = Depends(get_current_user),
db: Session = Depends(get_db)
):
@@ -165,6 +167,8 @@ def download_work(
status_code=status.HTTP_404_NOT_FOUND,
detail="文件不存在"
)
background_tasks.add_task(notify_download, work, current_user, paid_order)
# 返回文件
filename = os.path.basename(full_path)