<%= m.name %>
<%= m.url %>
diff --git a/apps/web/src/dashboard/app.js b/apps/web/src/dashboard/app.js index a986452..28e50b9 100644 --- a/apps/web/src/dashboard/app.js +++ b/apps/web/src/dashboard/app.js @@ -52,28 +52,6 @@ setInterval(() => { }); }, 1000); -// Render a tiny sparkline SVG from latency values -function sparkline(values, width = 120, height = 32) { - if (!values.length) return ''; - const max = Math.max(...values, 1); - const min = Math.min(...values, 0); - const range = max - min || 1; - const step = width / Math.max(values.length - 1, 1); - const points = values.map((v, i) => { - const x = i * step; - const y = height - ((v - min) / range) * (height - 4) - 2; - return `${x},${y}`; - }).join(' '); - return ``; -} - -// Status badge -function statusBadge(up) { - if (up === true) return ''; - if (up === false) return ''; - return ''; -} - function escapeHtml(str) { const div = document.createElement('div'); div.textContent = str; diff --git a/apps/web/src/routes/dashboard.ts b/apps/web/src/routes/dashboard.ts index 6d244f1..a6e4123 100644 --- a/apps/web/src/routes/dashboard.ts +++ b/apps/web/src/routes/dashboard.ts @@ -3,11 +3,58 @@ import { Eta } from "eta"; import { resolve } from "path"; import { resolveKey } from "./auth"; import sql from "../db"; +import { sparkline } from "../utils/sparkline"; const eta = new Eta({ views: resolve(import.meta.dir, "../views"), cache: true, defaultExtension: ".ejs" }); +function timeAgoSSR(date: string | Date): string { + const ts = new Date(date).getTime(); + const s = Math.floor((Date.now() - ts) / 1000); + const text = s < 60 ? `${s}s ago` : s < 3600 ? `${Math.floor(s/60)}m ago` : s < 86400 ? `${Math.floor(s/3600)}h ago` : `${Math.floor(s/86400)}d ago`; + return ``; +} + +const sparklineSSR = sparkline; + +function latencyChartSSR(pings: any[]): string { + const data = pings.filter((c: any) => c.latency_ms != null); + if (data.length < 2) { + return '
<%= m.url %>
No monitors yet
Create your first monitor