Обновление страницы ученика, сервера и добавление очистки фото
This commit is contained in:
@@ -67,6 +67,7 @@ const { lessonReportWriteBlocked } = require('./lib/lesson-reports');
|
||||
const { groupOwnedBy } = require('./lib/groups');
|
||||
const { ensureProjectFileSizeColumn, backfillProjectFileSizes } = require('./lib/file-sizes');
|
||||
const { resolveImgbbEndpoint, friendlyApiError } = require('./lib/feedback-imgbb');
|
||||
const { findBrokenFaceRefs, deleteFaceRef } = require('./lib/photo-cleanup');
|
||||
const {
|
||||
ensureDocsTables,
|
||||
docsTree,
|
||||
@@ -11786,6 +11787,79 @@ app.get('/api/students/:id/face-photos', requireAuth, async (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/api/students/:id/faces/broken', requireAuth, async (req, res) => {
|
||||
let id;
|
||||
try {
|
||||
id = reqInt(req.params.id);
|
||||
} catch {
|
||||
return res.status(400).json({ error: 'Неверный id ученика' });
|
||||
}
|
||||
const acc = await studentProfileAccess(req.user, id);
|
||||
if (!acc.found) {
|
||||
return res.status(acc.forbidden ? 403 : 404).json({ error: 'Ученик не найден' });
|
||||
}
|
||||
const limit = Math.min(1000, Math.max(1, safeId(req.query.limit) || 200));
|
||||
const broken = await findBrokenFaceRefs(pool, storage, { studentId: id, limit });
|
||||
res.json({ broken, total: broken.length });
|
||||
});
|
||||
|
||||
app.delete('/api/students/:id/face-refs/:refId/broken', requireAuth, requireAdmin, async (req, res) => {
|
||||
let id, refId;
|
||||
try {
|
||||
id = reqInt(req.params.id);
|
||||
refId = reqInt(req.params.refId);
|
||||
} catch {
|
||||
return res.status(400).json({ error: 'Неверный id' });
|
||||
}
|
||||
const acc = await studentProfileAccess(req.user, id);
|
||||
if (!acc.found) {
|
||||
return res.status(acc.forbidden ? 403 : 404).json({ error: 'Ученик не найден' });
|
||||
}
|
||||
const deleted = await deleteFaceRef(pool, storage, { table: 'student_face_refs', id: refId });
|
||||
if (!deleted) {
|
||||
return res.status(404).json({ error: 'Эталон лица не найден' });
|
||||
}
|
||||
await logAudit(req, 'face_ref.delete_broken', { student_id: id, ref_id: refId, photo_path: deleted.photo_path });
|
||||
res.json({ ok: true, deleted: { id: deleted.id, photo_path: deleted.photo_path } });
|
||||
});
|
||||
|
||||
app.delete('/api/photo-faces/:faceId/broken', requireAuth, requireAdmin, async (req, res) => {
|
||||
let faceId;
|
||||
try {
|
||||
faceId = reqInt(req.params.faceId);
|
||||
} catch {
|
||||
return res.status(400).json({ error: 'Неверный id лица' });
|
||||
}
|
||||
const { rows } = await pool.query('SELECT student_id, photo_path FROM photo_faces WHERE id = $1', [faceId]);
|
||||
if (!rows.length) {
|
||||
return res.status(404).json({ error: 'Лицо не найдено' });
|
||||
}
|
||||
const acc = await studentProfileAccess(req.user, rows[0].student_id);
|
||||
if (!acc.found) {
|
||||
return res.status(acc.forbidden ? 403 : 404).json({ error: 'Нет доступа к этому ученику' });
|
||||
}
|
||||
const deleted = await deleteFaceRef(pool, storage, { table: 'photo_faces', id: faceId });
|
||||
await logAudit(req, 'photo_face.delete_broken', { face_id: faceId, student_id: rows[0].student_id, photo_path: deleted.photo_path });
|
||||
res.json({ ok: true, deleted: { id: deleted.id, photo_path: deleted.photo_path } });
|
||||
});
|
||||
|
||||
app.post('/api/faces/cleanup', requireAuth, requireAdmin, async (req, res) => {
|
||||
const studentId = req.body.student_id ? reqInt(req.body.student_id) : null;
|
||||
const limit = Math.min(5000, Math.max(1, safeId(req.body.limit) || 500));
|
||||
const broken = await findBrokenFaceRefs(pool, storage, { studentId, limit });
|
||||
let deleted = 0;
|
||||
const errors = [];
|
||||
for (const item of broken) {
|
||||
try {
|
||||
await deleteFaceRef(pool, storage, { table: item.table, id: item.id });
|
||||
deleted++;
|
||||
} catch (e) {
|
||||
errors.push({ table: item.table, id: item.id, error: e.message });
|
||||
}
|
||||
}
|
||||
await logAudit(req, 'faces.cleanup_broken', { student_id: studentId || null, deleted, total: broken.length, errors: errors.length });
|
||||
res.json({ deleted, total: broken.length, errors });
|
||||
});
|
||||
|
||||
app.post('/api/faces/scan-unscanned', requireAuth, requireAdmin, async (req, res) => {
|
||||
if (!faceIdConfigured()) return res.status(503).json({ error: 'Face-ID сервис не настроен (FACE_ID_URL)' });
|
||||
|
||||
Reference in New Issue
Block a user