feat(ui): улучшения фото-модалки, отправки записей и списка модулей

- enhance-модалка: индикатор «размышления» с прогрессом, иконки Lucide
  вместо эмодзи, подсветка готового результата, защита от гонок опроса
- index.js: лимит модулей 1000, повторные попытки загрузки списка,
  таймаут и ретрай отправки записи, требование вложений по флагу модуля
- journal.js/groups.js: `data-img` получает полный путь (лайтбокс вместо
  миниатюры), thumbSrc отдаёт `/uploads/thumb/` и оригиналы из `.originals/`
- shorts.js: переключение «Использовано» без полной перезагрузки списка
- AGENTS.md: правила миниатюр (`thumbSrc`) и `data-img`
This commit is contained in:
dev
2026-10-14 22:59:27 +03:00
parent 06bcbe0824
commit 853b446591
8 changed files with 389 additions and 76 deletions
+79 -13
View File
@@ -958,11 +958,53 @@ function showEnhanceResult(show) {
if (loading) loading.style.display = show ? 'none' : '';
}
function flashEnhanceResult() {
const area = document.getElementById('enhanceCompare');
if (!area) return;
area.classList.remove('enhance-flash');
void area.offsetWidth;
area.classList.add('enhance-flash');
setTimeout(() => area.classList.remove('enhance-flash'), 1200);
}
function setBtnLabel(btn, text) {
if (!btn) return;
const icon = btn.querySelector('svg, i[data-lucide]');
btn.textContent = '';
if (icon) {
btn.appendChild(icon);
btn.appendChild(document.createTextNode(' ' + text));
} else {
btn.textContent = text;
}
}
function setEnhanceLoadingText(text) {
const el = document.getElementById('enhanceLoading');
if (!el) return;
el.style.display = '';
el.textContent = text;
const textEl = document.getElementById('enhanceThinkingText');
if (textEl) textEl.textContent = text;
const dots = el.querySelector('.enhance-thinking-dots');
if (dots) dots.style.display = '';
const progress = document.getElementById('enhanceProgress');
if (progress) progress.style.display = 'none';
}
function setEnhanceLoadingProgress(pct, text) {
const el = document.getElementById('enhanceLoading');
if (!el) return;
el.style.display = '';
const textEl = document.getElementById('enhanceThinkingText');
if (textEl && text) textEl.textContent = text;
const dots = el.querySelector('.enhance-thinking-dots');
if (dots) dots.style.display = pct >= 100 ? 'none' : '';
const progress = document.getElementById('enhanceProgress');
const bar = document.getElementById('enhanceProgressBar');
if (progress && bar) {
progress.style.display = '';
bar.style.width = Math.min(100, Math.max(0, pct)) + '%';
}
}
function medianFilterPass(ctx, w, h) {
@@ -1405,7 +1447,7 @@ function openEnhance(id) {
const orig = document.getElementById('enhanceOrig');
if (orig) orig.src = API + p.photo_path;
const btnAi = document.getElementById('enhanceAiBtn');
if (btnAi) { btnAi.disabled = false; btnAi.textContent = '🤖 ИИ'; }
if (btnAi) { btnAi.disabled = false; setBtnLabel(btnAi, 'ИИ'); }
const saveBtn = document.getElementById('enhanceSaveBtn');
if (saveBtn) saveBtn.disabled = true;
loadPhotoAiConfig().then(() => {
@@ -1419,13 +1461,25 @@ function openEnhance(id) {
setEnhanceLoadingText('Загрузка...');
const img = new Image();
img.onload = () => {
if (enhanceAiResultPath) return;
enhanceSourceImg = img;
renderEnhancePreview();
if (saveBtn) saveBtn.disabled = false;
};
img.onerror = () => setEnhanceLoadingText('Не удалось загрузить фото');
img.onerror = () => {
const loadingEl = document.getElementById('enhanceLoading');
if (loadingEl) {
const textEl = document.getElementById('enhanceThinkingText');
if (textEl) textEl.textContent = 'Не удалось загрузить фото';
const dots = loadingEl.querySelector('.enhance-thinking-dots');
if (dots) dots.style.display = 'none';
const progress = document.getElementById('enhanceProgress');
if (progress) progress.style.display = 'none';
}
};
img.src = API + p.photo_path;
modal.classList.add('open');
renderIcons();
}
function closeEnhance() {
@@ -1441,6 +1495,8 @@ function closeEnhance() {
enhanceSaving = false;
resetEnhanceZoom();
if (enhanceTimer) { clearTimeout(enhanceTimer); enhanceTimer = null; }
const loadingEl = document.getElementById('enhanceLoading');
if (loadingEl) loadingEl.style.display = 'none';
}
async function runPhotoAi() {
@@ -1453,11 +1509,11 @@ async function runPhotoAi() {
const btnAi = document.getElementById('enhanceAiBtn');
const saveBtn = document.getElementById('enhanceSaveBtn');
enhanceSaving = true;
if (btnAi) { btnAi.disabled = true; btnAi.textContent = '⏳ ИИ...'; }
if (btnAi) { btnAi.disabled = true; setBtnLabel(btnAi, '⏳ ИИ...'); }
if (saveBtn) saveBtn.disabled = true;
showEnhanceResult(false);
setEnhanceLoadingText(mode.face === 'off'
? 'ИИ обрабатывает фото... (может занять до минуты)'
setEnhanceLoadingProgress(0, mode.face === 'off'
? 'ИИ обрабатывает фото...'
: 'ИИ обрабатывает фото и восстанавливает лица...');
try {
const res = await fetch(API + `/api/groups/${currentGroupId}/photos/${enhancePhotoId}/enhance-ai`, {
@@ -1469,7 +1525,7 @@ async function runPhotoAi() {
pollAiResult();
} catch (err) {
enhanceSaving = false;
if (btnAi) { btnAi.disabled = false; btnAi.textContent = '🤖 ИИ'; }
if (btnAi) { btnAi.disabled = false; setBtnLabel(btnAi, 'ИИ'); }
if (saveBtn) saveBtn.disabled = (enhanceAiJobId == null);
showEnhanceResult(true);
alert(err.message);
@@ -1478,6 +1534,7 @@ async function runPhotoAi() {
async function pollAiResult() {
if (!enhancePhotoId || !enhanceAiJobId || !currentGroupId) return;
if (enhanceAiResultPath) return;
try {
const res = await fetch(API + `/api/groups/${currentGroupId}/photos/${enhancePhotoId}/enhance-ai/${enhanceAiJobId}`, { headers: hdr() });
if (!res.ok) { const e = await res.json().catch(() => ({})); throw new Error(e.error || 'Ошибка статуса'); }
@@ -1486,7 +1543,7 @@ async function pollAiResult() {
enhanceSaving = false;
enhanceAiResultPath = data.photo_path;
const btnAi = document.getElementById('enhanceAiBtn');
if (btnAi) { btnAi.disabled = false; btnAi.textContent = '🤖 ИИ'; }
if (btnAi) { btnAi.disabled = false; setBtnLabel(btnAi, 'ИИ'); }
const saveBtn = document.getElementById('enhanceSaveBtn');
if (saveBtn) saveBtn.disabled = false;
const img = new Image();
@@ -1501,9 +1558,12 @@ async function pollAiResult() {
document.getElementById('enhanceSharp').value = 0;
document.getElementById('enhanceSharpVal').textContent = '0%';
renderEnhancePreview();
flashEnhanceResult();
};
img.onerror = () => setEnhanceLoadingText('Не удалось загрузить результат ИИ');
img.onerror = () => showEnhanceResult(true);
img.src = API + data.photo_path;
const loadingEl = document.getElementById('enhanceLoading');
if (loadingEl) loadingEl.style.display = 'none';
showToast('ИИ результат готов');
return;
}
@@ -1511,17 +1571,23 @@ async function pollAiResult() {
enhanceSaving = false;
alert(data.error || 'Ошибка обработки');
const btnAi = document.getElementById('enhanceAiBtn');
if (btnAi) { btnAi.disabled = false; btnAi.textContent = '🤖 ИИ'; }
if (btnAi) { btnAi.disabled = false; setBtnLabel(btnAi, 'ИИ'); }
showEnhanceResult(true);
return;
}
setTimeout(pollAiResult, 2000);
// Simulate progress
const currentMode = photoAiMode();
const progress = Math.min(95, Date.now() % 10000 / 100); // Cycles 0-95 over 10 seconds
setEnhanceLoadingProgress(progress, currentMode.face === 'off'
? 'ИИ обрабатывает фото...'
: 'ИИ обрабатывает фото и восстанавливает лица...');
setTimeout(pollAiResult, 500);
} catch (err) {
enhanceSaving = false;
showEnhanceResult(true);
alert(err.message);
const btnAi = document.getElementById('enhanceAiBtn');
if (btnAi) { btnAi.disabled = false; btnAi.textContent = '🤖 ИИ'; }
showEnhanceResult(true);
if (btnAi) { btnAi.disabled = false; setBtnLabel(btnAi, 'ИИ'); }
}
}