From 3acb7aa874de79c83440fd8bdc0e6383cc9348dd Mon Sep 17 00:00:00 2001 From: rene Date: Sat, 9 May 2026 21:38:35 +0200 Subject: [PATCH] Debug: KI-Bericht save_count + save_error im Response, Toast-Feedback (SW by-v808) --- backend/main.py | 2 +- backend/routes/health.py | 8 +++++++- backend/static/index.html | 14 +++++++------- backend/static/js/app.js | 2 +- backend/static/js/pages/health.js | 5 ++++- backend/static/sw.js | 2 +- 6 files changed, 21 insertions(+), 12 deletions(-) diff --git a/backend/main.py b/backend/main.py index dbe101c..b1748e9 100644 --- a/backend/main.py +++ b/backend/main.py @@ -341,7 +341,7 @@ MEDIA_DIR = os.getenv("MEDIA_DIR", "/data/media") os.makedirs(MEDIA_DIR, exist_ok=True) app.mount("/media", StaticFiles(directory=MEDIA_DIR), name="media") -APP_VER = "807" # muss mit APP_VER in app.js übereinstimmen +APP_VER = "808" # muss mit APP_VER in app.js übereinstimmen @app.get("/.well-known/assetlinks.json") async def assetlinks(): diff --git a/backend/routes/health.py b/backend/routes/health.py index 1035cf1..f803b07 100644 --- a/backend/routes/health.py +++ b/backend/routes/health.py @@ -454,15 +454,21 @@ async def ki_zusammenfassung(dog_id: int, user=Depends(get_current_user)): user_is_premium=bool(user.get("is_premium")), user_id=user["id"], ) + save_error = None try: with db() as conn: conn.execute( "INSERT INTO ki_health_reports (dog_id, user_id, bericht) VALUES (?,?,?)", (dog_id, user["id"], result) ) + count = conn.execute( + "SELECT COUNT(*) FROM ki_health_reports WHERE dog_id=?", (dog_id,) + ).fetchone()[0] except Exception as e: + save_error = str(e) + count = 0 logger.warning(f"KI-Bericht konnte nicht gespeichert werden: {e}") - return {"zusammenfassung": result} + return {"zusammenfassung": result, "saved_count": count, "save_error": save_error} except KIPremiumRequired as e: raise HTTPException(402, str(e)) except KIUnavailableError as e: diff --git a/backend/static/index.html b/backend/static/index.html index 86d0993..b6933c2 100644 --- a/backend/static/index.html +++ b/backend/static/index.html @@ -96,9 +96,9 @@ - - - + + + @@ -578,10 +578,10 @@ - - - - + + + + diff --git a/backend/static/js/app.js b/backend/static/js/app.js index 70b20ca..bce2f8d 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 = '807'; // ← bei jedem Deploy mit Frontend-Änderungen erhöhen +const APP_VER = '808'; // ← bei jedem Deploy mit Frontend-Änderungen erhöhen const APP_VERSION = '1.5.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/health.js b/backend/static/js/pages/health.js index 87d6dd2..07a3f67 100644 --- a/backend/static/js/pages/health.js +++ b/backend/static/js/pages/health.js @@ -2793,7 +2793,10 @@ window.Page_health = (() => { UI.setLoading(btn, true); try { - const { zusammenfassung } = await API.health.kiZusammenfassung(_appState.activeDog.id); + const res = await API.health.kiZusammenfassung(_appState.activeDog.id); + const zusammenfassung = res.zusammenfassung ?? res; + if (res.save_error) UI.toast.warning(`Speichern fehlgeschlagen: ${res.save_error}`); + else if (res.saved_count !== undefined) UI.toast.info(`${res.saved_count} Bericht(e) gespeichert`); UI.modal.open({ title: `${UI.icon('star')} KI-Gesundheitsbericht`, body: `
${_esc(zusammenfassung)}
`, diff --git a/backend/static/sw.js b/backend/static/sw.js index a830a37..2e8c879 100644 --- a/backend/static/sw.js +++ b/backend/static/sw.js @@ -3,7 +3,7 @@ Offline-Cache + Push Notifications + Tile-Cache ============================================================ */ -const CACHE_VERSION = 'by-v807'; +const CACHE_VERSION = 'by-v808'; const CACHE_STATIC = `${CACHE_VERSION}-static`; const CACHE_TILES = 'ban-yaro-tiles-v1'; // bleibt über SW-Updates erhalten const CACHE_API = 'ban-yaro-api-v1'; // API-Response-Cache