Remove deprecated PDF endpoint and update frontend download actions

Remove the old HTML-based PDF download endpoint in favor of the new
WeasyPrint-based one, and replace the generic "Télécharger" button
in popout.html with a dedicated .md download and a new PDF button.
Also remove the unused generic download button from the main file view.
This commit is contained in:
2026-05-26 21:55:42 -04:00
parent 4929ff7beb
commit dc9684e56c
3 changed files with 54 additions and 54 deletions
-45
View File
@@ -2816,51 +2816,6 @@ async def api_share_revoke(share_id: str, current_user=Depends(require_auth)):
raise HTTPException(404, "Share not found")
return {"status": "revoked"}
@app.get("/s/{token}/pdf")
async def public_share_pdf(token: str):
"""Download shared document as PDF — no authentication required."""
share = get_share_by_token(token)
if not share:
raise HTTPException(404, "Share not found or expired")
vault_data = get_vault_data(share["vault"])
if not vault_data:
raise HTTPException(404, "Vault not found")
vault_root = Path(vault_data["path"])
file_path = _resolve_safe_path(vault_root, share["path"])
if not file_path.exists():
raise HTTPException(404, "File not found")
try:
raw = file_path.read_text(encoding="utf-8", errors="replace")
except Exception:
raise HTTPException(500, "Cannot read file")
record_access(token)
raw = redact_file_content(raw, str(file_path))
post = parse_markdown_file(raw)
html = _render_markdown(post.content, share["vault"], file_path)
title = post.metadata.get("title", file_path.stem)
# Build a full HTML page for PDF rendering
full_html = f"""<!DOCTYPE html><html><head><meta charset="utf-8"><title>{title}</title>
<style>
body{{font-family:Georgia,serif;max-width:700px;margin:40px auto;padding:0 20px;line-height:1.7;color:#1a1a2e;font-size:13px}}
h1{{font-size:22px;border-bottom:2px solid #333;padding-bottom:6px}}h2{{font-size:18px;margin-top:20px}}h3{{font-size:15px}}
pre{{background:#f5f5f5;padding:10px;border-radius:4px;font-size:11px;overflow-x:auto}}code{{font-size:12px;background:#f5f5f5;padding:1px 3px}}
img{{max-width:100%}}blockquote{{border-left:3px solid #ccc;padding-left:12px;color:#555}}
table{{border-collapse:collapse;width:100%}}th,td{{border:1px solid #ddd;padding:6px 10px;text-align:left}}th{{background:#f0f0f0}}
</style></head><body><h1>{title}</h1>{html}</body></html>"""
filename = f"{title}.pdf"
return HTMLResponse(
content=full_html,
media_type="text/html",
headers={
"Content-Disposition": f'attachment; filename="{filename}"',
"X-PDF-Download": "true",
},
)
@app.get("/s/{token}/pdf")
async def public_share_pdf_download(token: str):
"""Download shared document as real PDF via WeasyPrint."""