diff --git a/public/journal.html b/public/journal.html
index 6c47d52..b0438b6 100644
--- a/public/journal.html
+++ b/public/journal.html
@@ -480,6 +480,7 @@
diff --git a/public/js/journal.js b/public/js/journal.js
index ed2bf09..b98d39e 100644
--- a/public/js/journal.js
+++ b/public/js/journal.js
@@ -1139,7 +1139,7 @@ async function runPhotoAi() {
if (!confirm(`ИИ-обработка фото: ${mode.title}. ${faceNote} Продолжить?`)) return;
enhanceSaving = true;
const btn = document.getElementById('enhanceAiBtn');
- btn.disabled = true;
+ if (btn) btn.disabled = true;
try {
const res = await fetch(`${API}/api/entries/${entryId}/photo/enhance-ai`, {
method: 'POST',
@@ -1215,7 +1215,7 @@ async function runPhotoAi() {
alert(e.message);
} finally {
enhanceSaving = false;
- btn.disabled = false;
+ if (btn) btn.disabled = false;
setBtnLabel(btn, 'ИИ');
}
}
@@ -1304,11 +1304,12 @@ function isDefaultEnhanceParams() {
return p.brightness === 100 && p.contrast === 100 && p.saturate === 100 && p.denoise === 0 && p.sharp === 0;
}
-async function applyAiResult() {
+async function applyAiResult(signal) {
if (!enhanceAiJobId || !enhanceEntryId) return false;
const res = await fetch(`${API}/api/entries/${enhanceEntryId}/photo/jobs/${enhanceAiJobId}/apply`, {
method: 'POST',
headers: hdr(),
+ signal,
});
const data = await res.json().catch(() => ({}));
if (!res.ok) throw new Error(data.error || 'Ошибка применения ИИ-результата');
@@ -1634,6 +1635,8 @@ function cpuEnhanceSyncPending() {
if (autoBtn) autoBtn.disabled = cpuEnhanceBusy;
const resetBtn = document.getElementById('cpuEnhanceResetBtn');
if (resetBtn) resetBtn.disabled = cpuEnhanceBusy;
+ const applyCpuBtn = document.getElementById('cpuEnhanceApplyCpuBtn');
+ if (applyCpuBtn) applyCpuBtn.disabled = cpuEnhanceBusy;
}
function cpuEnhanceMarkApplied() {
@@ -1804,6 +1807,8 @@ async function openCpuEnhance(id) {
cpuEnhanceClearError();
const applyLabel = document.getElementById('cpuEnhanceApplyLabel');
if (applyLabel) applyLabel.textContent = 'Сохранить';
+ const applyCpuLabel = document.getElementById('cpuEnhanceApplyCpuLabel');
+ if (applyCpuLabel) applyCpuLabel.textContent = 'Только эффекты';
const restoreBtn = document.getElementById('cpuEnhanceRestoreBtn');
if (restoreBtn) restoreBtn.style.display = e.photo_original_path ? '' : 'none';
const context = document.getElementById('cpuEnhanceContext');
@@ -2021,6 +2026,41 @@ async function cpuEnhanceApply() {
}
}
+async function cpuEnhanceApplyCpuOnly() {
+ if (!cpuEnhanceEntryId || cpuEnhanceSaving) return;
+ const entryId = cpuEnhanceEntryId;
+ const label = document.getElementById('cpuEnhanceApplyCpuLabel');
+ cpuEnhanceSaving = true;
+ cpuEnhanceClearError();
+ if (label) label.textContent = 'Сохраняю…';
+ cpuEnhanceSetBusy(true);
+ cpuEnhanceSetLoading(true, 'Применение эффектов…');
+ try {
+ const res = await fetch(`${API}/api/entries/${entryId}/photo/enhance-cpu`, {
+ method: 'POST',
+ headers: hdrJson(),
+ body: JSON.stringify({
+ mode: 'cpu',
+ params: { ...cpuEnhanceReadParams(), preset: 'quality' },
+ face: 'off',
+ face_model: 'gfpgan',
+ }),
+ });
+ const data = await res.json().catch(() => ({}));
+ if (!res.ok) throw new Error(data.error || 'Ошибка обработки');
+ showToast('Эффекты применены, ИИ не использовался');
+ closeCpuEnhance(true);
+ refreshEntryCard(entryId);
+ } catch (e) {
+ cpuEnhanceSetError(e.message);
+ showToast(e.message, true);
+ } finally {
+ cpuEnhanceSaving = false;
+ if (label) label.textContent = 'Только эффекты';
+ cpuEnhanceSetLoading(false);
+ }
+}
+
function cpuEnhancePollAi(entryId, jobId) {
return new Promise((resolve, reject) => {
let done = false;
@@ -2351,18 +2391,25 @@ function autoEnhance() {
}
async function saveEnhance() {
- if (!enhanceEntryId || !enhanceSourceImg || enhanceSaving) return;
+ if (enhanceSaving) return;
+ if (!enhanceEntryId) { alert('Запись не выбрана'); return; }
+ if (!enhanceSourceImg) { alert('Фото ещё не загружено — подождите'); return; }
await loadEnhanceEngine();
const btn = document.getElementById('enhanceSaveBtn');
enhanceSaving = true;
- btn.disabled = true;
- btn.textContent = 'Сохранение...';
+ if (btn) { btn.disabled = true; btn.textContent = 'Сохранение...'; }
const entryId = enhanceEntryId;
try {
let done = false;
let engineLabel = 'клиент';
if (enhanceAiResultPath && isDefaultEnhanceParams()) {
- await applyAiResult();
+ const ctrl = new AbortController();
+ const timer = setTimeout(() => ctrl.abort(), 15000);
+ try {
+ await applyAiResult(ctrl.signal);
+ } finally {
+ clearTimeout(timer);
+ }
engineLabel = 'ИИ';
done = true;
} else if (enhanceEngine !== 'client' && !enhanceAiResultPath) {
@@ -2396,21 +2443,31 @@ async function saveEnhance() {
const blob = await new Promise((resolve, reject) => canvas.toBlob(b => b ? resolve(b) : reject(new Error('toBlob failed')), 'image/jpeg', 0.92));
const fd = new FormData();
fd.append('photo', blob, 'enhanced.jpg');
- const res = await fetch(`${API}/api/entries/${entryId}/photo/enhance`, { method: 'PUT', headers: hdr(), body: fd });
+ const ctrl = new AbortController();
+ const timer = setTimeout(() => ctrl.abort(), 30000);
+ let res;
+ try {
+ res = await fetch(`${API}/api/entries/${entryId}/photo/enhance`, { method: 'PUT', headers: hdr(), body: fd, signal: ctrl.signal });
+ } finally {
+ clearTimeout(timer);
+ }
if (!res.ok) {
const err = await res.json().catch(() => ({}));
throw new Error(err.error || 'Ошибка сохранения');
}
}
showToast(`Фото улучшено (${engineLabel}) и сохранено`);
- closeEnhance();
- refreshEntryCard(entryId);
+ try { closeEnhance(); } catch (e) { console.error('closeEnhance failed:', e); }
+ try { await refreshEntryCard(entryId); } catch (e) { console.error('refreshEntryCard failed:', e); }
} catch (e) {
- alert(e.message);
+ console.error('saveEnhance failed:', e);
+ alert(e && e.message ? e.message : String(e));
} finally {
enhanceSaving = false;
- btn.disabled = false;
- btn.textContent = 'Применить';
+ if (btn && document.contains(btn)) {
+ btn.disabled = false;
+ btn.textContent = 'Применить';
+ }
}
}
@@ -3028,10 +3085,16 @@ async function applyPhotoJob(jobId) {
}
}
document.getElementById('enhanceModal').addEventListener('click', e => { if (e.target === e.currentTarget) closeEnhance(); });
+document.getElementById('enhanceBrightness').addEventListener('input', scheduleEnhancePreview);
+document.getElementById('enhanceContrast').addEventListener('input', scheduleEnhancePreview);
+document.getElementById('enhanceSaturate').addEventListener('input', scheduleEnhancePreview);
+document.getElementById('enhanceDenoise').addEventListener('input', scheduleEnhancePreview);
+document.getElementById('enhanceSharp').addEventListener('input', scheduleEnhancePreview);
document.getElementById('cpuEnhanceModal').addEventListener('click', e => { if (e.target === e.currentTarget) closeCpuEnhance(); });
document.getElementById('cpuEnhanceCancelBtn').addEventListener('click', () => closeCpuEnhance());
document.getElementById('cpuEnhanceCloseX').addEventListener('click', () => closeCpuEnhance());
document.getElementById('cpuEnhanceApplyBtn').addEventListener('click', cpuEnhanceApply);
+document.getElementById('cpuEnhanceApplyCpuBtn').addEventListener('click', cpuEnhanceApplyCpuOnly);
document.getElementById('cpuEnhancePreviewBtn').addEventListener('click', cpuEnhancePreview);
document.getElementById('cpuEnhanceActivateBtn').addEventListener('click', cpuEnhanceActivate);
document.getElementById('cpuZoomIn').addEventListener('click', () => cpuEnhanceZoomBy(1.25));