fix(diarization-ui): download markdown with sanitized document title filename

This commit is contained in:
2026-03-21 14:27:52 +01:00
parent f0d851a28a
commit be416b7766

11
app.py
View File

@@ -308,7 +308,16 @@ def download_md(doc_id: int):
d = c.execute("SELECT title,content_md FROM documents WHERE id=?", (doc_id,)).fetchone() d = c.execute("SELECT title,content_md FROM documents WHERE id=?", (doc_id,)).fetchone()
if not d: if not d:
raise HTTPException(404, "not found") raise HTTPException(404, "not found")
return PlainTextResponse(d["content_md"], headers={"Content-Disposition": f"attachment; filename=document_{doc_id}.md"})
base = (d["title"] or f"document_{doc_id}").strip()
safe = "".join(ch if ch.isalnum() or ch in ("-", "_", " ") else "_" for ch in base).strip()
safe = safe.replace(" ", "_") or f"document_{doc_id}"
filename = f"{safe}.md"
return PlainTextResponse(
d["content_md"],
headers={"Content-Disposition": f"attachment; filename={filename}"},
)
@app.post("/document/{doc_id}/rename", response_class=HTMLResponse) @app.post("/document/{doc_id}/rename", response_class=HTMLResponse)