diff --git a/server.js b/server.js index 17a4653..d99390f 100644 --- a/server.js +++ b/server.js @@ -1,6 +1,7 @@ const path = require('path'); const http = require('http'); const crypto = require('crypto'); +const fs = require('fs'); const express = require('express'); const webpush = require('web-push'); @@ -416,6 +417,75 @@ function sendPush(session, result) { // Statische Dateien & Dashboard-Dateien // --------------------------------------------------------------------------- +// Wird in jedes ausgelieferte Dashboard-HTML injiziert: speichert den Zustand +// der Checklisten-Häkchen im localStorage und stellt ihn beim Laden wieder her +// (inkl. „Liste zurücksetzen"-Button). Key = Label-Text der Checkbox, damit +// der Stand auch bei Layout-Änderungen stabil bleibt. +const CHECKLIST_SCRIPT = ``; + +const CHECKLIST_MARKER = 'rc-checks'; + +app.get('/dashboards/:name.html', (req, res, next) => { + const name = path.basename(req.params.name); + const file = path.join(__dirname, 'dashboards', `${name}.html`); + fs.readFile(file, 'utf8', (err, html) => { + if (err) return next(); + if (!html.includes(CHECKLIST_MARKER)) { + html = html.replace(/<\/body>/i, `${CHECKLIST_SCRIPT}\n`); + } + res.setHeader('Cache-Control', 'no-cache'); + res.type('html').send(html); + }); +}); + app.use( '/dashboards', express.static(path.join(__dirname, 'dashboards'), {