diff --git a/backend/src/controllers/studentMaterialsController.js b/backend/src/controllers/studentMaterialsController.js index cc89127..7d06dc3 100644 --- a/backend/src/controllers/studentMaterialsController.js +++ b/backend/src/controllers/studentMaterialsController.js @@ -66,7 +66,7 @@ function create(req, res) { } /* 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) { 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' }); @@ -75,6 +75,7 @@ function update(req, res) { const fields = [], args = []; 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.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.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 }); diff --git a/frontend/my-materials.html b/frontend/my-materials.html index d70b9f6..aa7d30e 100644 --- a/frontend/my-materials.html +++ b/frontend/my-materials.html @@ -412,8 +412,14 @@ if (!blob) throw new Error('Не удалось сохранить рисунок'); const fd = new FormData(); fd.append('file', blob, 'drawing.png'); const up = await LS.uploadMaterialFile(fd); - await LS.saveMaterial({ kind: 'image', title: o.title || 'Рисунок', url: up.url, sourceTitle: o.sourceTitle || null }); - close(); load(); LS.toast('Сохранено в «Мои материалы»', 'success'); + if (o.materialId) { + // Аннотация существующего материала — перезаписываем его, а не плодим копии + 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; } }); }; @@ -423,7 +429,7 @@ function annotate(id) { const mt = _mats.find(x => x.id === id); 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;