From 8e568bb3e8cebee17ffcfa5220c3556023025b74 Mon Sep 17 00:00:00 2001 From: Kyrykbaev-I Date: Mon, 1 Jun 2026 10:52:16 +0500 Subject: [PATCH] =?UTF-8?q?fix:=20AI=20cache=20fallback=20chain=20(git=20?= =?UTF-8?q?=E2=86=92=20sessionStorage=20=E2=86=92=20prompt)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dashboard.html | 42 ++++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/dashboard.html b/dashboard.html index 3a53e38..e6d36d6 100644 --- a/dashboard.html +++ b/dashboard.html @@ -329,7 +329,7 @@ body { font-family: var(--font-base); background: var(--color-bg); color: var(--
-
+
🔄 Обновить анализ
@@ -1209,22 +1209,40 @@ function restoreAiCache(){const c=sessionStorage.getItem('lastAiResponse');if(c) /** Load AI response from ai-cache.json stored in the git repo */ async function loadAiCache() { - const dateEl = document.getElementById('ai-cache-date'); + const dateEl = document.getElementById('ai-cache-date'); + const details = document.getElementById('ai-update-details'); + + // 1. Try git-based shared cache try { const resp = await fetch(AI_CACHE_RAW, {cache:'no-cache'}); - if (!resp.ok) { if(dateEl) dateEl.textContent = 'Кэш не найден'; return; } - const data = await resp.json(); - if (!data.response) return; - AppState.lastAiResponse = data.response; - showAiResult(data.response); - if (dateEl && data.generated_at) { - const d = new Date(data.generated_at); - dateEl.textContent = 'Обновлено: ' + d.toLocaleDateString('ru-RU',{day:'numeric',month:'long',year:'numeric'}); + if (resp.ok) { + const data = await resp.json(); + if (data.response) { + AppState.lastAiResponse = data.response; + showAiResult(data.response); + if (dateEl && data.generated_at) { + const d = new Date(data.generated_at); + dateEl.textContent = 'Обновлено: ' + d.toLocaleDateString('ru-RU',{day:'numeric',month:'long',year:'numeric'}); + } + return; // ✓ got shared cache — done + } } } catch(e) { - if(dateEl) dateEl.textContent = 'Кэш недоступен'; - console.info('AI cache not loaded:', e.message); + console.info('AI git cache unavailable:', e.message); } + + // 2. Fallback: sessionStorage from this browser's previous session + const session = sessionStorage.getItem('lastAiResponse'); + if (session) { + AppState.lastAiResponse = session; + showAiResult(session); + if (dateEl) dateEl.textContent = 'Из предыдущей сессии браузера'; + return; + } + + // 3. Nothing found — prompt user to generate + if (dateEl) dateEl.textContent = 'Анализ ещё не сгенерирован'; + if (details) details.open = true; // auto-expand the refresh section } /** Save AI response to ai-cache.json in git via Gitea API.