File size: 1,572 Bytes
2274b3a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | """Shared read-only inspection UX routes for local FastAPI and the Space host.
The host's existing middleware establishes the account/browser and workspace.
Repository reads retain that boundary; these routes never grant access or write.
"""
from fastapi import HTTPException, Query
from fastapi.responses import HTMLResponse
from .batch_names import batch_name_available
from .inspection_report import render_report
INSPECTION_UX_PATHS = frozenset(("/api/batch-name", "/api/inspections/{identifier}/report"))
def mount_inspection_experience(app, repo, *, local=False):
@app.get("/api/batch-name")
def check_batch_name(name: str = Query(..., min_length=1, max_length=80)):
if not name.strip():
raise HTTPException(422, "Add a batch name")
return {"data": {"available": batch_name_available(repo, name)}}
@app.get("/api/inspections/{identifier}/report")
def inspection_report(identifier: str):
record = repo.get(identifier)
if not record:
raise HTTPException(404, "Inspection not found")
return HTMLResponse(
render_report(
record,
repo.review_history(identifier),
repo.review_notes(identifier),
repo.messages(identifier),
local=local,
),
headers={
"Cache-Control": "private, no-store",
"Referrer-Policy": "no-referrer",
"X-Content-Type-Options": "nosniff",
},
)
|