INNER CODE UNIT · Python
result_jpg
canarybyte/veridrop · web/server.py:541
async def result_jpg(job_id: str) -> Response:
j = await jobs.get(job_id)
if j is None or j.status != "done" or j.report is None:
raise HTTPException(status_code=404, detail="result not ready")
# Cache the JPG next to the JSON. Detection report is immutable, so once
# generated we always serve from disk to spare the CPU.
cache_path = jobs.image_path(job_id, j.protocol)
if not cache_path.exists():
png_bytes = render_report_jpg(j.report)
cache_path.write_bytes(png_bytes)
return Response(
content=cache_path.read_bytes(),
media_type="image/jpeg",
headers={
"Content-Disposition": f'inline; filename="veridrop-{job_id}.jpg"',
"Cache-Control": "public, max-age=86400",
},