Add layout API routes (list/save/load/delete)

This commit is contained in:
2026-08-03 14:25:22 +10:00
parent 986f97b49a
commit 8dc791bd46
+21
View File
@@ -79,6 +79,27 @@ app.put('/api/scene', guard, (req, res) => {
});
app.post('/api/scene/reset', guard, (req, res) => res.json(state.resetToSeed()));
// ---------- named layouts (scene + its playlist) ----------
app.get('/api/layouts', (req, res) => res.json(state.listLayouts()));
app.post('/api/layouts', guard, (req, res) => {
try {
const name = (req.body && req.body.name || '').trim();
if (!name) return res.status(400).json({ error: 'name required' });
res.json(state.saveLayout(name, playlist.getConfig()));
} catch (e) { res.status(400).json({ error: String(e.message || e) }); }
});
app.post('/api/layouts/:slug/load', guard, (req, res) => {
try {
const { scene, playlist: pl } = state.loadLayout(req.params.slug);
if (pl) playlist.reloadFromState();
res.json({ scene, layouts: state.listLayouts() });
} catch (e) { res.status(400).json({ error: String(e.message || e) }); }
});
app.delete('/api/layouts/:slug', guard, (req, res) => {
try { res.json(state.deleteLayout(req.params.slug)); }
catch (e) { res.status(400).json({ error: String(e.message || e) }); }
});
// ---------- playlist config ----------
app.get('/api/playlist', (req, res) => res.json(playlist.getConfig()));
app.put('/api/playlist', guard, (req, res) => {