fix: тема доски синхронизируется между учителем и учениками в реальном времени
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -22,6 +22,7 @@ const GUEST_EVENTS = new Set([
|
||||
'classroom_stroke_updated', 'classroom_page_added', 'classroom_page_changed',
|
||||
'classroom_template_changed', 'classroom_page_cleared', 'classroom_page_renamed',
|
||||
'classroom_page_duplicated', 'classroom_page_deleted', 'classroom_ended',
|
||||
'classroom_board_theme',
|
||||
]);
|
||||
|
||||
/* ── Helper: broadcast to all session participants ─────────────────────── */
|
||||
@@ -490,6 +491,21 @@ function updatePageTemplate(req, res) {
|
||||
res.json({ ok: true, template });
|
||||
}
|
||||
|
||||
/* PATCH /api/classroom/:id/board-theme — change board theme and broadcast to all */
|
||||
function updateBoardTheme(req, res) {
|
||||
const sessionId = Number(req.params.id);
|
||||
const VALID_THEMES = new Set(['chalkboard', 'blackboard', 'whiteboard', 'dark', 'grid', 'dots']);
|
||||
const { theme } = req.body;
|
||||
if (!theme || !VALID_THEMES.has(theme)) return res.status(400).json({ error: 'invalid theme' });
|
||||
const session = db.prepare(`SELECT * FROM classroom_sessions WHERE id=? AND status='active'`).get(sessionId);
|
||||
if (!session) return res.status(404).json({ error: 'Сессия не активна' });
|
||||
if (session.teacher_id !== req.user.id && req.user.role !== 'admin')
|
||||
return res.status(403).json({ error: 'Нет доступа' });
|
||||
db.prepare('UPDATE classroom_sessions SET board_theme=? WHERE id=?').run(theme, sessionId);
|
||||
emitToSession(sessionId, { type: 'classroom_board_theme', sessionId, theme });
|
||||
res.json({ ok: true, theme });
|
||||
}
|
||||
|
||||
/* POST /api/classroom/:id/hand — raise hand */
|
||||
function raiseHand(req, res) {
|
||||
const sessionId = Number(req.params.id);
|
||||
@@ -1521,6 +1537,7 @@ module.exports = {
|
||||
addPage,
|
||||
changePage,
|
||||
updatePageTemplate,
|
||||
updateBoardTheme,
|
||||
getPages,
|
||||
renamePage,
|
||||
duplicatePage,
|
||||
|
||||
@@ -2858,6 +2858,8 @@ db.exec(`
|
||||
|
||||
// Guest token for classroom sessions (public read-only whiteboard access)
|
||||
try { db.exec("ALTER TABLE classroom_sessions ADD COLUMN guest_token TEXT UNIQUE"); } catch {}
|
||||
// Board theme per session (synced to all participants)
|
||||
try { db.exec("ALTER TABLE classroom_sessions ADD COLUMN board_theme TEXT NOT NULL DEFAULT 'chalkboard'"); } catch {}
|
||||
|
||||
// Persistent draw permissions (survives server restart)
|
||||
db.exec(`
|
||||
|
||||
@@ -76,6 +76,7 @@ router.get('/:id/pages', ...auth, c.getPages);
|
||||
router.post('/:id/pages', ...teacher, c.addPage);
|
||||
router.put('/:id/page', ...teacher, c.changePage);
|
||||
router.patch('/:id/page-template', ...teacher, c.updatePageTemplate);
|
||||
router.patch('/:id/board-theme', ...teacher, c.updateBoardTheme);
|
||||
router.patch('/:id/pages/:pageNum/name', ...teacher, c.renamePage);
|
||||
router.post('/:id/pages/:pageNum/duplicate', ...teacher, c.duplicatePage);
|
||||
router.delete('/:id/pages/:pageNum', ...teacher, c.deletePage);
|
||||
|
||||
Reference in New Issue
Block a user