fix: SSE-driven chart/sparkline refresh, debounced server-side partials

This commit is contained in:
M1
2026-03-16 21:21:56 +04:00
parent 2f7273604b
commit 5071e340c7
3 changed files with 54 additions and 11 deletions
+21
View File
@@ -196,5 +196,26 @@ export const dashboard = new Elysia()
});
})
// Sparkline partial — returns just the SVG for one monitor
.get("/dashboard/monitors/:id/sparkline", async ({ cookie, headers, params }) => {
const accountId = await getAccountId(cookie, headers);
if (!accountId) return new Response("Unauthorized", { status: 401 });
const [monitor] = await sql`
SELECT id FROM monitors WHERE id = ${params.id} AND account_id = ${accountId}
`;
if (!monitor) return new Response("Not found", { status: 404 });
const pings = await sql`
SELECT latency_ms FROM pings
WHERE monitor_id = ${params.id} AND latency_ms IS NOT NULL
ORDER BY checked_at DESC LIMIT 20
`;
const latencies = pings.map((p: any) => p.latency_ms).reverse();
return new Response(sparklineSSR(latencies), {
headers: { "content-type": "text/html; charset=utf-8" },
});
})
// Docs
.get("/docs", () => Bun.file(`${dashDir}/docs.html`));