import { THEME_CSS, escapeHtml, tabNavHTML } from "../render/layout";
import { parsePatIpAllowlist, type PatRow, type UserRow } from "../store";
interface Flash {
kind: "ok" | "err";
msg: string;
}
function statusBadge(row: PatRow): string {
if (row.revoked_at) return `已吊销`;
if (row.expires_at && Date.parse(row.expires_at) < Date.now()) {
return `已过期`;
}
return `生效中`;
}
function ipBadge(row: PatRow): string {
const list = parsePatIpAllowlist(row.ip_allowlist ?? "[]");
if (list.length === 0) return `全部`;
return list.map((c) => `${escapeHtml(c)}`).join(" ");
}
export function buildTokensPage(
viewer: UserRow,
rows: PatRow[],
flash: Flash | null
): string {
const flashHtml = flash ? `
| 名称 | token | 状态 | IP 限制 | 最近使用 | 创建 | 过期 | 操作 |
|---|---|---|---|---|---|---|---|
| ${escapeHtml(r.name)} | …${escapeHtml(r.token_last_eight)} |
${statusBadge(r)} | ${ipBadge(r)} | ${lastUsed} | ${escapeHtml(r.created_at.slice(0, 10))} | ${expires} | ${ revoked ? "" : `` } |
${escapeHtml(plaintext)}Authorization: Bearer <token>。任何接受登录 cookie 的端点都接受这个 header。