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:
@@ -274,3 +274,25 @@ Internet → NPM (CT 103, 443) → auth_request-Subrequest an oauth2-proxy
|
||||
Backend-Container: `Memory("custom",…).get_embeddings().embed_query()` →
|
||||
768-dim Vektor über `llama-cpp-embed`, `OPENAI_BASE_URL` bleibt
|
||||
`llama-cpp`. research.yml idempotent (changed=0).
|
||||
|
||||
- **Befund 21.11. (Report-Download: „No pdf path provided“ / docx 404):**
|
||||
zwei unabhängige Ursachen. (a) PDF: `write_md_to_pdf` nutzt `md2pdf`
|
||||
(braucht playwright+chromium — im Image beides nicht installiert) →
|
||||
Exception wird geschluckt, Rückgabe `""` → Frontend loggt „No pdf path
|
||||
provided“ und rendert `href="#"` (Klick landet auf der Main Page).
|
||||
(b) docx/md: Backend schreibt die Dateien nach `outputs/` und mountet
|
||||
`/outputs` via StaticFiles, das gptr-nextjs-Frontend baut aber
|
||||
same-origin-Links `outputs/<pfad>` — die NPM-vHost leitete `/outputs/`
|
||||
bisher an den FRONTEND-Container (location /) → 404. Zusätzlich
|
||||
verdoppelt das Frontend das Präfix (`"outputs/" + output.pdf`, der
|
||||
Backend-Pfad enthält `outputs/` bereits) → `outputs/outputs/...`.
|
||||
- **Fix 21.11.:** (a) `sitecustomize_gnai.py` ersetzt `backend.utils.
|
||||
write_md_to_pdf` durch eine weasyprint-Implementierung (mistune → HTML →
|
||||
weasyprint 64.1, im Image vorhanden und funktionsfähig; CSS aus
|
||||
`frontend/pdf_styles.css`). Verifiziert: `write_md_to_pdf('# Test…')` →
|
||||
`outputs/verify_pdf.pdf`. (b) NPM-vHost um `location /outputs/` ergänzt
|
||||
(auth_request + proxy auf Backend :8086 + `rewrite ^/outputs/outputs/
|
||||
(.*)$ /outputs/$1 break;` gegen das doppelte Präfix). Verifiziert:
|
||||
NPM-API host research.* enthält den Block, `nginx -t` ok, unauth
|
||||
`/outputs/test.md` → 302 Keycloak. research.yml + ct103 site.yml
|
||||
idempotent (jeweils changed=0).
|
||||
|
||||
@@ -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
|
||||
|
||||
+10
@@ -65,6 +65,16 @@ reverse_proxy_research_advanced_config: |
|
||||
proxy_read_timeout 600s;
|
||||
proxy_send_timeout 600s;
|
||||
}
|
||||
# report downloads (pdf/docx/md/json): the backend serves /outputs via
|
||||
# StaticFiles; gptr-nextjs prepends "outputs/" to the backend path which
|
||||
# already contains it -> collapse the doubled prefix before proxying
|
||||
location /outputs/ {
|
||||
auth_request /oauth2/auth;
|
||||
error_page 401 =302 /oauth2/sign_in?rd=$scheme://$host$request_uri;
|
||||
rewrite ^/outputs/outputs/(.*)$ /outputs/$1 break;
|
||||
proxy_pass http://{{ reverse_proxy_research_upstream_host }}:{{ reverse_proxy_research_api_port }};
|
||||
proxy_set_header Host $host;
|
||||
}
|
||||
location /ws {
|
||||
auth_request /oauth2/auth;
|
||||
error_page 401 =302 /oauth2/sign_in?rd=$scheme://$host$request_uri;
|
||||
|
||||
Reference in New Issue
Block a user