fix: repair photo worker broken code; add pending queue view

- Fix runAiEnhance missing return/closing brace from previous commit
- Remove duplicate code fragments in worker.js
- Add renderPhotoPending() to show pending/processing jobs in worker dashboard
- New pending queue table in worker.html photo section
This commit is contained in:
dev
2026-09-17 17:52:51 +03:00
parent 1145be02f3
commit 881b5b4c67
3 changed files with 39 additions and 13 deletions
+8 -13
View File
@@ -136,6 +136,8 @@ function createPhotoEnhanceWorker({ pool, getSetting, logAudit, invalidateEntrie
const out = Buffer.from(await resp.arrayBuffer());
const newName = crypto.randomBytes(12).toString('hex') + '.jpg';
fs.writeFileSync(path.join(uploadsDir, newName), out);
return `/uploads/${newName}`;
}
async function applyResult(job, photoPath, newPath) {
const beforePath = backupOldFile(photoPath);
await pool.query('UPDATE entries SET photo_path = $1 WHERE id = $2', [newPath, job.entry_id]);
@@ -186,6 +188,12 @@ function createPhotoEnhanceWorker({ pool, getSetting, logAudit, invalidateEntrie
`UPDATE photo_jobs SET status = 'error', attempts = $1, error = $2, finished_at = now() WHERE id = $3`,
[tries, message, job.id]
);
stats.errors++;
if (logAudit) await logAudit(null, 'photo.job.error', { entry_id: job.entry_id, job_id: job.id, error: message });
return true;
}
}
async function loop() {
while (!stopped) {
let job = null;
@@ -248,17 +256,6 @@ function createPhotoEnhanceWorker({ pool, getSetting, logAudit, invalidateEntrie
return { start, notify, getInfo };
}
stats.errors++;
if (logAudit) await logAudit(null, 'photo.job.error', { entry_id: job.entry_id, job_id: job.id, error: message });
return true;
}
}
return `/uploads/${newName}`;
}
function createEntryAutoChecker({ pool, getSetting, logAudit, aiUrl, defaultPrompt, model }) {
const AI_URL = aiUrl || process.env.AI_URL || 'http://text-corrector:8080';
const MODEL = model || process.env.AI_MODEL || 'qwen2.5-1.5b-instruct-q4_k_m.gguf';
@@ -514,5 +511,3 @@ function createEntryAutoChecker({ pool, getSetting, logAudit, aiUrl, defaultProm
}
module.exports = { createEntryAutoChecker, createPhotoEnhanceWorker };
(function photoEnhanceWorkerImpl() {})();