add face library: face recognition, student refs, manual assign

Сервис face-id (insightface/ArcFace) ищет лица на фото групп и записей,
сравнивает их с эталонными фото учеников и предлагает привязки по
процентам косинусного сходства.

- face-id/: FastAPI-сервис /detect, /compare, /health, ленивая загрузка модели
- таблицы photo_faces + student_face_refs, face_scanned_at в фото групп и записей
- настройки: face_id_enabled, face_scan_on_upload, face_id_threshold
- пересчёт привязок по всем фото rematchFaces(): считает по сохранённым
  эмбеддингам, сервис face-id не нужен; автозапуск после добавления эталона
  плюс кнопка в настройках
- просмотрщик фото: рамки с процентом сходства, подсказка-кандидат,
  ручная привязка по всем группам
- бэкап/restore, sweep сиротских файлов, удаление лиц вместе с фото
This commit is contained in:
dev
2026-10-10 12:26:35 +03:00
parent 0c0a9615fa
commit 0356fd4e02
21 changed files with 1867 additions and 25 deletions
+31 -3
View File
@@ -9,13 +9,13 @@ const BACKUP_TABLES = [
'group_photos', 'entry_photos', 'modules', 'student_photos', 'share_links', 'photo_jobs',
'lesson_reports', 'lesson_report_versions', 'audit_log', 'notifications',
'notification_reads', 'banned_ips', 'chat_threads', 'chat_messages', 'chat_attachments',
'short_messages', 'feedbacks', 'bookmarks',
'short_messages', 'feedbacks', 'bookmarks', 'student_face_refs', 'photo_faces',
];
const BACKUP_SEQUENCE_TABLES = [
'groups', 'students', 'entries', 'project_files', 'branches', 'users', 'user_notes', 'group_photos',
'entry_photos', 'modules', 'student_photos', 'share_links', 'photo_jobs', 'lesson_reports',
'lesson_report_versions', 'audit_log', 'notifications', 'chat_threads', 'chat_messages',
'chat_attachments', 'short_messages', 'feedbacks', 'bookmarks',
'chat_attachments', 'short_messages', 'feedbacks', 'bookmarks', 'student_face_refs', 'photo_faces',
];
function isSupportedBackupVersion(data) {
@@ -52,6 +52,13 @@ function optInt(v, lo = -Infinity, hi = Infinity) {
return n;
}
function optFloat(v, lo = -Infinity, hi = Infinity) {
if (v === null || v === undefined || v === '') return 0;
const n = Number(v);
if (!Number.isFinite(n)) return 0;
return Math.min(hi, Math.max(lo, n));
}
function reqStr(v, max) {
if (typeof v !== 'string') throw new Error('Invalid string');
const s = v.trim();
@@ -584,7 +591,28 @@ function normalizeRestoreData(data) {
created_at: optTs(x.created_at),
updated_at: optTs(x.updated_at),
}));
return { groups, students, entries, project_files, settings, branches, users, user_branches, user_settings, user_notes, entry_photos, student_photos, group_photos, share_links, modules, photo_jobs, lesson_reports, lesson_report_versions, audit_log, notifications, notification_reads, banned_ips, chat_threads, chat_messages, chat_attachments, short_messages, feedbacks, bookmarks };
const faceRefs = (data.student_face_refs || []).map(x => ({
id: reqInt(x.id),
student_id: reqInt(x.student_id),
photo_path: optUploadPath(x.photo_path, 300) || '',
embedding: Array.isArray(x.embedding) ? x.embedding : [],
det_score: optFloat(x.det_score, 0, 1),
created_at: optTs(x.created_at),
})).filter(x => x.student_id && x.photo_path);
const faceRows = (data.photo_faces || []).map(x => ({
id: reqInt(x.id),
source_type: x.source_type === 'entry' ? 'entry' : 'group',
source_id: reqInt(x.source_id),
photo_path: optUploadPath(x.photo_path, 300) || '',
bbox: x.bbox && typeof x.bbox === 'object' && !Array.isArray(x.bbox) ? x.bbox : { x: 0, y: 0, w: 0, h: 0 },
embedding: Array.isArray(x.embedding) ? x.embedding : [],
det_score: optFloat(x.det_score, 0, 1),
student_id: x.student_id == null ? null : reqInt(x.student_id),
confidence: optFloat(x.confidence, 0, 1),
created_at: optTs(x.created_at),
updated_at: optTs(x.updated_at),
})).filter(x => x.source_id && x.photo_path);
return { groups, students, entries, project_files, settings, branches, users, user_branches, user_settings, user_notes, entry_photos, student_photos, group_photos, share_links, modules, photo_jobs, lesson_reports, lesson_report_versions, audit_log, notifications, notification_reads, banned_ips, chat_threads, chat_messages, chat_attachments, short_messages, feedbacks, bookmarks, student_face_refs: faceRefs, photo_faces: faceRows };
}
module.exports = {