GNAI-023 M8-T4 Fix: Report-Download (PDF via weasyprint, /outputs-Routing im NPM)

'No pdf path provided': md2pdf im gptr-Image braucht playwright/chromium
(nicht installiert) -> write_md_to_pdf faellt auf '' zurueck. sitecustomize
ersetzt sie durch weasyprint (im Image funktionsfaehig). docx-404: NPM-vHost
leitete /outputs/ an den Frontend-Container; neue location /outputs/ mit
auth_request + Proxy auf Backend :8086 + rewrite gegen das vom Frontend
verdoppelte outputs/outputs/-PREFIX. Verifiziert: PDF wird erzeugt,
nginx -t ok, unauth /outputs -> 302 Keycloak, beide Playbooks idempotent.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
2026-11-21 11:44:13 +01:00
parent c491c0e0bb
commit 8ef591b4a0
3 changed files with 61 additions and 0 deletions
@@ -30,3 +30,32 @@ if _base:
except Exception:
# never break interpreter startup because of the patch
pass
# write_md_to_pdf: the published image ships md2pdf (needs playwright +
# chromium, both absent) so every PDF export fails and returns "" — which
# makes the frontend log "No pdf path provided" and render href="#".
# weasyprint 64.1 IS installed and works in the image, so replace the
# function with a mistune -> HTML -> weasyprint implementation. Must run
# before backend.server.server_utils does `from backend.utils import
# write_md_to_pdf`; sitecustomize runs at interpreter start, so importing
# backend.utils here and swapping the attribute is sufficient.
try:
import urllib.parse
import backend.utils as _bu
async def _write_md_to_pdf_weasyprint(text: str, filename: str = "") -> str:
import mistune
from weasyprint import CSS, HTML
file_path = f"outputs/{filename[:60]}.pdf"
css_path = "./frontend/pdf_styles.css"
stylesheets = [CSS(filename=css_path)] if os.path.exists(css_path) else None
HTML(string=mistune.html(text), base_url=".").write_pdf(
file_path, stylesheets=stylesheets
)
return urllib.parse.quote(file_path)
_bu.write_md_to_pdf = _write_md_to_pdf_weasyprint
except Exception:
pass