fix(photo-enhance): restore dead sliders in enhanceModal and harden save
- re-bind input listeners for #enhanceBrightness/#enhanceContrast/#enhanceSaturate/#enhanceDenoise/#enhanceSharp -> scheduleEnhancePreview (lost in f5910d9)
- new "Только эффекты" button in #cpuEnhanceModal footer: applies slider effects via CPU pipeline (mode=cpu, face=off) in one click, no photo-ai/model
- harden saveEnhance: null-guard enhanceEntryId/enhanceSourceImg/btn, AbortController timeouts on applyAiResult (15s), canvas upload (30s), refreshEntryCard; guard runPhotoAi btn.disabled
This commit is contained in:
@@ -480,6 +480,7 @@
|
|||||||
<div class="card-foot cpu-enhance-foot">
|
<div class="card-foot cpu-enhance-foot">
|
||||||
<button type="button" class="btn-primary ghost" id="cpuEnhanceRestoreBtn" style="display:none" title="Вернуть исходную фотографию"><i data-lucide="undo-2"></i> Вернуть оригинал</button>
|
<button type="button" class="btn-primary ghost" id="cpuEnhanceRestoreBtn" style="display:none" title="Вернуть исходную фотографию"><i data-lucide="undo-2"></i> Вернуть оригинал</button>
|
||||||
<button type="button" class="btn-primary ghost" id="cpuEnhanceCancelBtn">Закрыть</button>
|
<button type="button" class="btn-primary ghost" id="cpuEnhanceCancelBtn">Закрыть</button>
|
||||||
|
<button type="button" class="btn-primary ghost" id="cpuEnhanceApplyCpuBtn" title="Сразу применить эффекты с ползунков на полном размере, без ИИ-обработки. Оригинал сохранится в .originals — его можно вернуть кнопкой «Вернуть оригинал»"><i data-lucide="sliders-horizontal"></i> <span id="cpuEnhanceApplyCpuLabel">Только эффекты</span></button>
|
||||||
<button type="button" class="btn-primary" id="cpuEnhanceActivateBtn" title="Запустить обработку и получить результат"><i data-lucide="zap"></i> Активировать</button>
|
<button type="button" class="btn-primary" id="cpuEnhanceActivateBtn" title="Запустить обработку и получить результат"><i data-lucide="zap"></i> Активировать</button>
|
||||||
<button type="button" class="btn-primary" id="cpuEnhanceApplyBtn" title="Сохранить результат к записи"><i data-lucide="check"></i> <span id="cpuEnhanceApplyLabel">Сохранить</span></button>
|
<button type="button" class="btn-primary" id="cpuEnhanceApplyBtn" title="Сохранить результат к записи"><i data-lucide="check"></i> <span id="cpuEnhanceApplyLabel">Сохранить</span></button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+74
-11
@@ -1139,7 +1139,7 @@ async function runPhotoAi() {
|
|||||||
if (!confirm(`ИИ-обработка фото: ${mode.title}. ${faceNote} Продолжить?`)) return;
|
if (!confirm(`ИИ-обработка фото: ${mode.title}. ${faceNote} Продолжить?`)) return;
|
||||||
enhanceSaving = true;
|
enhanceSaving = true;
|
||||||
const btn = document.getElementById('enhanceAiBtn');
|
const btn = document.getElementById('enhanceAiBtn');
|
||||||
btn.disabled = true;
|
if (btn) btn.disabled = true;
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`${API}/api/entries/${entryId}/photo/enhance-ai`, {
|
const res = await fetch(`${API}/api/entries/${entryId}/photo/enhance-ai`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@@ -1215,7 +1215,7 @@ async function runPhotoAi() {
|
|||||||
alert(e.message);
|
alert(e.message);
|
||||||
} finally {
|
} finally {
|
||||||
enhanceSaving = false;
|
enhanceSaving = false;
|
||||||
btn.disabled = false;
|
if (btn) btn.disabled = false;
|
||||||
setBtnLabel(btn, 'ИИ');
|
setBtnLabel(btn, 'ИИ');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1304,11 +1304,12 @@ function isDefaultEnhanceParams() {
|
|||||||
return p.brightness === 100 && p.contrast === 100 && p.saturate === 100 && p.denoise === 0 && p.sharp === 0;
|
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;
|
if (!enhanceAiJobId || !enhanceEntryId) return false;
|
||||||
const res = await fetch(`${API}/api/entries/${enhanceEntryId}/photo/jobs/${enhanceAiJobId}/apply`, {
|
const res = await fetch(`${API}/api/entries/${enhanceEntryId}/photo/jobs/${enhanceAiJobId}/apply`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: hdr(),
|
headers: hdr(),
|
||||||
|
signal,
|
||||||
});
|
});
|
||||||
const data = await res.json().catch(() => ({}));
|
const data = await res.json().catch(() => ({}));
|
||||||
if (!res.ok) throw new Error(data.error || 'Ошибка применения ИИ-результата');
|
if (!res.ok) throw new Error(data.error || 'Ошибка применения ИИ-результата');
|
||||||
@@ -1634,6 +1635,8 @@ function cpuEnhanceSyncPending() {
|
|||||||
if (autoBtn) autoBtn.disabled = cpuEnhanceBusy;
|
if (autoBtn) autoBtn.disabled = cpuEnhanceBusy;
|
||||||
const resetBtn = document.getElementById('cpuEnhanceResetBtn');
|
const resetBtn = document.getElementById('cpuEnhanceResetBtn');
|
||||||
if (resetBtn) resetBtn.disabled = cpuEnhanceBusy;
|
if (resetBtn) resetBtn.disabled = cpuEnhanceBusy;
|
||||||
|
const applyCpuBtn = document.getElementById('cpuEnhanceApplyCpuBtn');
|
||||||
|
if (applyCpuBtn) applyCpuBtn.disabled = cpuEnhanceBusy;
|
||||||
}
|
}
|
||||||
|
|
||||||
function cpuEnhanceMarkApplied() {
|
function cpuEnhanceMarkApplied() {
|
||||||
@@ -1804,6 +1807,8 @@ async function openCpuEnhance(id) {
|
|||||||
cpuEnhanceClearError();
|
cpuEnhanceClearError();
|
||||||
const applyLabel = document.getElementById('cpuEnhanceApplyLabel');
|
const applyLabel = document.getElementById('cpuEnhanceApplyLabel');
|
||||||
if (applyLabel) applyLabel.textContent = 'Сохранить';
|
if (applyLabel) applyLabel.textContent = 'Сохранить';
|
||||||
|
const applyCpuLabel = document.getElementById('cpuEnhanceApplyCpuLabel');
|
||||||
|
if (applyCpuLabel) applyCpuLabel.textContent = 'Только эффекты';
|
||||||
const restoreBtn = document.getElementById('cpuEnhanceRestoreBtn');
|
const restoreBtn = document.getElementById('cpuEnhanceRestoreBtn');
|
||||||
if (restoreBtn) restoreBtn.style.display = e.photo_original_path ? '' : 'none';
|
if (restoreBtn) restoreBtn.style.display = e.photo_original_path ? '' : 'none';
|
||||||
const context = document.getElementById('cpuEnhanceContext');
|
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) {
|
function cpuEnhancePollAi(entryId, jobId) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let done = false;
|
let done = false;
|
||||||
@@ -2351,18 +2391,25 @@ function autoEnhance() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function saveEnhance() {
|
async function saveEnhance() {
|
||||||
if (!enhanceEntryId || !enhanceSourceImg || enhanceSaving) return;
|
if (enhanceSaving) return;
|
||||||
|
if (!enhanceEntryId) { alert('Запись не выбрана'); return; }
|
||||||
|
if (!enhanceSourceImg) { alert('Фото ещё не загружено — подождите'); return; }
|
||||||
await loadEnhanceEngine();
|
await loadEnhanceEngine();
|
||||||
const btn = document.getElementById('enhanceSaveBtn');
|
const btn = document.getElementById('enhanceSaveBtn');
|
||||||
enhanceSaving = true;
|
enhanceSaving = true;
|
||||||
btn.disabled = true;
|
if (btn) { btn.disabled = true; btn.textContent = 'Сохранение...'; }
|
||||||
btn.textContent = 'Сохранение...';
|
|
||||||
const entryId = enhanceEntryId;
|
const entryId = enhanceEntryId;
|
||||||
try {
|
try {
|
||||||
let done = false;
|
let done = false;
|
||||||
let engineLabel = 'клиент';
|
let engineLabel = 'клиент';
|
||||||
if (enhanceAiResultPath && isDefaultEnhanceParams()) {
|
if (enhanceAiResultPath && isDefaultEnhanceParams()) {
|
||||||
await applyAiResult();
|
const ctrl = new AbortController();
|
||||||
|
const timer = setTimeout(() => ctrl.abort(), 15000);
|
||||||
|
try {
|
||||||
|
await applyAiResult(ctrl.signal);
|
||||||
|
} finally {
|
||||||
|
clearTimeout(timer);
|
||||||
|
}
|
||||||
engineLabel = 'ИИ';
|
engineLabel = 'ИИ';
|
||||||
done = true;
|
done = true;
|
||||||
} else if (enhanceEngine !== 'client' && !enhanceAiResultPath) {
|
} else if (enhanceEngine !== 'client' && !enhanceAiResultPath) {
|
||||||
@@ -2396,23 +2443,33 @@ 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 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();
|
const fd = new FormData();
|
||||||
fd.append('photo', blob, 'enhanced.jpg');
|
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) {
|
if (!res.ok) {
|
||||||
const err = await res.json().catch(() => ({}));
|
const err = await res.json().catch(() => ({}));
|
||||||
throw new Error(err.error || 'Ошибка сохранения');
|
throw new Error(err.error || 'Ошибка сохранения');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
showToast(`Фото улучшено (${engineLabel}) и сохранено`);
|
showToast(`Фото улучшено (${engineLabel}) и сохранено`);
|
||||||
closeEnhance();
|
try { closeEnhance(); } catch (e) { console.error('closeEnhance failed:', e); }
|
||||||
refreshEntryCard(entryId);
|
try { await refreshEntryCard(entryId); } catch (e) { console.error('refreshEntryCard failed:', e); }
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
alert(e.message);
|
console.error('saveEnhance failed:', e);
|
||||||
|
alert(e && e.message ? e.message : String(e));
|
||||||
} finally {
|
} finally {
|
||||||
enhanceSaving = false;
|
enhanceSaving = false;
|
||||||
|
if (btn && document.contains(btn)) {
|
||||||
btn.disabled = false;
|
btn.disabled = false;
|
||||||
btn.textContent = 'Применить';
|
btn.textContent = 'Применить';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function aiCorrect() {
|
async function aiCorrect() {
|
||||||
if (aiCorrecting) return;
|
if (aiCorrecting) return;
|
||||||
@@ -3028,10 +3085,16 @@ async function applyPhotoJob(jobId) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
document.getElementById('enhanceModal').addEventListener('click', e => { if (e.target === e.currentTarget) closeEnhance(); });
|
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('cpuEnhanceModal').addEventListener('click', e => { if (e.target === e.currentTarget) closeCpuEnhance(); });
|
||||||
document.getElementById('cpuEnhanceCancelBtn').addEventListener('click', () => closeCpuEnhance());
|
document.getElementById('cpuEnhanceCancelBtn').addEventListener('click', () => closeCpuEnhance());
|
||||||
document.getElementById('cpuEnhanceCloseX').addEventListener('click', () => closeCpuEnhance());
|
document.getElementById('cpuEnhanceCloseX').addEventListener('click', () => closeCpuEnhance());
|
||||||
document.getElementById('cpuEnhanceApplyBtn').addEventListener('click', cpuEnhanceApply);
|
document.getElementById('cpuEnhanceApplyBtn').addEventListener('click', cpuEnhanceApply);
|
||||||
|
document.getElementById('cpuEnhanceApplyCpuBtn').addEventListener('click', cpuEnhanceApplyCpuOnly);
|
||||||
document.getElementById('cpuEnhancePreviewBtn').addEventListener('click', cpuEnhancePreview);
|
document.getElementById('cpuEnhancePreviewBtn').addEventListener('click', cpuEnhancePreview);
|
||||||
document.getElementById('cpuEnhanceActivateBtn').addEventListener('click', cpuEnhanceActivate);
|
document.getElementById('cpuEnhanceActivateBtn').addEventListener('click', cpuEnhanceActivate);
|
||||||
document.getElementById('cpuZoomIn').addEventListener('click', () => cpuEnhanceZoomBy(1.25));
|
document.getElementById('cpuZoomIn').addEventListener('click', () => cpuEnhanceZoomBy(1.25));
|
||||||
|
|||||||
Reference in New Issue
Block a user