完善训练链路接口与PDF下载
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
from pathlib import Path
|
||||
|
||||
from fastapi import APIRouter, Depends
|
||||
from fastapi.responses import FileResponse
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.core.response import ApiResponse, ok
|
||||
@@ -37,3 +40,20 @@ def export_pdf(
|
||||
export = PdfExportService(db).export(evaluation_id, ctx.user_id)
|
||||
db.commit()
|
||||
return ok(ExportPdfResponse(export_id=export.id, file_path=export.file_path))
|
||||
|
||||
|
||||
@router.get("/{evaluation_id}/download-pdf", response_class=FileResponse)
|
||||
def download_pdf(
|
||||
evaluation_id: int,
|
||||
ctx: UserContext = Depends(get_user_context),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
"""PDF 下载:校验评价归属后生成报告,并以文件流方式触发浏览器下载。"""
|
||||
export = PdfExportService(db).export(evaluation_id, ctx.user_id)
|
||||
db.commit()
|
||||
file_path = Path(export.file_path)
|
||||
return FileResponse(
|
||||
path=file_path,
|
||||
media_type="application/pdf",
|
||||
filename=file_path.name,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user