Селективная очистка битых ссылок на фото лиц
Добавлена модалка #faceBrokenCleanupModal со списком битых ссылок (эталоны student_face_refs и найденные лица photo_faces), выбором отдельных записей и удалением только помеченных. Эндпоинт POST /api/faces/broken/cleanup-all принимает массив ids для точечного удаления, иначе сканирует и удаляет все битые. Каждое удаление аудируется face_ref.delete_broken с фото и учеником.
This commit is contained in:
@@ -11915,9 +11915,30 @@ app.post('/api/faces/broken/scan', requireAuth, requireAdmin, async (req, res) =
|
||||
|
||||
app.post('/api/faces/broken/cleanup-all', requireAuth, requireAdmin, async (req, res) => {
|
||||
const limit = Math.min(10000, Math.max(1, safeId(req.body.limit) || 1000));
|
||||
const result = await cleanupAllBrokenFaceRefs(pool, storage, { limit });
|
||||
await logAudit(req, 'faces.broken_link.cleanup_all', { deleted: result.deleted, total: result.total, errors: result.errors.length });
|
||||
res.json(result);
|
||||
let targets;
|
||||
if (Array.isArray(req.body.ids) && req.body.ids.length) {
|
||||
targets = req.body.ids
|
||||
.filter(i => i && (i.table === 'student_face_refs' || i.table === 'photo_faces') && Number.isInteger(i.id))
|
||||
.map(i => ({ table: i.table, id: i.id }));
|
||||
} else {
|
||||
const broken = await scanAllBrokenFaceRefs(pool, storage, { limit });
|
||||
targets = broken.map(b => ({ table: b.table, id: b.id, photo_path: b.photo_path, student_id: b.student_id }));
|
||||
}
|
||||
let deleted = 0;
|
||||
const errors = [];
|
||||
for (const item of targets) {
|
||||
try {
|
||||
const deletedRow = await deleteFaceRef(pool, storage, { table: item.table, id: item.id });
|
||||
if (deletedRow) {
|
||||
deleted++;
|
||||
await logAudit(req, 'face_ref.delete_broken', { student_id: item.student_id, ref_id: item.id, photo_path: deletedRow.photo_path || item.photo_path });
|
||||
}
|
||||
} catch (e) {
|
||||
errors.push({ table: item.table, id: item.id, error: e.message });
|
||||
}
|
||||
}
|
||||
await logAudit(req, 'faces.broken_link.cleanup_all', { deleted, total: targets.length, errors: errors.length, mode: req.body.ids ? 'selected' : 'all' });
|
||||
res.json({ deleted, total: targets.length, errors });
|
||||
});
|
||||
|
||||
app.post('/api/faces/scan-unscanned', requireAuth, requireAdmin, async (req, res) => {
|
||||
|
||||
Reference in New Issue
Block a user