fix: AI cache fallback chain (git → sessionStorage → prompt)
This commit is contained in:
parent
5b13383d5b
commit
8e568bb3e8
@ -329,7 +329,7 @@ body { font-family: var(--font-base); background: var(--color-bg); color: var(--
|
|||||||
|
|
||||||
<!-- Update section: only useful if you have DeepSeek key -->
|
<!-- Update section: only useful if you have DeepSeek key -->
|
||||||
<div class="ai-divider"></div>
|
<div class="ai-divider"></div>
|
||||||
<details class="ai-update-details">
|
<details class="ai-update-details" id="ai-update-details">
|
||||||
<summary class="ai-update-summary">🔄 Обновить анализ</summary>
|
<summary class="ai-update-summary">🔄 Обновить анализ</summary>
|
||||||
<div class="ai-api-row" style="margin-top:10px;">
|
<div class="ai-api-row" style="margin-top:10px;">
|
||||||
<div id="ai-key-note" class="ai-key-note hidden">✓ DeepSeek токен загружен из config.js</div>
|
<div id="ai-key-note" class="ai-key-note hidden">✓ DeepSeek токен загружен из config.js</div>
|
||||||
@ -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 */
|
/** Load AI response from ai-cache.json stored in the git repo */
|
||||||
async function loadAiCache() {
|
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 {
|
try {
|
||||||
const resp = await fetch(AI_CACHE_RAW, {cache:'no-cache'});
|
const resp = await fetch(AI_CACHE_RAW, {cache:'no-cache'});
|
||||||
if (!resp.ok) { if(dateEl) dateEl.textContent = 'Кэш не найден'; return; }
|
if (resp.ok) {
|
||||||
const data = await resp.json();
|
const data = await resp.json();
|
||||||
if (!data.response) return;
|
if (data.response) {
|
||||||
AppState.lastAiResponse = data.response;
|
AppState.lastAiResponse = data.response;
|
||||||
showAiResult(data.response);
|
showAiResult(data.response);
|
||||||
if (dateEl && data.generated_at) {
|
if (dateEl && data.generated_at) {
|
||||||
const d = new Date(data.generated_at);
|
const d = new Date(data.generated_at);
|
||||||
dateEl.textContent = 'Обновлено: ' + d.toLocaleDateString('ru-RU',{day:'numeric',month:'long',year:'numeric'});
|
dateEl.textContent = 'Обновлено: ' + d.toLocaleDateString('ru-RU',{day:'numeric',month:'long',year:'numeric'});
|
||||||
|
}
|
||||||
|
return; // ✓ got shared cache — done
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
if(dateEl) dateEl.textContent = 'Кэш недоступен';
|
console.info('AI git cache unavailable:', e.message);
|
||||||
console.info('AI cache not loaded:', 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.
|
/** Save AI response to ai-cache.json in git via Gitea API.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user