Files
dogfather-universe/server/workspace-probeabend.js
T

54 lines
2.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/* =====================================================================
DER PROBEABEND (05.11.2026, Perfektionsplan Runde 3)
Was nur an Filipes Rechner messbar ist (Saal-Fenster über GTA,
Freistellen auf der RTX, Clip aus dem echten OBS, Stream Deck …), misst
die Seite selbst – hier wird nur das ERGEBNIS je Punkt aufgehoben, damit
die Regie es beim nächsten Mal noch weiß. Eine Zeile in `einstellungen`
(kein neues Schema), nur die Regie liest und schreibt.
===================================================================== */
import { db, protokolliere, echteIp } from "./workspace.js";
export const PROBE_PUNKTE = ["fenster", "freistellen", "clip", "meinmix", "streamdeck", "lautheit"];
const STAENDE = ["offen", "geht", "knapp", "geht_nicht"];
const SCHLUESSEL = "reaktion_probeabend";
export function probeLesen() {
try {
const z = db().prepare("SELECT wert FROM einstellungen WHERE schluessel = ?").get(SCHLUESSEL);
const roh = z ? JSON.parse(z.wert) : {};
const aus = {};
for (const p of PROBE_PUNKTE) {
const e = roh[p];
aus[p] = e && STAENDE.includes(e.stand) ? { stand: e.stand, wann: String(e.wann || ""), wert: String(e.wert || "").slice(0, 160) } : { stand: "offen", wann: "", wert: "" };
}
return aus;
} catch { return Object.fromEntries(PROBE_PUNKTE.map((p) => [p, { stand: "offen", wann: "", wert: "" }])); }
}
export function probeabendWege(probeRouter, { nurHost, kleinerRumpf }) {
probeRouter.use(["/workspace/api/reaktion/probeabend"], kleinerRumpf(1024));
probeRouter.get("/workspace/api/reaktion/probeabend", nurHost, (req, res) => {
res.set("Cache-Control", "no-store");
res.json({ punkte: probeLesen() });
});
probeRouter.put("/workspace/api/reaktion/probeabend", nurHost, (req, res) => {
try {
const punkt = String(req.body?.punkt || "");
const stand = String(req.body?.stand || "");
if (!PROBE_PUNKTE.includes(punkt) || !STAENDE.includes(stand)) return res.status(400).json({ fehler: "probe_unklar" });
const wert = String(req.body?.wert ?? "").replace(/[\u0000-\u001f\u007f]/g, " ").trim().slice(0, 160);
const alle = probeLesen();
alle[punkt] = { stand, wann: new Date().toISOString(), wert };
db().prepare(`INSERT INTO einstellungen (schluessel, wert, geaendert, von) VALUES (?,?,?,?)
ON CONFLICT(schluessel) DO UPDATE SET wert = excluded.wert, geaendert = excluded.geaendert, von = excluded.von`)
.run(SCHLUESSEL, JSON.stringify(alle), new Date().toISOString(), req.person.id);
protokolliere("reaktion_probeabend", { personId: req.person.id, detail: `${punkt}: ${stand}`, ip: echteIp(req) });
res.json({ punkte: alle });
} catch (f) {
console.error("[probeabend]", f?.message);
res.status(503).json({ fehler: "nicht_verfuegbar" });
}
});
}