mirror of
https://github.com/screentinker/screentinker.git
synced 2026-05-15 07:32:23 -06:00
Phase 2: devices.js returns playlist items instead of assignments
GET /:id now queries playlist_items via device.playlist_id. DELETE no longer cleans up assignments table (playlist survives device deletion). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
55c8e354b4
commit
a9aaebc08d
|
|
@ -64,15 +64,22 @@ router.get('/:id', (req, res) => {
|
||||||
'SELECT * FROM screenshots WHERE device_id = ? ORDER BY captured_at DESC LIMIT 1'
|
'SELECT * FROM screenshots WHERE device_id = ? ORDER BY captured_at DESC LIMIT 1'
|
||||||
).get(req.params.id);
|
).get(req.params.id);
|
||||||
|
|
||||||
const assignments = db.prepare(`
|
// Get playlist items if device has an assigned playlist
|
||||||
SELECT a.*, COALESCE(c.filename, w.name) as filename, c.mime_type, c.filepath, c.thumbnail_path, c.duration_sec as content_duration, c.remote_url,
|
let assignments = [];
|
||||||
w.name as widget_name, w.widget_type, w.config as widget_config
|
if (device.playlist_id) {
|
||||||
FROM assignments a
|
assignments = db.prepare(`
|
||||||
LEFT JOIN content c ON a.content_id = c.id
|
SELECT pi.id, pi.content_id, pi.widget_id, pi.sort_order, pi.duration_sec,
|
||||||
LEFT JOIN widgets w ON a.widget_id = w.id
|
pi.created_at, pi.updated_at,
|
||||||
WHERE a.device_id = ?
|
COALESCE(c.filename, w.name) as filename, c.mime_type, c.filepath, c.thumbnail_path,
|
||||||
ORDER BY a.sort_order ASC
|
c.duration_sec as content_duration, c.remote_url,
|
||||||
`).all(req.params.id);
|
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(device.playlist_id);
|
||||||
|
}
|
||||||
|
|
||||||
// Uptime timeline: get status change events for last 24 hours
|
// Uptime timeline: get status change events for last 24 hours
|
||||||
const dayAgo = Math.floor(Date.now() / 1000) - 86400;
|
const dayAgo = Math.floor(Date.now() / 1000) - 86400;
|
||||||
|
|
@ -135,8 +142,7 @@ router.delete('/:id', (req, res) => {
|
||||||
const device = checkDeviceOwnership(req, res);
|
const device = checkDeviceOwnership(req, res);
|
||||||
if (!device) return;
|
if (!device) return;
|
||||||
|
|
||||||
// Clean up related data
|
// Clean up related data (playlist is NOT deleted — may be shared with other devices)
|
||||||
db.prepare('DELETE FROM assignments WHERE device_id = ?').run(req.params.id);
|
|
||||||
db.prepare('DELETE FROM schedules WHERE device_id = ?').run(req.params.id);
|
db.prepare('DELETE FROM schedules WHERE device_id = ?').run(req.params.id);
|
||||||
db.prepare('DELETE FROM screenshots WHERE device_id = ?').run(req.params.id);
|
db.prepare('DELETE FROM screenshots WHERE device_id = ?').run(req.params.id);
|
||||||
db.prepare('DELETE FROM device_telemetry WHERE device_id = ?').run(req.params.id);
|
db.prepare('DELETE FROM device_telemetry WHERE device_id = ?').run(req.params.id);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue