fix(materials): аннотация фото перезаписывает материал, а не плодит копии
Рисование поверх существующего материала (annotate) теперь обновляет ту же запись (LS.updateMaterial url), а не создаёт новую. На бэкенде PATCH /api/materials/:id разрешает менять поле url. Кнопка «Рисунок» (новый с нуля) по-прежнему создаёт новый материал. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -66,7 +66,7 @@ function create(req, res) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* PATCH /api/materials/:id — rename / edit one of the current user's items.
|
/* PATCH /api/materials/:id — rename / edit one of the current user's items.
|
||||||
Editable: title, body. (collection_id/tags wired in a later phase.) */
|
Editable: title, body, url (e.g. re-saving an annotated image), collection_id, tags. */
|
||||||
function update(req, res) {
|
function update(req, res) {
|
||||||
const row = db.prepare('SELECT user_id FROM student_materials WHERE id = ?').get(req.params.id);
|
const row = db.prepare('SELECT user_id FROM student_materials WHERE id = ?').get(req.params.id);
|
||||||
if (!row) return res.status(404).json({ error: 'not found' });
|
if (!row) return res.status(404).json({ error: 'not found' });
|
||||||
@@ -75,6 +75,7 @@ function update(req, res) {
|
|||||||
const fields = [], args = [];
|
const fields = [], args = [];
|
||||||
if (b.title !== undefined) { fields.push('title = ?'); args.push(String(b.title || '').slice(0, 300)); }
|
if (b.title !== undefined) { fields.push('title = ?'); args.push(String(b.title || '').slice(0, 300)); }
|
||||||
if (b.body !== undefined) { fields.push('body = ?'); args.push(b.body != null ? String(b.body).slice(0, 60000) : null); }
|
if (b.body !== undefined) { fields.push('body = ?'); args.push(b.body != null ? String(b.body).slice(0, 60000) : null); }
|
||||||
|
if (b.url !== undefined) { fields.push('url = ?'); args.push(b.url != null ? String(b.url).slice(0, 2000) : null); }
|
||||||
if (b.collection_id !== undefined) { fields.push('collection_id = ?'); args.push(ownCollectionId(b.collection_id, req.user.id)); }
|
if (b.collection_id !== undefined) { fields.push('collection_id = ?'); args.push(ownCollectionId(b.collection_id, req.user.id)); }
|
||||||
if (b.tags !== undefined) { fields.push('tags = ?'); args.push(b.tags != null ? String(b.tags).slice(0, 500) : null); }
|
if (b.tags !== undefined) { fields.push('tags = ?'); args.push(b.tags != null ? String(b.tags).slice(0, 500) : null); }
|
||||||
if (!fields.length) return res.json({ ok: true });
|
if (!fields.length) return res.json({ ok: true });
|
||||||
|
|||||||
@@ -412,8 +412,14 @@
|
|||||||
if (!blob) throw new Error('Не удалось сохранить рисунок');
|
if (!blob) throw new Error('Не удалось сохранить рисунок');
|
||||||
const fd = new FormData(); fd.append('file', blob, 'drawing.png');
|
const fd = new FormData(); fd.append('file', blob, 'drawing.png');
|
||||||
const up = await LS.uploadMaterialFile(fd);
|
const up = await LS.uploadMaterialFile(fd);
|
||||||
await LS.saveMaterial({ kind: 'image', title: o.title || 'Рисунок', url: up.url, sourceTitle: o.sourceTitle || null });
|
if (o.materialId) {
|
||||||
close(); load(); LS.toast('Сохранено в «Мои материалы»', 'success');
|
// Аннотация существующего материала — перезаписываем его, а не плодим копии
|
||||||
|
await LS.updateMaterial(o.materialId, { url: up.url });
|
||||||
|
close(); load(); LS.toast('Изменения сохранены', 'success');
|
||||||
|
} else {
|
||||||
|
await LS.saveMaterial({ kind: 'image', title: o.title || 'Рисунок', url: up.url, sourceTitle: o.sourceTitle || null });
|
||||||
|
close(); load(); LS.toast('Сохранено в «Мои материалы»', 'success');
|
||||||
|
}
|
||||||
} catch (e) { LS.toast(e.message || 'Ошибка', 'error'); btn.disabled = false; }
|
} catch (e) { LS.toast(e.message || 'Ошибка', 'error'); btn.disabled = false; }
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -423,7 +429,7 @@
|
|||||||
function annotate(id) {
|
function annotate(id) {
|
||||||
const mt = _mats.find(x => x.id === id);
|
const mt = _mats.find(x => x.id === id);
|
||||||
if (!mt) return;
|
if (!mt) return;
|
||||||
openDrawModal({ bgImage: mt.url, title: (mt.title || 'Рисунок') + ' (разметка)', sourceTitle: mt.source_title });
|
openDrawModal({ materialId: mt.id, bgImage: mt.url, title: mt.title || 'Рисунок', sourceTitle: mt.source_title });
|
||||||
}
|
}
|
||||||
window.annotate = annotate;
|
window.annotate = annotate;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user