Add kiosk launcher downloads and player URL resolution
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
// Screen route registration and dashboard wiring.
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
module.exports = function registerScreensRoutes(app, deps) {
|
||||
const pool = deps.pool;
|
||||
const common = deps.common;
|
||||
@@ -10,6 +12,12 @@ module.exports = function registerScreensRoutes(app, deps) {
|
||||
const requirePermission = deps.requirePermission;
|
||||
|
||||
const LIST_PAGE_SIZE = 25;
|
||||
const batTemplatePath = require.resolve('#root/scripts/pulse-signage-kiosk.bat');
|
||||
const shTemplatePath = require.resolve('#root/scripts/pulse-signage-kiosk.sh');
|
||||
const launcherDownloadPaths = {
|
||||
windows: '/downloads/kiosk/pulse-signage-kiosk.bat',
|
||||
linux: '/downloads/kiosk/pulse-signage-kiosk.sh'
|
||||
};
|
||||
|
||||
function requireQueryPermission(readPermissionKey, editPermissionKey) {
|
||||
return function (req, res, next) {
|
||||
@@ -55,6 +63,36 @@ module.exports = function registerScreensRoutes(app, deps) {
|
||||
});
|
||||
}
|
||||
|
||||
async function buildPlayerUrl() {
|
||||
if (typeof common.fetchPlayerPublicBaseUrl !== 'function') {
|
||||
return null;
|
||||
}
|
||||
|
||||
return common.fetchPlayerPublicBaseUrl(pool);
|
||||
}
|
||||
|
||||
function buildLauncherContent(templatePath, playerUrl) {
|
||||
const template = fs.readFileSync(templatePath, 'utf8');
|
||||
const normalizedPlayerUrl = String(playerUrl || '').trim();
|
||||
if (!normalizedPlayerUrl) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (template.indexOf('http://localhost:8081') === -1) {
|
||||
throw new Error(`Launcher template is missing the default player URL placeholder: ${templatePath}`);
|
||||
}
|
||||
|
||||
return template.replace('http://localhost:8081', normalizedPlayerUrl);
|
||||
}
|
||||
|
||||
function sendLauncherDownload(res, fileName, content) {
|
||||
res.set('Cache-Control', 'no-store, no-cache, must-revalidate, proxy-revalidate');
|
||||
res.set('Pragma', 'no-cache');
|
||||
res.attachment(fileName);
|
||||
res.type('text/plain; charset=utf-8');
|
||||
res.send(content);
|
||||
}
|
||||
|
||||
app.get('/screens', requireQueryPermission('screens.read', 'screens.update'), async function (req, res, next) {
|
||||
try {
|
||||
if (req.query.edit) {
|
||||
@@ -62,6 +100,10 @@ module.exports = function registerScreensRoutes(app, deps) {
|
||||
if (!screen) {
|
||||
return res.status(404).send('Screen not found');
|
||||
}
|
||||
screen.player_url = await buildPlayerUrl();
|
||||
if (screen.player_url) {
|
||||
screen.launcher_downloads = launcherDownloadPaths;
|
||||
}
|
||||
screen.inUse = Boolean(await getScreenDeleteBlockMessage(pool, screen, deps.getScreenConnections));
|
||||
const editData = await common.fetchScreenEditData(pool);
|
||||
return res.send(pages.renderScreenEditPage(screen, editData, req.query.message ? String(req.query.message) : '', req.currentUser));
|
||||
@@ -99,7 +141,10 @@ module.exports = function registerScreensRoutes(app, deps) {
|
||||
const playerUrlsBySlug = typeof common.fetchScreenPlayerUrls === 'function'
|
||||
? await common.fetchScreenPlayerUrls(pool)
|
||||
: {};
|
||||
screen.player_url = screen.slug && playerUrlsBySlug[screen.slug] ? String(playerUrlsBySlug[screen.slug]).trim() : null;
|
||||
screen.player_url = String(playerUrlsBySlug[screen.slug] || '').trim() || null;
|
||||
if (screen.player_url) {
|
||||
screen.launcher_downloads = launcherDownloadPaths;
|
||||
}
|
||||
screen.inUse = Boolean(await getScreenDeleteBlockMessage(pool, screen, deps.getScreenConnections));
|
||||
const editData = await common.fetchScreenEditData(pool);
|
||||
return res.send(pages.renderScreenEditPage(screen, editData, req.query.message ? String(req.query.message) : '', req.currentUser));
|
||||
@@ -107,5 +152,41 @@ module.exports = function registerScreensRoutes(app, deps) {
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
app.get('/downloads/kiosk/pulse-signage-kiosk.bat', requirePermission('screens.update'), async function (_req, res, next) {
|
||||
try {
|
||||
const playerUrl = await buildPlayerUrl();
|
||||
if (!playerUrl) {
|
||||
return res.status(404).send('Player URL is not available yet.');
|
||||
}
|
||||
|
||||
const content = buildLauncherContent(batTemplatePath, playerUrl);
|
||||
if (!content) {
|
||||
return res.status(404).send('Launcher template is not available.');
|
||||
}
|
||||
|
||||
sendLauncherDownload(res, 'pulse-signage-kiosk.bat', content);
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
app.get('/downloads/kiosk/pulse-signage-kiosk.sh', requirePermission('screens.update'), async function (_req, res, next) {
|
||||
try {
|
||||
const playerUrl = await buildPlayerUrl();
|
||||
if (!playerUrl) {
|
||||
return res.status(404).send('Player URL is not available yet.');
|
||||
}
|
||||
|
||||
const content = buildLauncherContent(shTemplatePath, playerUrl);
|
||||
if (!content) {
|
||||
return res.status(404).send('Launcher template is not available.');
|
||||
}
|
||||
|
||||
sendLauncherDownload(res, 'pulse-signage-kiosk.sh', content);
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user