From e5abdcab6293197d9187253e5dbafa8eec503868 Mon Sep 17 00:00:00 2001 From: rene Date: Tue, 26 May 2026 13:38:11 +0200 Subject: [PATCH] =?UTF-8?q?Fix:=20Tagebuch=20Foto-L=C3=B6schen=20=E2=80=94?= =?UTF-8?q?=20null-crash=20+=20404-Cleanup,=20SW=20by-v1073?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 'null is not an object (wrap2.remove)': Wrapper-Div hat keine Klasse .diary-media-thumb-wrap → closest() lieferte null. Fallback auf btn.parentElement + Null-Check vor remove() - Bei 404 'Medium nicht gefunden' wird das verwaiste Foto jetzt trotzdem lokal aufgeräumt (entry.media_items + DOM), statt einen Error-Toast zu zeigen. Verwaiste Phantome verschwinden so beim ersten Lösch-Klick. --- backend/main.py | 2 +- backend/static/index.html | 14 +++++++------- backend/static/js/app.js | 2 +- backend/static/js/pages/diary.js | 24 ++++++++++++++++-------- backend/static/sw.js | 2 +- 5 files changed, 26 insertions(+), 18 deletions(-) diff --git a/backend/main.py b/backend/main.py index 8268dfd..484f7ae 100644 --- a/backend/main.py +++ b/backend/main.py @@ -410,7 +410,7 @@ async def serve_media(path: str, request: _Request): raise _HE(404, "Nicht gefunden.") return _media_response(filepath) -APP_VER = "1072" # muss mit APP_VER in app.js übereinstimmen +APP_VER = "1073" # muss mit APP_VER in app.js übereinstimmen @app.get("/.well-known/assetlinks.json") async def assetlinks(): diff --git a/backend/static/index.html b/backend/static/index.html index 80b7487..4c56c46 100644 --- a/backend/static/index.html +++ b/backend/static/index.html @@ -101,9 +101,9 @@ - - - + + + @@ -616,10 +616,10 @@ - - - - + + + + diff --git a/backend/static/js/app.js b/backend/static/js/app.js index 98b9316..29c16ff 100644 --- a/backend/static/js/app.js +++ b/backend/static/js/app.js @@ -3,7 +3,7 @@ Router, State-Management, Navigation, Initialisierung. ============================================================ */ -const APP_VER = '1072'; // ← bei jedem Deploy mit Frontend-Änderungen erhöhen +const APP_VER = '1073'; // ← bei jedem Deploy mit Frontend-Änderungen erhöhen const APP_VERSION = '1.6.0'; // ← semantische Version, wird bei make release gesetzt const IS_STAGING = location.hostname === 'staging.banyaro.app'; // Cache-Bust-Parameter nach Update-Reload sofort entfernen. diff --git a/backend/static/js/pages/diary.js b/backend/static/js/pages/diary.js index a4e16e6..cdd67be 100644 --- a/backend/static/js/pages/diary.js +++ b/backend/static/js/pages/diary.js @@ -1437,25 +1437,33 @@ window.Page_diary = (() => { wrap.innerHTML = grid; wrap.querySelectorAll('.diary-media-thumb-del').forEach(btn => { btn.addEventListener('click', async () => { - const wrap2 = btn.closest('.diary-media-thumb-wrap'); + const wrap2 = btn.closest('.diary-media-thumb-wrap') || btn.parentElement; const mediaId = btn.dataset.mediaId ? parseInt(btn.dataset.mediaId) : null; const isLegacy = !!btn.dataset.legacy; btn.disabled = true; + let alreadyGone = false; try { if (mediaId != null) { await API.diary.deleteMediaItem(_appState.activeDog.id, entry.id, mediaId); - // aus entry.media_items entfernen - if (entry.media_items) entry.media_items = entry.media_items.filter(m => m.id !== mediaId); } else if (isLegacy) { await API.diary.deleteMedia(_appState.activeDog.id, entry.id); - entry.media_url = null; } - wrap2.remove(); - UI.toast.success('Medium entfernt.'); } catch (e) { - btn.disabled = false; - UI.toast.error(e.message || 'Fehler beim Löschen.'); + if (e?.status === 404) { + alreadyGone = true; // serverseitig schon weg → trotzdem lokal aufräumen + } else { + btn.disabled = false; + UI.toast.error(e.message || 'Fehler beim Löschen.'); + return; + } } + if (mediaId != null && entry.media_items) { + entry.media_items = entry.media_items.filter(m => m.id !== mediaId); + } else if (isLegacy) { + entry.media_url = null; + } + if (wrap2) wrap2.remove(); + UI.toast.success(alreadyGone ? 'Verwaisten Eintrag aufgeräumt.' : 'Medium entfernt.'); }); }); // Stern-Buttons im Edit-Formular diff --git a/backend/static/sw.js b/backend/static/sw.js index 2eded82..400c2a5 100644 --- a/backend/static/sw.js +++ b/backend/static/sw.js @@ -4,7 +4,7 @@ ============================================================ */ // ← EINZIGE Stelle für die Version — STATIC_ASSETS und CACHE_VERSION leiten sich ab -const VER = '1072'; +const VER = '1073'; const CACHE_VERSION = `by-v${VER}`; const CACHE_STATIC = `${CACHE_VERSION}-static`; const CACHE_TILES = 'ban-yaro-tiles-v1'; // bleibt über SW-Updates erhalten