Web changes: Split shared helpers, bootstrap logic, route groups, and upload-sync behavior out of web.js. Kept web.js focused on wiring and server startup. Fixed screen playlist reassignment so changing a screen’s playlist now triggers a refresh. Fixed single-slide playlist refresh behavior so updates do not get stuck behind the current slide. Player changes: Split websocket/runtime handling into runtime.js. Split playlist assembly and revision hashing into playlist.js. Split onboarding and player HTTP routes into dedicated modules. Split render utilities and template loading into render-helpers.js. Kept player.js mostly as startup/orchestration. Validation: Rebuilt both services with Docker Compose. Smoke-checked web and player routes after the refactor. Verified get_errors was clean on the touched modules.
87 lines
3.3 KiB
JavaScript
87 lines
3.3 KiB
JavaScript
module.exports = function registerAdminPagesRoutes(app, deps) {
|
|
const pool = deps.pool;
|
|
const common = deps.common;
|
|
const pages = deps.pages;
|
|
const buildDashboardState = deps.buildDashboardState;
|
|
|
|
app.get('/admin', async function (req, res, next) {
|
|
try {
|
|
const data = await buildDashboardState(pool);
|
|
res.send(pages.renderDashboardPage(data, req.query.message ? String(req.query.message) : '', req.currentUser));
|
|
} catch (error) {
|
|
next(error);
|
|
}
|
|
});
|
|
|
|
app.get('/admin/clients', async function (req, res, next) {
|
|
try {
|
|
const data = await buildDashboardState(pool);
|
|
res.send(pages.renderConnectedClientsPage(data, req.query.message ? String(req.query.message) : '', req.currentUser));
|
|
} catch (error) {
|
|
next(error);
|
|
}
|
|
});
|
|
|
|
app.get('/admin/screens', async function (req, res, next) {
|
|
try {
|
|
const data = await buildDashboardState(pool);
|
|
if (req.query.edit) {
|
|
const screen = await common.fetchScreenById(pool, Number(req.query.edit));
|
|
if (!screen) {
|
|
return res.status(404).send('Screen not found');
|
|
}
|
|
const editData = await common.fetchScreenEditData(pool);
|
|
return res.send(pages.renderScreenEditPage(screen, editData, req.query.message ? String(req.query.message) : '', req.currentUser));
|
|
}
|
|
res.send(pages.renderScreensPage(data, req.query.message ? String(req.query.message) : '', req.currentUser));
|
|
} catch (error) {
|
|
next(error);
|
|
}
|
|
});
|
|
|
|
app.get('/admin/screens/:id/edit', async function (req, res, next) {
|
|
try {
|
|
const screen = await common.fetchScreenById(pool, Number(req.params.id));
|
|
if (!screen) {
|
|
return res.status(404).send('Screen not found');
|
|
}
|
|
const editData = await common.fetchScreenEditData(pool);
|
|
return res.send(pages.renderScreenEditPage(screen, editData, req.query.message ? String(req.query.message) : '', req.currentUser));
|
|
} catch (error) {
|
|
next(error);
|
|
}
|
|
});
|
|
|
|
app.get('/admin/playlists', async function (req, res, next) {
|
|
try {
|
|
const data = await common.fetchAdminData(pool);
|
|
if (req.query.edit) {
|
|
const playlist = await common.fetchPlaylistById(pool, Number(req.query.edit));
|
|
if (!playlist) {
|
|
return res.status(404).send('Playlist not found');
|
|
}
|
|
return res.send(pages.renderPlaylistEditPage(playlist, data, req.query.message ? String(req.query.message) : '', req.currentUser));
|
|
}
|
|
res.send(pages.renderPlaylistsPage(data, req.query.message ? String(req.query.message) : '', req.currentUser));
|
|
} catch (error) {
|
|
next(error);
|
|
}
|
|
});
|
|
|
|
app.get('/admin/playlists/new', function (req, res) {
|
|
res.send(pages.renderPlaylistFormPage(req.query.message ? String(req.query.message) : '', req.currentUser));
|
|
});
|
|
|
|
app.get('/admin/playlists/:id/edit', async function (req, res, next) {
|
|
try {
|
|
const playlist = await common.fetchPlaylistById(pool, Number(req.params.id));
|
|
if (!playlist) {
|
|
return res.status(404).send('Playlist not found');
|
|
}
|
|
const data = await common.fetchAdminData(pool);
|
|
res.send(pages.renderPlaylistEditPage(playlist, data, req.query.message ? String(req.query.message) : '', req.currentUser));
|
|
} catch (error) {
|
|
next(error);
|
|
}
|
|
});
|
|
}; |