Promote Neko to top-level nav; always show remote Neko UX on assign cards.

Ops sub-tab renamed to 综合; /ops/neko redirects to /neko.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
eric 2026-09-05 02:42:42 -05:00
parent d3f17f7477
commit fa403d7b6a
5 changed files with 499 additions and 450 deletions

View File

@ -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<Peer>({});
const [instances, setInstances] = useState<Instance[]>([]);
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<RemoteCard[]>([]);
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<string, unknown> = {}) {
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 (
<Shell>
<div className="animate-fade-up space-y-5">
<header className="flex flex-wrap items-start justify-between gap-3">
<div>
<h1 className="font-display text-2xl font-semibold text-white">Neko</h1>
<p className="mt-1 max-w-2xl text-sm text-slate-400">
独立实例池(<span className="font-mono text-slate-300">douyinweb-ops-neko-*</span>
),与 YouTube 分配页原生 Neko(<span className="font-mono text-slate-300">douyinweb-neko-*</span>
)互不影响。VPS 频道原生 Neko 永远保留、默认停止;物理机在此创建实例后配对到 VPS
分配卡,分配页用开关选择「打开本机 / 打开远程」。
</p>
{hostProfile ? (
<p className="mt-1 text-[11px] text-slate-500">当前主机形态:{hostProfile}</p>
) : null}
</div>
<button
type="button"
onClick={() => void load()}
className="inline-flex items-center gap-1.5 rounded-xl border border-white/10 bg-white/5 px-3 py-2 text-xs text-slate-300"
>
<RefreshCw className="h-3.5 w-3.5" />
刷新
</button>
</header>
<section className="rounded-2xl border border-white/10 bg-white/[0.03] p-4">
<h2 className="flex items-center gap-2 text-sm font-medium text-white">
<Server className="h-4 w-4 text-teal-300" />
跨机配对(域名 + Token)
</h2>
<p className="mt-1 text-[11px] text-slate-500">{peer.hint || "选择 hub / edge"}</p>
<div className="mt-3 grid gap-3 sm:grid-cols-2">
<label className="block text-[11px] text-slate-400">
角色
<select
value={role}
onChange={(e) => setRole(e.target.value)}
className="mt-1 w-full rounded-xl border border-white/10 bg-black/40 px-3 py-2 text-sm text-white"
>
<option value="off">off(本机独立)</option>
<option value="hub">hub(通常 VPS:发布分配卡)</option>
<option value="edge">edge(通常物理机:建 Neko 并登记)</option>
</select>
</label>
<label className="block text-[11px] text-slate-400">
Hub 域名(edge 填 VPS,如 https://dylive.nomadro.com)
<input
value={peerBase}
onChange={(e) => setPeerBase(e.target.value)}
className="mt-1 w-full rounded-xl border border-white/10 bg-black/40 px-3 py-2 text-sm text-white"
placeholder="https://dylive.nomadro.com"
/>
</label>
<label className="block text-[11px] text-slate-400">
本机 Neko 公网根(edge 建议 .cn,如 https://dy.nomadro.cn)
<input
value={publicBase}
onChange={(e) => setPublicBase(e.target.value)}
className="mt-1 w-full rounded-xl border border-white/10 bg-black/40 px-3 py-2 text-sm text-white"
placeholder="https://dy.nomadro.cn"
/>
</label>
<label className="block text-[11px] text-slate-400">
Token{peer.has_token ? `(已有 …${peer.token_suffix})` : ""}
<input
value={tokenInput}
onChange={(e) => setTokenInput(e.target.value)}
className="mt-1 w-full rounded-xl border border-white/10 bg-black/40 px-3 py-2 font-mono text-sm text-white"
placeholder="hub 生成后粘贴到 edge"
/>
</label>
</div>
<div className="mt-3 flex flex-wrap gap-2">
<button
type="button"
disabled={Boolean(busy)}
onClick={() => void savePeer()}
className="rounded-xl bg-teal-500/20 px-3 py-2 text-xs text-teal-100 ring-1 ring-teal-400/30"
>
保存配对
</button>
<button
type="button"
disabled={Boolean(busy)}
onClick={() => void savePeer({ rotate_token: true })}
className="rounded-xl border border-white/10 bg-white/5 px-3 py-2 text-xs text-slate-300"
>
生成新 Token(hub)
</button>
{role === "edge" ? (
<button
type="button"
disabled={Boolean(busy)}
onClick={() => void pullCards()}
className="inline-flex items-center gap-1 rounded-xl border border-violet-500/30 bg-violet-500/10 px-3 py-2 text-xs text-violet-100"
>
<Link2 className="h-3.5 w-3.5" />
拉取 VPS 分配卡片
</button>
) : null}
</div>
</section>
<section className="rounded-2xl border border-white/10 bg-white/[0.03] p-4">
<div className="flex flex-wrap items-end justify-between gap-3">
<h2 className="flex items-center gap-2 text-sm font-medium text-white">
<Monitor className="h-4 w-4 text-violet-300" />
Ops Neko 实例
</h2>
<div className="flex flex-wrap gap-2">
<input
value={newName}
onChange={(e) => setNewName(e.target.value)}
placeholder="名称(可选)"
className="rounded-xl border border-white/10 bg-black/40 px-3 py-2 text-sm text-white"
/>
<button
type="button"
disabled={busy === "create"}
onClick={() => void createInstance()}
className="inline-flex items-center gap-1 rounded-xl bg-violet-500/20 px-3 py-2 text-xs text-violet-100 ring-1 ring-violet-400/30"
>
{busy === "create" ? <Loader2 className="h-3.5 w-3.5 animate-spin" /> : <Plus className="h-3.5 w-3.5" />}
新建(默认停止)
</button>
</div>
</div>
{loading ? (
<p className="mt-4 text-sm text-slate-500">加载中…</p>
) : instances.length === 0 ? (
<p className="mt-4 text-sm text-slate-500">暂无实例。物理机建议在此创建;VPS 也可建但默认停着省内存。</p>
) : (
<ul className="mt-4 space-y-3">
{instances.map((inst) => (
<li
key={inst.id}
className="rounded-xl border border-white/10 bg-black/25 p-3"
>
<div className="flex flex-wrap items-center justify-between gap-2">
<div>
<p className="text-sm text-white">
#{inst.slot} {inst.name || "Ops Neko"}
<span
className={`ml-2 rounded-md px-1.5 py-0.5 text-[10px] ${
inst.running
? "bg-emerald-500/20 text-emerald-200"
: "bg-white/5 text-slate-400"
}`}
>
{inst.running ? "运行中" : "已停止"}
</span>
</p>
<p className="mt-0.5 font-mono text-[10px] text-slate-500">
{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)}…`
: ""}
</p>
</div>
<div className="flex flex-wrap gap-1.5">
{inst.open_url ? (
<a
href={inst.open_url}
target="_blank"
rel="noreferrer"
className="inline-flex items-center gap-1 rounded-lg border border-white/10 px-2.5 py-1.5 text-[11px] text-slate-200"
>
<ExternalLink className="h-3 w-3" />
打开
</a>
) : null}
<button
type="button"
disabled={Boolean(busy)}
onClick={() => void act(inst.id, "start")}
className="rounded-lg bg-emerald-500/15 px-2.5 py-1.5 text-[11px] text-emerald-100"
>
启动
</button>
<button
type="button"
disabled={Boolean(busy)}
onClick={() => void act(inst.id, "stop")}
className="rounded-lg bg-rose-500/15 px-2.5 py-1.5 text-[11px] text-rose-100"
>
停止
</button>
<button
type="button"
disabled={Boolean(busy)}
onClick={() => void act(inst.id, "delete")}
className="rounded-lg bg-white/5 px-2.5 py-1.5 text-[11px] text-slate-400"
>
删除
</button>
</div>
</div>
{role === "edge" && remoteCards.length > 0 ? (
<div className="mt-2 flex flex-wrap gap-1.5">
<span className="w-full text-[10px] text-slate-500">配对到 VPS 分配频道并登记:</span>
{remoteCards.map((c) => (
<button
key={c.id}
type="button"
disabled={Boolean(busy)}
onClick={() => void bindAndPush(inst, c)}
className="rounded-lg border border-teal-500/25 bg-teal-500/10 px-2 py-1 text-[10px] text-teal-100"
>
{c.name || c.id.slice(0, 8)}
{c.ops_neko_bound ? " ·已绑" : ""}
</button>
))}
</div>
) : null}
</li>
))}
</ul>
)}
</section>
</div>
</Shell>
);
}

View File

@ -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<Peer>({});
const [instances, setInstances] = useState<Instance[]>([]);
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<RemoteCard[]>([]);
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<string, unknown> = {}) {
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 (
<Shell>
<div className="animate-fade-up space-y-5">
<header className="flex flex-wrap items-start justify-between gap-3">
<div>
<h1 className="font-display text-2xl font-semibold text-white">运维 · Neko</h1>
<p className="mt-1 max-w-2xl text-sm text-slate-400">
独立实例池(<span className="font-mono text-slate-300">douyinweb-ops-neko-*</span>
),与分配页原生 Neko(<span className="font-mono text-slate-300">douyinweb-neko-*</span>
)互不影响。VPS 频道原生 Neko 永远保留、默认停止;物理机在此创建实例后配对到 VPS
分配卡,分配页用开关选择「打开本机 / 打开物理机」。
</p>
{hostProfile ? (
<p className="mt-1 text-[11px] text-slate-500">当前主机形态:{hostProfile}</p>
) : null}
</div>
<button
type="button"
onClick={() => void load()}
className="inline-flex items-center gap-1.5 rounded-xl border border-white/10 bg-white/5 px-3 py-2 text-xs text-slate-300"
>
<RefreshCw className="h-3.5 w-3.5" />
刷新
</button>
</header>
<section className="rounded-2xl border border-white/10 bg-white/[0.03] p-4">
<h2 className="flex items-center gap-2 text-sm font-medium text-white">
<Server className="h-4 w-4 text-teal-300" />
跨机配对(域名 + Token)
</h2>
<p className="mt-1 text-[11px] text-slate-500">{peer.hint || "选择 hub / edge"}</p>
<div className="mt-3 grid gap-3 sm:grid-cols-2">
<label className="block text-[11px] text-slate-400">
角色
<select
value={role}
onChange={(e) => setRole(e.target.value)}
className="mt-1 w-full rounded-xl border border-white/10 bg-black/40 px-3 py-2 text-sm text-white"
>
<option value="off">off(本机独立)</option>
<option value="hub">hub(通常 VPS:发布分配卡)</option>
<option value="edge">edge(通常物理机:建 Neko 并登记)</option>
</select>
</label>
<label className="block text-[11px] text-slate-400">
Hub 域名(edge 填 VPS,如 https://dylive.nomadro.com)
<input
value={peerBase}
onChange={(e) => setPeerBase(e.target.value)}
className="mt-1 w-full rounded-xl border border-white/10 bg-black/40 px-3 py-2 text-sm text-white"
placeholder="https://dylive.nomadro.com"
/>
</label>
<label className="block text-[11px] text-slate-400">
本机 Neko 公网根(edge 建议 .cn,如 https://dy.nomadro.cn)
<input
value={publicBase}
onChange={(e) => setPublicBase(e.target.value)}
className="mt-1 w-full rounded-xl border border-white/10 bg-black/40 px-3 py-2 text-sm text-white"
placeholder="https://dy.nomadro.cn"
/>
</label>
<label className="block text-[11px] text-slate-400">
Token{peer.has_token ? `(已有 …${peer.token_suffix})` : ""}
<input
value={tokenInput}
onChange={(e) => setTokenInput(e.target.value)}
className="mt-1 w-full rounded-xl border border-white/10 bg-black/40 px-3 py-2 font-mono text-sm text-white"
placeholder="hub 生成后粘贴到 edge"
/>
</label>
</div>
<div className="mt-3 flex flex-wrap gap-2">
<button
type="button"
disabled={Boolean(busy)}
onClick={() => void savePeer()}
className="rounded-xl bg-teal-500/20 px-3 py-2 text-xs text-teal-100 ring-1 ring-teal-400/30"
>
保存配对
</button>
<button
type="button"
disabled={Boolean(busy)}
onClick={() => void savePeer({ rotate_token: true })}
className="rounded-xl border border-white/10 bg-white/5 px-3 py-2 text-xs text-slate-300"
>
生成新 Token(hub)
</button>
{role === "edge" ? (
<button
type="button"
disabled={Boolean(busy)}
onClick={() => void pullCards()}
className="inline-flex items-center gap-1 rounded-xl border border-violet-500/30 bg-violet-500/10 px-3 py-2 text-xs text-violet-100"
>
<Link2 className="h-3.5 w-3.5" />
拉取 VPS 分配卡片
</button>
) : null}
</div>
</section>
<section className="rounded-2xl border border-white/10 bg-white/[0.03] p-4">
<div className="flex flex-wrap items-end justify-between gap-3">
<h2 className="flex items-center gap-2 text-sm font-medium text-white">
<Monitor className="h-4 w-4 text-violet-300" />
Ops Neko 实例
</h2>
<div className="flex flex-wrap gap-2">
<input
value={newName}
onChange={(e) => setNewName(e.target.value)}
placeholder="名称(可选)"
className="rounded-xl border border-white/10 bg-black/40 px-3 py-2 text-sm text-white"
/>
<button
type="button"
disabled={busy === "create"}
onClick={() => void createInstance()}
className="inline-flex items-center gap-1 rounded-xl bg-violet-500/20 px-3 py-2 text-xs text-violet-100 ring-1 ring-violet-400/30"
>
{busy === "create" ? <Loader2 className="h-3.5 w-3.5 animate-spin" /> : <Plus className="h-3.5 w-3.5" />}
新建(默认停止)
</button>
</div>
</div>
{loading ? (
<p className="mt-4 text-sm text-slate-500">加载中…</p>
) : instances.length === 0 ? (
<p className="mt-4 text-sm text-slate-500">暂无实例。物理机建议在此创建;VPS 也可建但默认停着省内存。</p>
) : (
<ul className="mt-4 space-y-3">
{instances.map((inst) => (
<li
key={inst.id}
className="rounded-xl border border-white/10 bg-black/25 p-3"
>
<div className="flex flex-wrap items-center justify-between gap-2">
<div>
<p className="text-sm text-white">
#{inst.slot} {inst.name || "Ops Neko"}
<span
className={`ml-2 rounded-md px-1.5 py-0.5 text-[10px] ${
inst.running
? "bg-emerald-500/20 text-emerald-200"
: "bg-white/5 text-slate-400"
}`}
>
{inst.running ? "运行中" : "已停止"}
</span>
</p>
<p className="mt-0.5 font-mono text-[10px] text-slate-500">
{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)}…`
: ""}
</p>
</div>
<div className="flex flex-wrap gap-1.5">
{inst.open_url ? (
<a
href={inst.open_url}
target="_blank"
rel="noreferrer"
className="inline-flex items-center gap-1 rounded-lg border border-white/10 px-2.5 py-1.5 text-[11px] text-slate-200"
>
<ExternalLink className="h-3 w-3" />
打开
</a>
) : null}
<button
type="button"
disabled={Boolean(busy)}
onClick={() => void act(inst.id, "start")}
className="rounded-lg bg-emerald-500/15 px-2.5 py-1.5 text-[11px] text-emerald-100"
>
启动
</button>
<button
type="button"
disabled={Boolean(busy)}
onClick={() => void act(inst.id, "stop")}
className="rounded-lg bg-rose-500/15 px-2.5 py-1.5 text-[11px] text-rose-100"
>
停止
</button>
<button
type="button"
disabled={Boolean(busy)}
onClick={() => void act(inst.id, "delete")}
className="rounded-lg bg-white/5 px-2.5 py-1.5 text-[11px] text-slate-400"
>
删除
</button>
</div>
</div>
{role === "edge" && remoteCards.length > 0 ? (
<div className="mt-2 flex flex-wrap gap-1.5">
<span className="w-full text-[10px] text-slate-500">配对到 VPS 分配频道并登记:</span>
{remoteCards.map((c) => (
<button
key={c.id}
type="button"
disabled={Boolean(busy)}
onClick={() => void bindAndPush(inst, c)}
className="rounded-lg border border-teal-500/25 bg-teal-500/10 px-2 py-1 text-[10px] text-teal-100"
>
{c.name || c.id.slice(0, 8)}
{c.ops_neko_bound ? " ·已绑" : ""}
</button>
))}
</div>
) : null}
</li>
))}
</ul>
)}
</section>
</div>
</Shell>
);
/** Legacy path — Neko is now a top-level tab at /neko */
export default function OpsNekoRedirect() {
redirect("/neko");
}

View File

@ -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[];

View File

@ -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({
/>
</div>
<p className="mt-2 text-[10px] leading-relaxed text-slate-500">
本机原生 Neko #{instanceId} 始终保留(默认停止)。可另配对物理机「运维 → Neko」实例;用下方开关选择默认打开目标。密码{" "}
本机原生 Neko #{instanceId} 始终保留(默认停止)。密码{" "}
<span className="font-mono text-slate-400">douyinweb</span>
。地址须带尾斜杠。
{nekoPollErr ? <span className="ml-2 text-rose-300">({nekoPollErr})</span> : null}
</p>
{remoteBound ? (
<div className="mt-2 flex flex-wrap items-center gap-2 rounded-lg border border-teal-500/20 bg-teal-500/[0.06] px-2.5 py-2">
<span className="text-[10px] text-teal-100/90">默认打开</span>
{/* Remote Neko — always visible UX (paired or empty CTA) */}
<div className="mt-2 space-y-2 rounded-lg border border-teal-500/25 bg-teal-500/[0.07] px-2.5 py-2.5">
<div className="flex flex-wrap items-center justify-between gap-2">
<div className="min-w-0">
<p className="text-[11px] font-medium text-teal-50">远程 Neko</p>
<p className="mt-0.5 text-[10px] text-slate-400">
{remoteBound
? `已配对${group.ops_neko_slot ? ` slot #${group.ops_neko_slot}` : ""}${
group.ops_neko_edge_label ? ` · ${group.ops_neko_edge_label}` : ""
}`
: "尚未配对 — 在物理机一级「Neko」创建实例并登记到本频道"}
</p>
</div>
<Link
href="/neko"
className="shrink-0 rounded-lg border border-teal-400/30 bg-teal-500/10 px-2.5 py-1 text-[10px] text-teal-100 hover:bg-teal-500/20"
>
打开 Neko Tab
</Link>
</div>
<div className="flex flex-wrap items-center gap-2">
<span className="text-[10px] text-slate-400">默认打开</span>
<div className="inline-flex rounded-full border border-white/10 bg-black/30 p-0.5">
<button
type="button"
@ -401,21 +421,27 @@ export function YtRelayProStatusPanel({
</button>
<button
type="button"
disabled={nekoBusy}
disabled={nekoBusy || !remoteBound}
title={remoteBound ? "打开物理机配对实例" : "请先完成远程配对"}
onClick={() => void setPrefer("remote")}
className={`rounded-full px-2.5 py-1 text-[10px] ${
openPrefer === "remote" ? "bg-teal-400/90 text-slate-900" : "text-slate-400"
}`}
openPrefer === "remote" && remoteBound
? "bg-teal-400/90 text-slate-900"
: "text-slate-500"
} disabled:cursor-not-allowed disabled:opacity-40`}
>
物理机 Tab
远程
{group.ops_neko_slot ? ` #${group.ops_neko_slot}` : ""}
</button>
</div>
{group.ops_neko_edge_label ? (
<span className="font-mono text-[10px] text-slate-500">{group.ops_neko_edge_label}</span>
) : null}
</div>
) : null}
{!remoteBound ? (
<p className="text-[10px] leading-relaxed text-slate-500">
流程:物理机 Neko Tab → edge + Token → 新建实例 → 拉取 VPS 分配卡 → 绑定本频道并登记。登记后此处可切「远程」。
</p>
) : null}
</div>
<div className="mt-2 flex flex-wrap gap-1.5">
{preferredUrl ? (
<a
@ -426,10 +452,10 @@ export function YtRelayProStatusPanel({
>
<ExternalLink className="h-3 w-3" />
打开工作室
{openPrefer === "remote" && remoteBound ? "(物理机)" : "(本机)"}
{openPrefer === "remote" && remoteBound ? "(远程)" : "(本机)"}
</a>
) : null}
{localStudioUrl && remoteBound ? (
{localStudioUrl ? (
<a
href={localStudioUrl}
target="_blank"
@ -446,9 +472,16 @@ export function YtRelayProStatusPanel({
rel="noreferrer"
className="inline-flex items-center gap-1 rounded-lg border border-teal-500/30 bg-teal-500/10 px-2.5 py-1.5 text-[11px] text-teal-100 hover:bg-teal-500/20"
>
物理机 Neko
远程 Neko
</a>
) : null}
) : (
<Link
href="/neko"
className="inline-flex items-center gap-1 rounded-lg border border-dashed border-teal-500/30 bg-teal-500/[0.06] px-2.5 py-1.5 text-[11px] text-teal-200/80 hover:bg-teal-500/15"
>
去配对远程…
</Link>
)}
<button
type="button"
disabled={nekoBusy || !nekoEnabled}

View File

@ -8,6 +8,7 @@ export const MAIN_NAV: NavItem[] = [
{ href: "/x", label: "X", emoji: "𝕏" },
{ href: "/web", label: "Web", emoji: "🌐" },
{ href: "/network", label: "网络", emoji: "🔌" },
{ href: "/neko", label: "Neko", emoji: "🖥️" },
{ href: "/ops", label: "运维", emoji: "🛰️" },
{ href: "/settings", label: "设置", emoji: "⚙️" },
];
@ -31,10 +32,9 @@ export const LIVE_TABS: NavItem[] = [
{ href: "/yt-long", label: "长视频", emoji: "🎞️" },
];
/** Sub-tabs under 运维 */
/** Sub-tabs under 运维(Neko 已升为一级导航) */
export const OPS_TABS: NavItem[] = [
{ href: "/ops", label: "运维", emoji: "🛰️" },
{ href: "/ops/neko", label: "Neko", emoji: "🖥️" },
{ href: "/ops", label: "综合", emoji: "🛰️" },
{ href: "/clash", label: "Clash", emoji: "🧿" },
{ href: "/downloads", label: "下载", emoji: "⬇️" },
];
@ -47,7 +47,7 @@ export type NavSection = "overview" | "live" | "ops";
export function navPathActive(pathname: string, href: string): boolean {
if (href === "/") return pathname === "/";
// /ops must not steal /ops/neko (and other ops children)
// /ops must not steal /ops/mobile; /neko is top-level and not under ops
if (href === "/ops") return pathname === "/ops" || pathname.startsWith("/ops/mobile");
return pathname === href || pathname.startsWith(`${href}/`);
}
@ -56,10 +56,12 @@ export function mainNavActive(pathname: string, href: string): boolean {
if (href === "/") return OVERVIEW_PATHS.some((p) => navPathActive(pathname, p));
if (href === "/youtube") return LIVE_PATHS.some((p) => navPathActive(pathname, p));
if (href === "/ops") return OPS_PATHS.some((p) => navPathActive(pathname, p));
if (href === "/neko") return pathname === "/neko" || pathname.startsWith("/neko/") || pathname.startsWith("/ops/neko");
return navPathActive(pathname, href);
}
export function shellSection(pathname: string): NavSection | null {
if (pathname === "/neko" || pathname.startsWith("/neko/") || pathname.startsWith("/ops/neko")) return null;
if (OVERVIEW_PATHS.some((p) => navPathActive(pathname, p))) return "overview";
if (LIVE_PATHS.some((p) => navPathActive(pathname, p))) return "live";
if (OPS_PATHS.some((p) => navPathActive(pathname, p))) return "ops";