add fix for predict
This commit is contained in:
29
server.js
29
server.js
@@ -156,7 +156,7 @@ app.post("/api/state", (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.post("/api/passings", (req, res) => {
|
app.post("/api/passings", (req, res) => {
|
||||||
const { sessionId, passing } = req.body || {};
|
const { sessionId, passing, sessionResult } = req.body || {};
|
||||||
if (!sessionId || !passing || typeof passing !== "object") {
|
if (!sessionId || !passing || typeof passing !== "object") {
|
||||||
res.status(400).json({ error: "Expected { sessionId, passing }" });
|
res.status(400).json({ error: "Expected { sessionId, passing }" });
|
||||||
return;
|
return;
|
||||||
@@ -196,6 +196,33 @@ app.post("/api/passings", (req, res) => {
|
|||||||
new Date().toISOString()
|
new Date().toISOString()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Keep app_state hot for overlay clients that hydrate from backend instead of
|
||||||
|
// having their own direct decoder socket.
|
||||||
|
if (sessionResult && typeof sessionResult === "object") {
|
||||||
|
const nowIso = new Date().toISOString();
|
||||||
|
const row = db.prepare("SELECT state_json FROM app_state WHERE id = 1").get();
|
||||||
|
if (row?.state_json) {
|
||||||
|
try {
|
||||||
|
const parsed = JSON.parse(row.state_json);
|
||||||
|
if (!parsed.resultsBySession || typeof parsed.resultsBySession !== "object") {
|
||||||
|
parsed.resultsBySession = {};
|
||||||
|
}
|
||||||
|
parsed.resultsBySession[String(sessionId)] = sessionResult;
|
||||||
|
db.prepare(
|
||||||
|
`
|
||||||
|
INSERT INTO app_state (id, state_json, updated_at)
|
||||||
|
VALUES (1, ?, ?)
|
||||||
|
ON CONFLICT(id) DO UPDATE SET
|
||||||
|
state_json = excluded.state_json,
|
||||||
|
updated_at = excluded.updated_at
|
||||||
|
`
|
||||||
|
).run(JSON.stringify(parsed), nowIso);
|
||||||
|
} catch {
|
||||||
|
// leave app_state untouched if the stored JSON is invalid
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
res.json({ ok: true });
|
res.json({ ok: true });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1551,7 +1551,7 @@ function startOverlaySync() {
|
|||||||
if (currentView === "overlay") {
|
if (currentView === "overlay") {
|
||||||
renderView();
|
renderView();
|
||||||
}
|
}
|
||||||
}, 2000);
|
}, 800);
|
||||||
}
|
}
|
||||||
|
|
||||||
function startOverlayRotation() {
|
function startOverlayRotation() {
|
||||||
@@ -6123,7 +6123,7 @@ async function persistPassingToBackend(sessionId, passing) {
|
|||||||
const res = await fetch(`${getBackendUrl()}/api/passings`, {
|
const res = await fetch(`${getBackendUrl()}/api/passings`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify({ sessionId, passing }),
|
body: JSON.stringify({ sessionId, passing, sessionResult: state.resultsBySession[sessionId] || null }),
|
||||||
});
|
});
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
throw new Error(`HTTP ${res.status}`);
|
throw new Error(`HTTP ${res.status}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user