fix(diarization-ui): download markdown with sanitized document title filename
This commit is contained in:
11
app.py
11
app.py
@@ -308,7 +308,16 @@ def download_md(doc_id: int):
|
||||
d = c.execute("SELECT title,content_md FROM documents WHERE id=?", (doc_id,)).fetchone()
|
||||
if not d:
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user