import { getTranslations } from "next-intl/server"; import { formatDate } from "@/lib/format-date"; import { createApiKey, deleteApiKey, toggleApiKey, } from "@/actions/admin-radio-api-keys"; import { StatusCard } from "@/components/admin/dashboard"; import { prisma } from "@/lib/prisma"; export const dynamic = "force-dynamic"; export const metadata = { title: "Radio API Keys" }; type ApiKey = { id: bigint; name: string; key: string; allowedIps: string | null; rateLimit: number; lastUsedAt: Date | null; expiresAt: Date | null; isActive: boolean; createdAt: Date | null; }; function maskKey(key: string): string { return key.length > 8 ? `${key.slice(0, 8)}\u2026` : key; } export default async function AdminRadioApiKeysPage() { const t = await getTranslations("pages.admin.radio"); let keys: ApiKey[] = []; let dbError = false; try { keys = await prisma.radioApiKeys .findMany({ select: { id: true, name: true, key: true, allowedIps: true, rateLimit: true, lastUsedAt: true, expiresAt: true, isActive: true, createdAt: true, }, orderBy: [{ isActive: "desc" }, { id: "desc" }], take: 500, }) .catch(() => { dbError = true; return []; }); } catch { dbError = true; keys = []; } const total = keys.length; const activeCount = keys.filter((k) => k.isActive).length; const inactiveCount = total - activeCount; return (
{dbError ? (

{t("apiKeysForm.dbError")}

) : (
0 ? "ok" : "neutral"} icon="✅" /> 0 ? "warn" : "neutral"} icon="🚫" />
)}

{t("apiKeysForm.generateKey")}

{t("apiKeysForm.generateHint")}

{t("apiKeysForm.existingKeys", { count: total })}

{total === 0 ? (
{t("apiKeysForm.noKeys")}
) : (
{keys.map((k) => ( ))}
# {t("apiKeysForm.colName")} {t("apiKeysForm.colKey")} {t("apiKeysForm.colAllowedIps")} {t("apiKeysForm.colRateLimit")} {t("apiKeysForm.colLastUsed")} {t("apiKeysForm.colExpires")} {t("apiKeysForm.colStatus")} {t("apiKeysForm.colActions")}
{String(k.id)} {k.name} {maskKey(k.key)} {k.allowedIps || t("apiKeysForm.any")} {k.rateLimit}/min {formatDate(k.lastUsedAt, "datetime", "\u2014")} {formatDate(k.expiresAt, "datetime", "\u2014")} {k.isActive ? t("apiKeysForm.activeLabel") : t("apiKeysForm.inactiveLabel")}
)}
); }