diff --git a/backend/main.py b/backend/main.py index c4661e8..e928b62 100644 --- a/backend/main.py +++ b/backend/main.py @@ -2836,7 +2836,11 @@ async def public_share_pdf_download(token: str): 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) + ext = file_path.suffix.lower() + if ext == ".md": + html = _render_markdown(post.content, share["vault"], file_path) + else: + html = f'
{html_mod.escape(raw)}
' title = post.metadata.get("title", file_path.stem) pdf_html = build_pdf_html(html, str(title)) pdf_bytes = generate_pdf(pdf_html, str(title)) @@ -2844,6 +2848,23 @@ async def public_share_pdf_download(token: str): return Response(content=pdf_bytes, media_type="application/pdf", headers={"Content-Disposition": f'attachment; filename="{safe_name}.pdf"'}) +@app.get("/s/{token}/raw") +async def public_share_raw(token: str): + """Download the raw (original) shared document.""" + 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") + record_access(token) + return FileResponse(path=str(file_path), filename=file_path.name, media_type="application/octet-stream") + + @app.get("/s/{token}") async def public_share_view(token: str): """Public share view — no authentication required.""" @@ -2864,10 +2885,19 @@ async def public_share_view(token: str): 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) + ext = file_path.suffix.lower() + + if ext == ".md": + html = _render_markdown(post.content, share["vault"], file_path) + else: + escaped = html_mod.escape(raw) + html = f'
{escaped}
' + title = post.metadata.get("title", file_path.stem) - # Build frontmatter section HTML + # JSON-escape raw content for embedding in HTML + import json as _json + raw_json = _json.dumps(raw) fm_html = "" if post.metadata: fm_items = [] @@ -2943,10 +2973,11 @@ body{{font-family:system-ui,-apple-system,sans-serif;background:var(--bg);color:
{fm_html}{html}
+ """)