import Link from "next/link"; import { createApiKey, deleteApiKey, toggleApiKey } from "@/actions/admin-radio-api-keys"; import { StatusCard } from "@/components/admin/dashboard"; import { prisma } from "@/lib/prisma"; import { Key } from "lucide-react"; import { getTranslations } from "next-intl/server"; 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 formatDate(d: Date | null): string { return d ? d.toISOString().slice(0, 16).replace("T", " ") : "\u2014"; } 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 (

{t("apiKeysForm.title")}

{t("apiKeysForm.subtitle")}

{dbError ? (

{t("apiKeysForm.dbError")}

) : (
0 ? "ok" : "neutral"} icon="\u{2705}" /> 0 ? "warn" : "neutral"} icon="\u{1F6AB}" />
)}

{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)} {formatDate(k.expiresAt)} {k.isActive ? t("apiKeysForm.activeLabel") : t("apiKeysForm.inactiveLabel")}
)}
); }