fb4880a1d9
Adds an authenticated admin surface gated by auth.users.app_metadata.role==='admin'. - lib/auth/admin-guard.ts: requireAdmin() (pages) + requireAdminApi() (routes) - middleware.ts: defense-in-depth /admin and /api/admin guarding - API: users (list/detail/role/ban/delete), tunnels (list + active/quota/reset/reassign/regenerate-token/delete), metrics, audit log, reserved subdomains - Self-lockout prevention (no self demote/ban/delete) - Best-effort Redis kill-switch via dependency-free net-socket client (REDIS_URL) - admin_audit_log + reserved_subdomains migration (RLS on, service-role only) - Admin UI (overview, users, tunnels, reserved, audit) + conditional nav link
20 lines
515 B
TypeScript
20 lines
515 B
TypeScript
export function formatBytes(n: number): string {
|
|
const num = Number(n) || 0;
|
|
if (num < 1024) return `${num} B`;
|
|
const units = ['KiB', 'MiB', 'GiB', 'TiB', 'PiB'];
|
|
let v = num / 1024;
|
|
let i = 0;
|
|
while (v >= 1024 && i < units.length - 1) {
|
|
v /= 1024;
|
|
i++;
|
|
}
|
|
return `${v.toFixed(2)} ${units[i]}`;
|
|
}
|
|
|
|
export function formatDate(s: string | null | undefined): string {
|
|
if (!s) return '—';
|
|
const d = new Date(s);
|
|
if (Number.isNaN(d.getTime())) return '—';
|
|
return d.toLocaleString();
|
|
}
|