feat: add official artifact download endpoints and UI for KS-2/KS-3
This commit is contained in:
@@ -195,6 +195,39 @@ def _content_disposition(filename: str) -> str:
|
||||
return content_disposition(filename)
|
||||
|
||||
|
||||
@router.get("/{project_id}/ks2/{ks2_id}/artifact")
|
||||
async def ks2_download_artifact(project_id: int, ks2_id: int, db: Session = Depends(get_db)):
|
||||
"""Download the official issued artifact (stored file, no re-render)."""
|
||||
from app.exporters import content_disposition, safe_export_filename
|
||||
from app.services.document_artifact_service import (
|
||||
ArtifactHashMismatchError,
|
||||
ArtifactNotFoundError,
|
||||
resolve_artifact,
|
||||
)
|
||||
|
||||
document = _document(db, project_id, ks2_id)
|
||||
if document.status == "draft":
|
||||
raise HTTPException(status_code=409, detail="Официальная форма доступна только после проведения КС-2")
|
||||
try:
|
||||
artifact, content = resolve_artifact(
|
||||
db,
|
||||
project_id=project_id,
|
||||
document_type="KS2",
|
||||
document_id=ks2_id,
|
||||
format="xlsx",
|
||||
)
|
||||
except ArtifactNotFoundError as exc:
|
||||
raise HTTPException(status_code=404, detail="Официальная форма недоступна: файл документа не найден.") from exc
|
||||
except ArtifactHashMismatchError as exc:
|
||||
raise HTTPException(status_code=500, detail="Файл документа повреждён и не может быть выдан.") from exc
|
||||
filename = safe_export_filename("КС-2", document.number, document.date, "xlsx")
|
||||
return Response(
|
||||
content=content,
|
||||
media_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||||
headers={"Content-Disposition": content_disposition(filename)},
|
||||
)
|
||||
|
||||
|
||||
@router.get("/{project_id}/ks2/{ks2_id}/export/excel")
|
||||
async def ks2_export_excel(project_id: int, ks2_id: int, db: Session = Depends(get_db)):
|
||||
document = _document(db, project_id, ks2_id)
|
||||
|
||||
Reference in New Issue
Block a user