From a4a40fd2e7f765416aa12c102c8aaa764de6ac7d Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Wed, 17 Jun 2026 20:02:35 +0200 Subject: [PATCH] =?UTF-8?q?Performance-Optimierung:=209.9=20MB=20=E2=86=92?= =?UTF-8?q?=20124=20KB=20(-98.7%)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - /media/ Endpunkt mit Cache-Control (max-age=86400, ETag) - Thumbnail-Generator für Bilder (300px via PIL, on-the-fly) - Frontend-Karten: URLs statt Base64 + Thumbnails + loading=lazy - Admin-Detailseite + öffentliche Detailseite ebenfalls auf URLs - Video-Thumbnails als separate Dateien via /media/ statt Base64 --- app.py | 97 ++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 67 insertions(+), 30 deletions(-) diff --git a/app.py b/app.py index 296e93f..7ee8fe1 100644 --- a/app.py +++ b/app.py @@ -1074,25 +1074,16 @@ def submission_detail(sub_id: int): _, ext = os.path.splitext(path) mime = mime_map.get(ext.lower(), "application/octet-stream") try: - with open(path, "rb") as f: - b64 = base64.b64encode(f.read()).decode() - src = f"data:{mime};base64,{b64}" + basename = os.path.basename(path) + src = f"/media/{basename}" media_html += f'
' # Media element if mime.startswith("image/"): - media_html += f'' + media_html += f'' elif mime.startswith("video/"): - # Generate thumbnail for poster thumb = generate_video_thumbnail(path) - poster_attr = "" - if thumb: - try: - with open(thumb, "rb") as tf: - thumb_b64 = base64.b64encode(tf.read()).decode() - poster_attr = f' poster="data:image/jpeg;base64,{thumb_b64}"' - except Exception: - pass - media_html += f'' + poster_attr = f' poster="/media/{os.path.basename(thumb)}"' if thumb else "" + media_html += f'' elif mime.startswith("audio/"): media_html += f'' else: @@ -1711,17 +1702,21 @@ def public_frontend(): continue if not os.path.exists(path): continue + basename = os.path.basename(path) _, ext = os.path.splitext(path) mime = mime_map.get(ext.lower(), "application/octet-stream") try: - with open(path, "rb") as f: - b64 = base64.b64encode(f.read()).decode() - src = "data:" + mime + ";base64," + b64 if mime.startswith("image/"): + # Use thumbnail for frontend cards + thumb = generate_image_thumbnail(path) + if thumb: + img_src = f"/media/{os.path.basename(thumb)}" + else: + img_src = f"/media/{basename}" img_tag = ( '' '
' - 'Beitragsbild' + 'Beitragsbild' '
' ) if i == 0 and not media_first: @@ -1730,16 +1725,11 @@ def public_frontend(): media_html += img_tag elif mime.startswith("video/"): thumb = generate_video_thumbnail(path) - if thumb: - with open(thumb, "rb") as f: - thumb_b64 = base64.b64encode(f.read()).decode() - thumb_src = "data:image/jpeg;base64," + thumb_b64 - else: - thumb_src = "" + thumb_src = f"/media/{os.path.basename(thumb)}" if thumb else "" vid_tag = ( '' '
' - + (f'Video-Vorschau' if thumb_src else '
🎬
') + + (f'Video-Vorschau' if thumb_src else '
🎬
') + '
' + '' + '
' @@ -2059,7 +2049,7 @@ def public_frontend():
Hey! 👋 Ich bin der BSN Community Assistant. Frag mich nach Spielen, Ständen oder was auf der SPIEL Essen los ist!
- +