From fa403d7b6a13a181c6bd5320f2723d248b5dd64c Mon Sep 17 00:00:00 2001 From: eric Date: Sat, 5 Sep 2026 02:42:42 -0500 Subject: [PATCH] Promote Neko to top-level nav; always show remote Neko UX on assign cards. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ops sub-tab renamed to 综合; /ops/neko redirects to /neko. Co-authored-by: Cursor --- frontend/src/app/neko/page.tsx | 430 +++++++++++++++++ frontend/src/app/ops/neko/page.tsx | 432 +----------------- frontend/src/components/YtAssignPanel.tsx | 8 + .../src/components/YtRelayProStatusPanel.tsx | 69 ++- frontend/src/lib/shellNav.ts | 10 +- 5 files changed, 499 insertions(+), 450 deletions(-) create mode 100644 frontend/src/app/neko/page.tsx diff --git a/frontend/src/app/neko/page.tsx b/frontend/src/app/neko/page.tsx new file mode 100644 index 0000000..56df69a --- /dev/null +++ b/frontend/src/app/neko/page.tsx @@ -0,0 +1,430 @@ +"use client"; + +import { useCallback, useEffect, useState } from "react"; +import { + ExternalLink, + Loader2, + Monitor, + Plus, + RefreshCw, + Server, + Link2, +} from "lucide-react"; + +import { Shell } from "@/components/Shell"; +import { useToast } from "@/components/Toast"; +import { useConfirm } from "@/components/ConfirmDialog"; +import { fetchJson } from "@/lib/api"; + +type Peer = { + role?: string; + peer_base_url?: string; + public_base?: string; + has_token?: boolean; + token_suffix?: string; + token?: string; + hint?: string; +}; + +type Instance = { + id: string; + slot?: number; + name?: string; + note?: string; + running?: boolean; + want_running?: boolean; + open_url?: string; + http_port?: number; + bind_remote_group_id?: string; + bind_remote_name?: string; + container?: string; +}; + +type RemoteCard = { + id: string; + name?: string; + neko_instance_id?: number; + ops_neko_bound?: boolean; + neko_open_prefer?: string; +}; + +export default function OpsNekoPage() { + const toast = useToast(); + const confirm = useConfirm(); + const [loading, setLoading] = useState(true); + const [busy, setBusy] = useState(""); + const [peer, setPeer] = useState({}); + const [instances, setInstances] = useState([]); + const [hostProfile, setHostProfile] = useState(""); + const [role, setRole] = useState("off"); + const [peerBase, setPeerBase] = useState(""); + const [publicBase, setPublicBase] = useState(""); + const [tokenInput, setTokenInput] = useState(""); + const [remoteCards, setRemoteCards] = useState([]); + const [newName, setNewName] = useState(""); + + const load = useCallback(async () => { + try { + const d = (await fetchJson("/api/ops/neko")) as { + peer?: Peer; + instances?: Instance[]; + host_profile?: { profile?: string }; + }; + setPeer(d.peer || {}); + setInstances(d.instances || []); + setHostProfile(String(d.host_profile?.profile || "")); + setRole(String(d.peer?.role || "off")); + setPeerBase(String(d.peer?.peer_base_url || "")); + setPublicBase(String(d.peer?.public_base || "")); + } catch (e) { + toast.push((e as Error).message, "err"); + } finally { + setLoading(false); + } + }, [toast]); + + useEffect(() => { + void load(); + }, [load]); + + async function savePeer(extra: Record = {}) { + setBusy("peer"); + try { + const d = (await fetchJson("/api/ops/neko/peer", { + method: "POST", + body: JSON.stringify({ + role, + peer_base_url: peerBase, + public_base: publicBase, + token: tokenInput || undefined, + ...extra, + }), + })) as Peer & { token?: string }; + setPeer(d); + if (d.token) { + setTokenInput(d.token); + toast.push("已生成 token(请复制到对端)", "ok"); + } else { + toast.push("配对配置已保存", "ok"); + } + await load(); + } catch (e) { + toast.push((e as Error).message, "err"); + } finally { + setBusy(""); + } + } + + async function createInstance() { + setBusy("create"); + try { + await fetchJson("/api/ops/neko/instances", { + method: "POST", + body: JSON.stringify({ name: newName }), + }); + setNewName(""); + toast.push("已创建 Ops Neko(默认停止,与分配原生 Neko 隔离)", "ok"); + await load(); + } catch (e) { + toast.push((e as Error).message, "err"); + } finally { + setBusy(""); + } + } + + async function act(id: string, action: "start" | "stop" | "delete") { + if (action === "delete") { + const ok = await confirm({ + title: "删除此 Ops Neko?", + message: "只删 Neko Tab 实例,不影响 YouTube 分配页的原生 Neko。", + confirmLabel: "删除", + destructive: true, + }); + if (!ok) return; + } + setBusy(id + action); + try { + if (action === "delete") { + await fetchJson(`/api/ops/neko/instances/${encodeURIComponent(id)}`, { method: "DELETE" }); + } else { + await fetchJson(`/api/ops/neko/instances/${encodeURIComponent(id)}/${action}`, { + method: "POST", + }); + } + await load(); + } catch (e) { + toast.push((e as Error).message, "err"); + } finally { + setBusy(""); + } + } + + async function pullCards() { + setBusy("pull"); + try { + const d = (await fetchJson("/api/ops/neko/remote-cards", { method: "POST" })) as { + ok?: boolean; + cards?: RemoteCard[]; + error?: string; + }; + if (!d.ok) throw new Error(d.error || "拉取失败"); + setRemoteCards(d.cards || []); + toast.push(`已拉取 ${(d.cards || []).length} 张 VPS 分配卡片`, "ok"); + } catch (e) { + toast.push((e as Error).message, "err"); + } finally { + setBusy(""); + } + } + + async function bindAndPush(inst: Instance, card: RemoteCard) { + setBusy("bind"); + try { + await fetchJson(`/api/ops/neko/instances/${encodeURIComponent(inst.id)}`, { + method: "PATCH", + body: JSON.stringify({ + bind_remote_group_id: card.id, + bind_remote_name: card.name || "", + }), + }); + const push = (await fetchJson( + `/api/ops/neko/instances/${encodeURIComponent(inst.id)}/push-bind`, + { method: "POST" }, + )) as { ok?: boolean; error?: string }; + if (!push.ok) throw new Error(push.error || "登记到 VPS 失败"); + toast.push(`已绑定并登记到 VPS:${card.name || card.id}(VPS 原生 Neko 仍保留)`, "ok"); + await load(); + } catch (e) { + toast.push((e as Error).message, "err"); + } finally { + setBusy(""); + } + } + + return ( + +
+
+
+

Neko

+

+ 独立实例池(douyinweb-ops-neko-* + ),与 YouTube 分配页原生 Neko(douyinweb-neko-* + )互不影响。VPS 频道原生 Neko 永远保留、默认停止;物理机在此创建实例后配对到 VPS + 分配卡,分配页用开关选择「打开本机 / 打开远程」。 +

+ {hostProfile ? ( +

当前主机形态:{hostProfile}

+ ) : null} +
+ +
+ +
+

+ + 跨机配对(域名 + Token) +

+

{peer.hint || "选择 hub / edge"}

+
+ + + + +
+
+ + + {role === "edge" ? ( + + ) : null} +
+
+ +
+
+

+ + Ops Neko 实例 +

+
+ setNewName(e.target.value)} + placeholder="名称(可选)" + className="rounded-xl border border-white/10 bg-black/40 px-3 py-2 text-sm text-white" + /> + +
+
+ + {loading ? ( +

加载中…

+ ) : instances.length === 0 ? ( +

暂无实例。物理机建议在此创建;VPS 也可建但默认停着省内存。

+ ) : ( +
    + {instances.map((inst) => ( +
  • +
    +
    +

    + #{inst.slot} {inst.name || "Ops Neko"} + + {inst.running ? "运行中" : "已停止"} + +

    +

    + {inst.container} · :{inst.http_port} + {inst.bind_remote_name + ? ` · 绑定 ${inst.bind_remote_name}` + : inst.bind_remote_group_id + ? ` · 绑定 ${inst.bind_remote_group_id.slice(0, 8)}…` + : ""} +

    +
    +
    + {inst.open_url ? ( + + + 打开 + + ) : null} + + + +
    +
    + {role === "edge" && remoteCards.length > 0 ? ( +
    + 配对到 VPS 分配频道并登记: + {remoteCards.map((c) => ( + + ))} +
    + ) : null} +
  • + ))} +
+ )} +
+
+
+ ); +} diff --git a/frontend/src/app/ops/neko/page.tsx b/frontend/src/app/ops/neko/page.tsx index 309982b..e1ddc5b 100644 --- a/frontend/src/app/ops/neko/page.tsx +++ b/frontend/src/app/ops/neko/page.tsx @@ -1,430 +1,6 @@ -"use client"; +import { redirect } from "next/navigation"; -import { useCallback, useEffect, useState } from "react"; -import { - ExternalLink, - Loader2, - Monitor, - Plus, - RefreshCw, - Server, - Link2, -} from "lucide-react"; - -import { Shell } from "@/components/Shell"; -import { useToast } from "@/components/Toast"; -import { useConfirm } from "@/components/ConfirmDialog"; -import { fetchJson } from "@/lib/api"; - -type Peer = { - role?: string; - peer_base_url?: string; - public_base?: string; - has_token?: boolean; - token_suffix?: string; - token?: string; - hint?: string; -}; - -type Instance = { - id: string; - slot?: number; - name?: string; - note?: string; - running?: boolean; - want_running?: boolean; - open_url?: string; - http_port?: number; - bind_remote_group_id?: string; - bind_remote_name?: string; - container?: string; -}; - -type RemoteCard = { - id: string; - name?: string; - neko_instance_id?: number; - ops_neko_bound?: boolean; - neko_open_prefer?: string; -}; - -export default function OpsNekoPage() { - const toast = useToast(); - const confirm = useConfirm(); - const [loading, setLoading] = useState(true); - const [busy, setBusy] = useState(""); - const [peer, setPeer] = useState({}); - const [instances, setInstances] = useState([]); - const [hostProfile, setHostProfile] = useState(""); - const [role, setRole] = useState("off"); - const [peerBase, setPeerBase] = useState(""); - const [publicBase, setPublicBase] = useState(""); - const [tokenInput, setTokenInput] = useState(""); - const [remoteCards, setRemoteCards] = useState([]); - const [newName, setNewName] = useState(""); - - const load = useCallback(async () => { - try { - const d = (await fetchJson("/api/ops/neko")) as { - peer?: Peer; - instances?: Instance[]; - host_profile?: { profile?: string }; - }; - setPeer(d.peer || {}); - setInstances(d.instances || []); - setHostProfile(String(d.host_profile?.profile || "")); - setRole(String(d.peer?.role || "off")); - setPeerBase(String(d.peer?.peer_base_url || "")); - setPublicBase(String(d.peer?.public_base || "")); - } catch (e) { - toast.push((e as Error).message, "err"); - } finally { - setLoading(false); - } - }, [toast]); - - useEffect(() => { - void load(); - }, [load]); - - async function savePeer(extra: Record = {}) { - setBusy("peer"); - try { - const d = (await fetchJson("/api/ops/neko/peer", { - method: "POST", - body: JSON.stringify({ - role, - peer_base_url: peerBase, - public_base: publicBase, - token: tokenInput || undefined, - ...extra, - }), - })) as Peer & { token?: string }; - setPeer(d); - if (d.token) { - setTokenInput(d.token); - toast.push("已生成 token(请复制到对端)", "ok"); - } else { - toast.push("配对配置已保存", "ok"); - } - await load(); - } catch (e) { - toast.push((e as Error).message, "err"); - } finally { - setBusy(""); - } - } - - async function createInstance() { - setBusy("create"); - try { - await fetchJson("/api/ops/neko/instances", { - method: "POST", - body: JSON.stringify({ name: newName }), - }); - setNewName(""); - toast.push("已创建 Ops Neko(默认停止,与分配原生 Neko 隔离)", "ok"); - await load(); - } catch (e) { - toast.push((e as Error).message, "err"); - } finally { - setBusy(""); - } - } - - async function act(id: string, action: "start" | "stop" | "delete") { - if (action === "delete") { - const ok = await confirm({ - title: "删除此 Ops Neko?", - message: "只删运维 Tab 实例,不影响 YouTube 分配页的原生 Neko。", - confirmLabel: "删除", - destructive: true, - }); - if (!ok) return; - } - setBusy(id + action); - try { - if (action === "delete") { - await fetchJson(`/api/ops/neko/instances/${encodeURIComponent(id)}`, { method: "DELETE" }); - } else { - await fetchJson(`/api/ops/neko/instances/${encodeURIComponent(id)}/${action}`, { - method: "POST", - }); - } - await load(); - } catch (e) { - toast.push((e as Error).message, "err"); - } finally { - setBusy(""); - } - } - - async function pullCards() { - setBusy("pull"); - try { - const d = (await fetchJson("/api/ops/neko/remote-cards", { method: "POST" })) as { - ok?: boolean; - cards?: RemoteCard[]; - error?: string; - }; - if (!d.ok) throw new Error(d.error || "拉取失败"); - setRemoteCards(d.cards || []); - toast.push(`已拉取 ${(d.cards || []).length} 张 VPS 分配卡片`, "ok"); - } catch (e) { - toast.push((e as Error).message, "err"); - } finally { - setBusy(""); - } - } - - async function bindAndPush(inst: Instance, card: RemoteCard) { - setBusy("bind"); - try { - await fetchJson(`/api/ops/neko/instances/${encodeURIComponent(inst.id)}`, { - method: "PATCH", - body: JSON.stringify({ - bind_remote_group_id: card.id, - bind_remote_name: card.name || "", - }), - }); - const push = (await fetchJson( - `/api/ops/neko/instances/${encodeURIComponent(inst.id)}/push-bind`, - { method: "POST" }, - )) as { ok?: boolean; error?: string }; - if (!push.ok) throw new Error(push.error || "登记到 VPS 失败"); - toast.push(`已绑定并登记到 VPS:${card.name || card.id}(VPS 原生 Neko 仍保留)`, "ok"); - await load(); - } catch (e) { - toast.push((e as Error).message, "err"); - } finally { - setBusy(""); - } - } - - return ( - -
-
-
-

运维 · Neko

-

- 独立实例池(douyinweb-ops-neko-* - ),与分配页原生 Neko(douyinweb-neko-* - )互不影响。VPS 频道原生 Neko 永远保留、默认停止;物理机在此创建实例后配对到 VPS - 分配卡,分配页用开关选择「打开本机 / 打开物理机」。 -

- {hostProfile ? ( -

当前主机形态:{hostProfile}

- ) : null} -
- -
- -
-

- - 跨机配对(域名 + Token) -

-

{peer.hint || "选择 hub / edge"}

-
- - - - -
-
- - - {role === "edge" ? ( - - ) : null} -
-
- -
-
-

- - Ops Neko 实例 -

-
- setNewName(e.target.value)} - placeholder="名称(可选)" - className="rounded-xl border border-white/10 bg-black/40 px-3 py-2 text-sm text-white" - /> - -
-
- - {loading ? ( -

加载中…

- ) : instances.length === 0 ? ( -

暂无实例。物理机建议在此创建;VPS 也可建但默认停着省内存。

- ) : ( -
    - {instances.map((inst) => ( -
  • -
    -
    -

    - #{inst.slot} {inst.name || "Ops Neko"} - - {inst.running ? "运行中" : "已停止"} - -

    -

    - {inst.container} · :{inst.http_port} - {inst.bind_remote_name - ? ` · 绑定 ${inst.bind_remote_name}` - : inst.bind_remote_group_id - ? ` · 绑定 ${inst.bind_remote_group_id.slice(0, 8)}…` - : ""} -

    -
    -
    - {inst.open_url ? ( - - - 打开 - - ) : null} - - - -
    -
    - {role === "edge" && remoteCards.length > 0 ? ( -
    - 配对到 VPS 分配频道并登记: - {remoteCards.map((c) => ( - - ))} -
    - ) : null} -
  • - ))} -
- )} -
-
-
- ); +/** Legacy path — Neko is now a top-level tab at /neko */ +export default function OpsNekoRedirect() { + redirect("/neko"); } diff --git a/frontend/src/components/YtAssignPanel.tsx b/frontend/src/components/YtAssignPanel.tsx index 221f3ae..6ab5757 100644 --- a/frontend/src/components/YtAssignPanel.tsx +++ b/frontend/src/components/YtAssignPanel.tsx @@ -95,6 +95,14 @@ type AssignGroup = { neko_instance_id?: number; neko_enabled?: boolean; neko_studio_url?: string; + neko_local_studio_url?: string; + ops_neko_open_url?: string; + ops_neko_bound?: boolean; + ops_neko_slot?: number; + ops_neko_edge_label?: string; + neko_open_prefer?: "local" | "remote"; + neko_open_url?: string; + neko_open_source?: "local" | "remote"; pool?: PoolUrl[]; featured?: FeaturedUrl[]; slots?: SlotUrl[]; diff --git a/frontend/src/components/YtRelayProStatusPanel.tsx b/frontend/src/components/YtRelayProStatusPanel.tsx index 59222d7..ef65930 100644 --- a/frontend/src/components/YtRelayProStatusPanel.tsx +++ b/frontend/src/components/YtRelayProStatusPanel.tsx @@ -200,7 +200,7 @@ export function YtRelayProStatusPanel({ async function setPrefer(prefer: "local" | "remote") { if (prefer === "remote" && !remoteBound) { - toast.push("尚未配对物理机 Neko(运维 → Neko)", "err"); + toast.push("尚未配对远程 Neko(请先到一级 Tab「Neko」完成绑定)", "err"); return; } setNekoBusy(true); @@ -215,7 +215,7 @@ export function YtRelayProStatusPanel({ setOpenPrefer(prefer); } toast.push( - prefer === "remote" ? "默认打开:物理机 Neko(原生实例仍保留)" : "默认打开:本机原生 Neko", + prefer === "remote" ? "默认打开:远程 Neko(本机原生仍保留)" : "默认打开:本机原生 Neko", "ok", ); onNekoChange?.(); @@ -380,14 +380,34 @@ export function YtRelayProStatusPanel({ />

- 本机原生 Neko #{instanceId} 始终保留(默认停止)。可另配对物理机「运维 → Neko」实例;用下方开关选择默认打开目标。密码{" "} + 本机原生 Neko #{instanceId} 始终保留(默认停止)。密码{" "} douyinweb 。地址须带尾斜杠。 {nekoPollErr ? ({nekoPollErr}) : null}

- {remoteBound ? ( -
- 默认打开 + + {/* Remote Neko — always visible UX (paired or empty CTA) */} +
+
+
+

远程 Neko

+

+ {remoteBound + ? `已配对${group.ops_neko_slot ? ` slot #${group.ops_neko_slot}` : ""}${ + group.ops_neko_edge_label ? ` · ${group.ops_neko_edge_label}` : "" + }` + : "尚未配对 — 在物理机一级「Neko」创建实例并登记到本频道"} +

+
+ + 打开 Neko Tab + +
+
+ 默认打开
- {group.ops_neko_edge_label ? ( - {group.ops_neko_edge_label} - ) : null}
- ) : null} + {!remoteBound ? ( +

+ 流程:物理机 Neko Tab → edge + Token → 新建实例 → 拉取 VPS 分配卡 → 绑定本频道并登记。登记后此处可切「远程」。 +

+ ) : null} +
+
{preferredUrl ? ( 打开工作室 - {openPrefer === "remote" && remoteBound ? "(物理机)" : "(本机)"} + {openPrefer === "remote" && remoteBound ? "(远程)" : "(本机)"} ) : null} - {localStudioUrl && remoteBound ? ( + {localStudioUrl ? ( - 物理机 Neko + 远程 Neko - ) : null} + ) : ( + + 去配对远程… + + )}