feat: add official artifact download endpoints and UI for KS-2/KS-3

This commit is contained in:
Арсентьев Александр
2026-09-30 11:20:47 +03:00
parent c1be111e1a
commit bc0e04a482
7 changed files with 1078 additions and 0 deletions
+33
View File
@@ -191,6 +191,39 @@ async def ks3_cancel(project_id: int, ks3_id: int, db: Session = Depends(get_db)
return RedirectResponse(f"/projects/{project_id}/ks3/{ks3_id}", status_code=303)
@router.get("/{project_id}/ks3/{ks3_id}/artifact")
async def ks3_download_artifact(project_id: int, ks3_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, ks3_id)
if document.status == "draft":
raise HTTPException(status_code=409, detail="Официальная форма доступна только после проведения КС-3")
try:
artifact, content = resolve_artifact(
db,
project_id=project_id,
document_type="KS3",
document_id=ks3_id,
format="docx",
)
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("КС-3", document.number, document.date, "docx")
return Response(
content=content,
media_type="application/vnd.openxmlformats-officedocument.wordprocessingml.document",
headers={"Content-Disposition": content_disposition(filename)},
)
@router.get("/{project_id}/ks3/{ks3_id}/export/excel")
async def ks3_export_excel(project_id: int, ks3_id: int, db: Session = Depends(get_db)):
document = _document(db, project_id, ks3_id)