feat(houseofrc): save the club API key server-side and test the connection (1.78.0)

This commit is contained in:
larssand committed 2026-11-07 22:27:13 +01:00
1 parent 7f7af2600d
commit 0c54e8b58a
11 files changed
+280 -4

No files matched your search

+16
View File
@@ -13,6 +13,7 @@ const { createTts, resolvePiperBinary } = require("./server/tts");
const { installAll: installPiperAll, VOICES: PIPER_VOICES } = require("./server/tts_install");
const { createDecoderSimulator } = require("./server/decoder_sim");
const { buildStyledPdf } = require("./server/pdf_render");
const { createHouseOfRc } = require("./server/houseofrc");
const PORT = Number(process.env.PORT || 8081);
const HOST = process.env.HOST || "0.0.0.0";
@@ -20,6 +21,7 @@ const DB_DIR = process.env.RC_TIMING_DATA_DIR ? path.resolve(process.env.RC_TIMI
const DB_PATH = path.join(DB_DIR, "rc_timing.sqlite");
const AMMC_CONFIG_PATH = path.join(DB_DIR, "ammc_config.json");
const auth = createAuth({ dataDir: DB_DIR, allowedCidrs: process.env.RC_ADMIN_ALLOWED_CIDRS || "" });
const houseOfRc = createHouseOfRc({ dataDir: DB_DIR });
const tts = createTts({
dataDir: DB_DIR,
projectDir: __dirname,
@@ -469,6 +471,20 @@ app.post("/api/controller/release", (req, res) => {
res.json(controllerView());
});
// House of RC: the key is write-only from the browser (POST is PIN-protected by the middleware).
app.get("/api/houseofrc/status", (_req, res) => res.json(houseOfRc.status()));
app.post("/api/houseofrc/key", (req, res) => {
try {
res.json({ ok: true, ...houseOfRc.setKey(req.body?.apiKey) });
} catch (error) {
res.status(400).json({ error: error.message });
}
});
app.post("/api/houseofrc/test", async (_req, res) => {
const result = await houseOfRc.testConnection();
res.status(result.ok ? 200 : 502).json(result);
});
app.post("/api/state", (req, res) => {
if (!req.body || typeof req.body !== "object") {
res.status(400).json({ error: "Expected JSON body" });