Add saved filter views, a customisable dashboard, server comparison, row keyboard navigation and share links
- Table search, status, tag and sort live in the address; Save view pins one as a favourite. - Dashboard cards can be moved and hidden per user (users.dashboard_layout, migration 0022). - Compare two to four servers' load, memory or disk on one chart. - j/k move through table rows that open a detail panel. - Share links open a read-only wall without signing in, numbers only or with names (share_links, migration 0023); the wall is split into a shared view over two data sources. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
906220040e
commit
44e393f172
50 files changed
+6114
-258
No files matched your search
@@ -0,0 +1,86 @@
|
||||
/**
|
||||
* What a share link may show: the wall display's picture of how things are, built here on the server so that nothing beyond it ever
|
||||
* reaches someone who isn't signed in. "summary" is only numbers and an overall state; "names" adds the names of what is wrong, of what
|
||||
* is in maintenance, and of the integrations — but never addresses, tokens or other settings.
|
||||
*/
|
||||
import { db } from "../db/client.js";
|
||||
import { integrations, servers } from "../db/schema.js";
|
||||
import { env } from "../env.js";
|
||||
import { getAlerts } from "./alerts.js";
|
||||
import { getSourceStatus } from "./integrationHealthMonitor.js";
|
||||
import { describeTarget, listActiveWindows, activeSubjects } from "./maintenance.js";
|
||||
import { buildServerSummary } from "./serverSummary.js";
|
||||
import { getSettings } from "./settingsStore.js";
|
||||
import type { ShareLinkDetail } from "../db/schema.js";
|
||||
|
||||
export interface PublicWall {
|
||||
detail: ShareLinkDetail;
|
||||
/** Overall state, decided here exactly as the signed-in wall decides it. */
|
||||
level: "ok" | "warning" | "critical" | "unsure";
|
||||
environment: string | null;
|
||||
servers: { online: number; offline: number };
|
||||
alerts: { critical: number; warning: number };
|
||||
/** Windows running now. */
|
||||
maintenance: number;
|
||||
integrationsFailing: number;
|
||||
/** Only with detail "names". */
|
||||
problems?: { id: string; severity: "critical" | "warning"; message: string }[];
|
||||
maintenanceWindows?: { id: number; name: string; endsAt: string }[];
|
||||
integrations?: { id: number; name: string; type: string; status: "ok" | "failing" | "unknown" }[];
|
||||
generatedAt: string;
|
||||
/** How dates and times are written here — so the board reads the way the rest of the app does. */
|
||||
display: { dateFormat: string; timeFormat: string };
|
||||
}
|
||||
|
||||
const MAX_PROBLEMS = 7;
|
||||
const MAX_WINDOWS = 8;
|
||||
|
||||
export async function buildPublicWall(detail: ShareLinkDetail, now: Date = new Date()): Promise<PublicWall> {
|
||||
const [report, settings, windows, serverRows, integrationRows, subjects] = await Promise.all([
|
||||
getAlerts(false),
|
||||
getSettings(),
|
||||
listActiveWindows(now),
|
||||
db.select({ id: servers.id, name: servers.name, osType: servers.osType, lastSeenAt: servers.lastSeenAt, disks: servers.disks }).from(servers),
|
||||
db.select({ id: integrations.id, name: integrations.name, type: integrations.type, enabled: integrations.enabled }).from(integrations),
|
||||
activeSubjects(now),
|
||||
]);
|
||||
|
||||
const summary = buildServerSummary(serverRows, settings.healthChecks, now.getTime(), subjects);
|
||||
const enabled = integrationRows.filter((i) => i.enabled);
|
||||
const statusOf = (type: string) => getSourceStatus(type).status;
|
||||
const failing = enabled.filter((i) => statusOf(i.type) === "failing");
|
||||
|
||||
const critical = report.counts.critical;
|
||||
const warning = report.counts.warning;
|
||||
const level: PublicWall["level"] = critical > 0 ? "critical" : warning > 0 ? "warning" : report.couldntCheck.length > 0 ? "unsure" : "ok";
|
||||
|
||||
const out: PublicWall = {
|
||||
detail,
|
||||
level,
|
||||
environment: env.environment?.name || null,
|
||||
servers: { online: summary.online, offline: summary.offline.length },
|
||||
alerts: { critical, warning },
|
||||
maintenance: windows.length,
|
||||
integrationsFailing: failing.length,
|
||||
generatedAt: now.toISOString(),
|
||||
display: { dateFormat: settings.display.dateFormat, timeFormat: settings.display.timeFormat },
|
||||
};
|
||||
|
||||
if (detail === "names") {
|
||||
out.problems = report.alerts
|
||||
.filter((a): a is typeof a & { severity: "critical" | "warning" } => !a.silenced && a.severity !== "info")
|
||||
.sort((a, b) => (a.severity === b.severity ? 0 : a.severity === "critical" ? -1 : 1))
|
||||
.slice(0, MAX_PROBLEMS)
|
||||
.map((a) => ({ id: a.id, severity: a.severity, message: a.message }));
|
||||
const named: { id: number; name: string; endsAt: string }[] = [];
|
||||
for (const w of [...windows].sort((a, b) => a.endsAt.localeCompare(b.endsAt))) {
|
||||
const target = await describeTarget(w.targetType, w.targetId);
|
||||
if (target) named.push({ id: w.id, name: target.name, endsAt: w.endsAt });
|
||||
}
|
||||
out.maintenanceWindows = named.slice(0, MAX_WINDOWS);
|
||||
out.integrations = [...enabled]
|
||||
.sort((a, b) => Number(statusOf(b.type) === "failing") - Number(statusOf(a.type) === "failing") || a.name.localeCompare(b.name))
|
||||
.map((i) => ({ id: i.id, name: i.name, type: i.type, status: statusOf(i.type) }));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* Share links: an address that opens a read-only wall display without signing in. The address carries a long random secret; only its
|
||||
* SHA-256 is stored, so the secret can't be read back out of the database or a backup, and it is shown once, when the link is made.
|
||||
*/
|
||||
import { createHash, randomBytes } from "node:crypto";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { db } from "../db/client.js";
|
||||
import { shareLinks, type ShareLinkDetail } from "../db/schema.js";
|
||||
|
||||
export type ShareLinkRow = typeof shareLinks.$inferSelect;
|
||||
|
||||
/** What the public may be told about a link that doesn't work: nothing that tells "never existed" from "ended" or "removed". */
|
||||
export const NOT_FOUND = { error: "not_found", message: "This link doesn't work." } as const;
|
||||
|
||||
const hash = (token: string) => createHash("sha256").update(token).digest("hex");
|
||||
|
||||
/** A link isn't recorded as used more than once in this time, so a screen refreshing every few seconds doesn't write the database each time. */
|
||||
const USED_WRITE_GAP_MS = 60_000;
|
||||
|
||||
export async function createShareLink(params: { label: string; detail: ShareLinkDetail; expiresInDays: number | null; createdBy: string; now?: Date }): Promise<{ link: ShareLinkRow; token: string }> {
|
||||
const now = params.now ?? new Date();
|
||||
const token = randomBytes(24).toString("base64url");
|
||||
const [link] = await db
|
||||
.insert(shareLinks)
|
||||
.values({
|
||||
label: params.label,
|
||||
tokenHash: hash(token),
|
||||
tokenPrefix: token.slice(0, 6),
|
||||
detail: params.detail,
|
||||
createdBy: params.createdBy,
|
||||
expiresAt: params.expiresInDays === null ? null : new Date(now.getTime() + params.expiresInDays * 86_400_000).toISOString(),
|
||||
})
|
||||
.returning();
|
||||
return { link, token };
|
||||
}
|
||||
|
||||
/** The link a secret belongs to, if it exists and has not ended. Notes that it was used. */
|
||||
export async function resolveShareLink(token: string, now: Date = new Date()): Promise<ShareLinkRow | null> {
|
||||
if (typeof token !== "string" || token.length < 16 || token.length > 128) return null;
|
||||
const [link] = await db.select().from(shareLinks).where(eq(shareLinks.tokenHash, hash(token))).limit(1);
|
||||
if (!link) return null;
|
||||
if (link.expiresAt && Date.parse(link.expiresAt) <= now.getTime()) return null;
|
||||
if (!link.lastUsedAt || now.getTime() - Date.parse(link.lastUsedAt) >= USED_WRITE_GAP_MS) {
|
||||
await db.update(shareLinks).set({ lastUsedAt: now.toISOString() }).where(eq(shareLinks.id, link.id));
|
||||
}
|
||||
return link;
|
||||
}
|
||||
|
||||
/** A link as the admin list shows it: everything but the hash. */
|
||||
export function publicShareLink(link: ShareLinkRow, now: Date = new Date()) {
|
||||
return {
|
||||
id: link.id,
|
||||
label: link.label,
|
||||
tokenPrefix: link.tokenPrefix,
|
||||
detail: link.detail,
|
||||
createdBy: link.createdBy,
|
||||
createdAt: link.createdAt,
|
||||
expiresAt: link.expiresAt,
|
||||
lastUsedAt: link.lastUsedAt,
|
||||
expired: !!link.expiresAt && Date.parse(link.expiresAt) <= now.getTime(),
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user