diff --git a/app/main.py b/app/main.py index 21d9b04..6c0a330 100644 --- a/app/main.py +++ b/app/main.py @@ -875,6 +875,37 @@ neu analysiert, um verifizierte Zitate zu erzeugen.
) +@app.get("/api/programme/thumbnail/{programm_id}") +async def programme_thumbnail(programm_id: str): + """Thumbnail der ersten Seite eines Wahlprogramm-PDFs (PNG, 200px breit). + + Wird auf der Quellen-Seite als Vorschau angezeigt. Cached 24h. + """ + import fitz + if programm_id not in PROGRAMME: + raise HTTPException(status_code=404) + info = PROGRAMME[programm_id] + pdf_path = static_dir / "referenzen" / info["pdf"] + if not pdf_path.exists(): + raise HTTPException(status_code=404) + try: + doc = fitz.open(str(pdf_path)) + page = doc[0] + # 200px Breite, proportional skaliert + zoom = 200 / page.rect.width + mat = fitz.Matrix(zoom, zoom) + pix = page.get_pixmap(matrix=mat) + png_bytes = pix.tobytes("png") + doc.close() + return Response( + content=png_bytes, + media_type="image/png", + headers={"Cache-Control": "public, max-age=86400"}, + ) + except Exception: + raise HTTPException(status_code=500) + + @app.get("/api/programme") async def list_programme(): """List all available programmes.""" diff --git a/app/templates/quellen.html b/app/templates/quellen.html index 7df3ccb..cb446d6 100644 --- a/app/templates/quellen.html +++ b/app/templates/quellen.html @@ -221,7 +221,13 @@