students: add face reference from the profile photo
POST /api/students/:id/face-refs/from-profile inserts a student_face_refs
row straight from students.photo_path, with no new upload. The file is copied
under a fresh name via storage.copyObject: deleting a ref unlinks its
photo_path, so reusing the original would destroy the profile photo. Path must
start with /uploads/, otherwise 400.
The faces modal gets a "Взять из фото профиля" button, hidden unless the
student has an /uploads/ profile photo (state from GET /api/students/:id/profile).
.face-ref-profile-btn[hidden]{display:none} is required — .btn-primary sets
inline-flex, which overrides the UA [hidden] rule.
This commit is contained in:
@@ -289,6 +289,7 @@ body{font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;b
|
||||
.face-stage img{max-width:100%;max-height:74vh;display:block}
|
||||
.face-stage .face-box{pointer-events:auto}
|
||||
.face-empty{color:var(--muted);font-size:.78rem}
|
||||
.face-ref-profile-btn[hidden]{display:none}
|
||||
.btn-primary.ghost.spinning svg{animation:spin 1s linear infinite}
|
||||
.p-faces{position:absolute;right:8px;top:8px;background:rgba(15,23,42,.72);color:#e2e8f0;font-size:.68rem;font-weight:700;padding:2px 7px;border-radius:999px;pointer-events:none;display:inline-flex;align-items:center;gap:4px}
|
||||
.p-faces svg{width:12px;height:12px}
|
||||
|
||||
+48
-1
@@ -9,6 +9,7 @@ let attachGroupLoaded = false;
|
||||
let faceRefs = [];
|
||||
let facePhotos = [];
|
||||
let faceSimilar = [];
|
||||
let faceProfilePhoto = '';
|
||||
|
||||
async function loadGroupOptions(sel, selected) {
|
||||
if (!groupOptionsLoaded) {
|
||||
@@ -266,12 +267,14 @@ async function openStudentFaces(id, name) {
|
||||
faceRefs = [];
|
||||
facePhotos = [];
|
||||
faceSimilar = [];
|
||||
faceProfilePhoto = '';
|
||||
renderFaceProfileBtn();
|
||||
document.getElementById('studentFacesName').textContent = name || '';
|
||||
renderFaceRefs();
|
||||
renderFacePhotos();
|
||||
renderFaceSimilar();
|
||||
document.getElementById('studentFacesModal').classList.add('open');
|
||||
await Promise.all([loadFaceRefs(id), loadFacePhotos(id)]);
|
||||
await Promise.all([loadFaceRefs(id), loadFacePhotos(id), loadFaceProfilePhoto(id)]);
|
||||
}
|
||||
|
||||
function closeStudentFaces() {
|
||||
@@ -280,6 +283,27 @@ function closeStudentFaces() {
|
||||
faceRefs = [];
|
||||
facePhotos = [];
|
||||
faceSimilar = [];
|
||||
faceProfilePhoto = '';
|
||||
renderFaceProfileBtn();
|
||||
}
|
||||
|
||||
function renderFaceProfileBtn() {
|
||||
const btn = document.getElementById('faceRefProfileBtn');
|
||||
if (btn) btn.hidden = !faceProfilePhoto;
|
||||
}
|
||||
|
||||
async function loadFaceProfilePhoto(id) {
|
||||
faceProfilePhoto = '';
|
||||
try {
|
||||
const res = await fetch(`${API}/api/students/${id}/profile`, { headers: hdr() });
|
||||
if (!res.ok) return;
|
||||
const data = await res.json();
|
||||
if (typeof data.photo_path === 'string' && data.photo_path.startsWith('/uploads/')) faceProfilePhoto = data.photo_path;
|
||||
} catch {
|
||||
faceProfilePhoto = '';
|
||||
} finally {
|
||||
if (profileDataId === id) renderFaceProfileBtn();
|
||||
}
|
||||
}
|
||||
|
||||
async function loadFaceRefs(id) {
|
||||
@@ -346,6 +370,27 @@ async function addFaceRef(file) {
|
||||
}
|
||||
}
|
||||
|
||||
async function addFaceRefFromProfile() {
|
||||
if (!profileDataId) return;
|
||||
showToast('Ищем лицо на фото профиля...');
|
||||
try {
|
||||
const res = await fetch(`${API}/api/students/${profileDataId}/face-refs/from-profile`, { method: 'POST', headers: hdr() });
|
||||
const data = await res.json();
|
||||
if (!res.ok) {
|
||||
showToast(data.error || 'Не удалось добавить эталон');
|
||||
return;
|
||||
}
|
||||
faceRefs.push(data);
|
||||
faceProfilePhoto = '';
|
||||
renderFaceProfileBtn();
|
||||
renderFaceRefs();
|
||||
showToast('Эталон добавлен из фото профиля, пересчитываем лица на всех фото...');
|
||||
refreshFacesAfterRefChange();
|
||||
} catch {
|
||||
showToast('Не удалось добавить эталон');
|
||||
}
|
||||
}
|
||||
|
||||
async function delFaceRef(refId) {
|
||||
try {
|
||||
const res = await fetch(`${API}/api/students/${profileDataId}/face-refs/${refId}`, { method: 'DELETE', headers: hdr() });
|
||||
@@ -357,6 +402,7 @@ async function delFaceRef(refId) {
|
||||
renderFaceRefs();
|
||||
showToast('Эталон удалён, пересчитываем лица...');
|
||||
refreshFacesAfterRefChange();
|
||||
if (profileDataId) loadFaceProfilePhoto(profileDataId);
|
||||
} catch {
|
||||
showToast('Не удалось удалить эталон');
|
||||
}
|
||||
@@ -819,6 +865,7 @@ document.getElementById('pfFacesBtn').addEventListener('click', () => {
|
||||
document.getElementById('studentFacesCloseBtn').addEventListener('click', closeStudentFaces);
|
||||
document.getElementById('studentFacesModal').addEventListener('click', e => { if (e.target === e.currentTarget) closeStudentFaces(); });
|
||||
document.getElementById('faceRefAddBtn').addEventListener('click', () => document.getElementById('faceRefFile').click());
|
||||
document.getElementById('faceRefProfileBtn').addEventListener('click', addFaceRefFromProfile);
|
||||
document.getElementById('faceRefFile').addEventListener('change', e => {
|
||||
const f = e.target.files[0];
|
||||
e.target.value = '';
|
||||
|
||||
@@ -235,6 +235,7 @@
|
||||
<div style="display:flex;gap:10px;align-items:center;flex-wrap:wrap;margin-top:6px">
|
||||
<input type="file" id="faceRefFile" accept="image/*" hidden>
|
||||
<button type="button" class="btn-primary ghost" id="faceRefAddBtn">Добавить эталон</button>
|
||||
<button type="button" class="btn-primary ghost face-ref-profile-btn" id="faceRefProfileBtn" hidden>Взять из фото профиля</button>
|
||||
<span class="hint">1–2 фото анфас при хорошем свете. После добавления система пересчитает лица на всех фото.</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user