✓ DeepSeek токен загружен из config.js
@@ -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.