From 52e68ac490776a61cc4890e11a7782f6ed05d0c7 Mon Sep 17 00:00:00 2001 From: ScreenTinker Date: Mon, 11 May 2026 22:28:59 -0500 Subject: [PATCH] fix(playlists): POST /publish returns items with pi.id so post-publish delete works without refresh; future refactor candidate to share SELECT shape with GET /:id --- server/routes/playlists.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/server/routes/playlists.js b/server/routes/playlists.js index 9eecf0b..8542450 100644 --- a/server/routes/playlists.js +++ b/server/routes/playlists.js @@ -175,10 +175,27 @@ router.put('/:id', requirePlaylistWrite, (req, res) => { // Publish playlist — snapshot current items and push to devices router.post('/:id/publish', requirePlaylistWrite, (req, res) => { - const items = buildSnapshotItems(req.params.id); + // Snapshot shape (no pi.id) is intentional — published_snapshot is consumed + // by devices and stored as JSON; row IDs there would be misleading. + const snapshotItems = buildSnapshotItems(req.params.id); db.prepare("UPDATE playlists SET status = 'published', published_snapshot = ?, updated_at = strftime('%s','now') WHERE id = ?") - .run(JSON.stringify(items), req.params.id); + .run(JSON.stringify(snapshotItems), req.params.id); pushToDevices(req.params.id, req); + // UI response shape must include pi.id so the post-publish render can wire + // per-row delete/duration listeners. TODO: refactor to share this SELECT + // with GET /:id (also duplicated in /discard and POST /:id/items/reorder). + const items = db.prepare(` + SELECT pi.*, + COALESCE(c.filename, w.name) as filename, + c.mime_type, c.filepath, c.thumbnail_path, + c.duration_sec as content_duration, c.file_size, c.remote_url, + w.name as widget_name, w.widget_type, w.config as widget_config + FROM playlist_items pi + LEFT JOIN content c ON pi.content_id = c.id + LEFT JOIN widgets w ON pi.widget_id = w.id + WHERE pi.playlist_id = ? + ORDER BY pi.sort_order ASC + `).all(req.params.id); res.json({ ...db.prepare('SELECT * FROM playlists WHERE id = ?').get(req.params.id), items }); });