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,61 @@
|
||||
import { Router } from "express";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { z } from "zod";
|
||||
import { db } from "../db/client.js";
|
||||
import { shareLinkDetails, shareLinks } from "../db/schema.js";
|
||||
import { requireAuth, requireRole } from "../auth/middleware.js";
|
||||
import { recordAudit } from "../services/audit.js";
|
||||
import { createShareLink, publicShareLink } from "../services/shareLinks.js";
|
||||
import { asyncHandler } from "../utils/asyncHandler.js";
|
||||
|
||||
export const shareLinksRouter = Router();
|
||||
|
||||
// Making a link that anyone can open without signing in is an administrator's decision.
|
||||
shareLinksRouter.use(requireAuth, requireRole("admin"));
|
||||
|
||||
/** More links than anyone needs; each is something to keep track of and take back. */
|
||||
const MAX_LINKS = 20;
|
||||
|
||||
const createSchema = z.object({
|
||||
label: z.string().trim().min(1).max(60),
|
||||
detail: z.enum(shareLinkDetails),
|
||||
expiresInDays: z.number().int().min(1).max(365).nullable(),
|
||||
});
|
||||
|
||||
shareLinksRouter.get("/", asyncHandler(async (_req, res) => {
|
||||
const rows = await db.select().from(shareLinks).orderBy(shareLinks.createdAt);
|
||||
res.json({ links: rows.map((r) => publicShareLink(r)) });
|
||||
}));
|
||||
|
||||
// The secret part of the address is in this response and nowhere else, ever: only a hash of it is kept.
|
||||
shareLinksRouter.post("/", asyncHandler(async (req, res) => {
|
||||
const parsed = createSchema.safeParse(req.body);
|
||||
if (!parsed.success) {
|
||||
return res.status(400).json({ error: "invalid_body", message: "Give the link a name, say how much it shows, and how long it lasts.", details: parsed.error.flatten() });
|
||||
}
|
||||
const existing = await db.select({ id: shareLinks.id }).from(shareLinks);
|
||||
if (existing.length >= MAX_LINKS) {
|
||||
return res.status(400).json({ error: "too_many", message: `There are already ${MAX_LINKS} share links. Remove one you no longer use first.` });
|
||||
}
|
||||
const actor = req.currentUser!;
|
||||
const { link, token } = await createShareLink({ ...parsed.data, createdBy: actor.name ?? actor.email ?? actor.oidcSub });
|
||||
await recordAudit({
|
||||
actor,
|
||||
category: "share_link",
|
||||
action: "create",
|
||||
targetType: "share_link",
|
||||
targetId: link.id,
|
||||
detail: { label: link.label, detail: link.detail, expiresAt: link.expiresAt },
|
||||
});
|
||||
res.status(201).json({ link: publicShareLink(link), token, path: `/share/wall/${token}` });
|
||||
}));
|
||||
|
||||
shareLinksRouter.delete("/:id", asyncHandler(async (req, res) => {
|
||||
const id = Number(req.params.id);
|
||||
if (!Number.isInteger(id)) return res.status(400).json({ error: "invalid_id" });
|
||||
const [link] = await db.select().from(shareLinks).where(eq(shareLinks.id, id)).limit(1);
|
||||
if (!link) return res.status(404).json({ error: "not_found" });
|
||||
await db.delete(shareLinks).where(eq(shareLinks.id, id));
|
||||
await recordAudit({ actor: req.currentUser!, category: "share_link", action: "delete", targetType: "share_link", targetId: id, detail: { label: link.label } });
|
||||
res.status(204).end();
|
||||
}));
|
||||
Reference in new issue
Block a user