"use client"; import { useCallback, useEffect, useState } from "react"; import { Check, Copy, KeyRound, Link2, Loader2, RefreshCw } from "lucide-react"; import { useToast } from "@/components/Toast"; import { fetchJson } from "@/lib/api"; type Creds = { profile?: string; domain?: string; token?: string; ready?: boolean; role?: string; }; /** VPS assign hero: copyable hub domain + token for physical Neko pairing. */ export function OpsNekoHubCredentialsCard() { const toast = useToast(); const [creds, setCreds] = useState(null); const [loading, setLoading] = useState(true); const [busy, setBusy] = useState(false); const [copied, setCopied] = useState<"domain" | "token" | "both" | "">(""); const load = useCallback(async () => { try { const d = (await fetchJson("/api/ops/neko/hub/credentials")) as Creds; setCreds(d); } catch (e) { toast.push((e as Error).message, "err"); } finally { setLoading(false); } }, [toast]); useEffect(() => { void load(); }, [load]); async function rotate() { setBusy(true); try { const d = (await fetchJson("/api/ops/neko/hub/credentials", { method: "POST", body: JSON.stringify({ rotate_token: true }), })) as Creds; setCreds(d); toast.push("已生成新 Token(请同步到物理机)", "ok"); } catch (e) { toast.push((e as Error).message, "err"); } finally { setBusy(false); } } async function copy(text: string, which: "domain" | "token" | "both") { try { await navigator.clipboard.writeText(text); setCopied(which); toast.push("已复制", "ok"); window.setTimeout(() => setCopied(""), 1500); } catch { toast.push("复制失败", "err"); } } // Only show on VPS profile if (!loading && creds?.profile && creds.profile !== "vps") { return null; } if (loading && !creds) { return (
加载物理机配对凭证…
); } const domain = String(creds?.domain || "").trim(); const token = String(creds?.token || "").trim(); return (
物理机 Neko 配对

粘贴一次域名 + Token 并连接后,后台每 5 秒自动同步;启停实例立刻推送。VPS 分配页下拉会实时更新。

); }