728 lines
30 KiB
TypeScript
728 lines
30 KiB
TypeScript
"use client";
|
||
|
||
import { motion } from "framer-motion";
|
||
import {
|
||
Activity,
|
||
ArrowUpRight,
|
||
ChevronDown,
|
||
CirclePlay,
|
||
Cpu,
|
||
ExternalLink,
|
||
HardDrive,
|
||
MonitorPlay,
|
||
Radio,
|
||
Server,
|
||
Smartphone,
|
||
Sparkles,
|
||
Wifi,
|
||
} from "lucide-react";
|
||
import { useMemo, useState, type ReactNode } from "react";
|
||
|
||
import OverviewCharts from "@/components/OverviewCharts";
|
||
import { LiveStudioScene3D } from "@/components/LiveStudioScene3D";
|
||
import { formatBytes, formatPercent, formatRate, formatUptime, statusLabel, statusPill } from "@/lib/dashboardFormat";
|
||
import { normalizeBrowserReachableHttpUrl } from "@/lib/panelUrls";
|
||
import type { NekoBrowserLink } from "@/lib/nekoLinks";
|
||
|
||
type PortalTheme = "dark" | "light";
|
||
type ViewKey =
|
||
| "dashboard"
|
||
| "services"
|
||
| "live_youtube"
|
||
| "live_tiktok"
|
||
| "android"
|
||
| "studio"
|
||
| "network"
|
||
| "settings";
|
||
|
||
type TFn = (zh: string, en: string) => string;
|
||
|
||
type HubDashboard = {
|
||
snapshot?: {
|
||
cpu_load?: { "1m"?: number; "5m"?: number; "15m"?: number };
|
||
memory?: { total?: number; available?: number; free?: number };
|
||
disk?: { total?: number; free?: number; used?: number };
|
||
netdata?: { available?: boolean; version?: string };
|
||
uptime_seconds?: number;
|
||
};
|
||
hardware?: Record<string, unknown>;
|
||
stack?: {
|
||
hostname?: string;
|
||
mdns_host?: string;
|
||
machine?: string;
|
||
kernel?: string;
|
||
python?: string;
|
||
ips?: string[];
|
||
quick_links?: Record<string, string>;
|
||
neko_login?: {
|
||
user_login?: string;
|
||
user_password?: string;
|
||
admin_login?: string;
|
||
admin_password?: string;
|
||
note_zh?: string;
|
||
};
|
||
};
|
||
services?: Array<{
|
||
service_id: string;
|
||
label: string;
|
||
description: string;
|
||
available: boolean;
|
||
running: boolean;
|
||
status: string;
|
||
url?: string;
|
||
}>;
|
||
live?: {
|
||
backend_mode?: string;
|
||
processes?: Array<{ pm2: string; label?: string; process_status?: string; script?: string }>;
|
||
};
|
||
network?: {
|
||
interfaces?: Array<{
|
||
name?: string;
|
||
rx_bytes?: number;
|
||
tx_bytes?: number;
|
||
rx_bps?: number;
|
||
tx_bps?: number;
|
||
operstate?: string;
|
||
speed_mbps?: number | null;
|
||
}>;
|
||
total_rx_bytes?: number;
|
||
total_tx_bytes?: number;
|
||
total_rx_bps?: number;
|
||
total_tx_bps?: number;
|
||
};
|
||
live_events?: {
|
||
pm2_tail?: string[];
|
||
process_digest?: Array<{ pm2?: string; label?: string; status?: string }>;
|
||
};
|
||
probes?: {
|
||
srs?: {
|
||
port?: number;
|
||
api_port?: number;
|
||
api_ok?: boolean;
|
||
tcp?: { reachable?: boolean; latency_ms?: number };
|
||
http?: { http_code?: number; latency_ms?: number; error?: string; reachable?: boolean };
|
||
};
|
||
neko?: {
|
||
port?: number;
|
||
tcp?: { reachable?: boolean };
|
||
http?: { http_code?: number; reachable?: boolean; error?: string };
|
||
instances?: Array<{ id?: number; port?: number; tcp?: { reachable?: boolean }; http?: { http_code?: number } }>;
|
||
running_count?: number;
|
||
required_count?: number;
|
||
};
|
||
};
|
||
};
|
||
|
||
type DeploymentReport = {
|
||
ready?: boolean;
|
||
pass_count?: number;
|
||
total_count?: number;
|
||
required_total?: number;
|
||
mdns_enabled?: boolean;
|
||
live_edge_enabled?: boolean;
|
||
failing_checks?: Array<{ id: string; label: string; detail?: string }>;
|
||
hints?: string[];
|
||
urls?: Record<string, string>;
|
||
};
|
||
|
||
const QUICK_NAV: Array<{ id: ViewKey; zh: string; en: string; icon: typeof Radio; accent: string }> = [
|
||
{ id: "live_youtube", zh: "YouTube 无人直播", en: "YouTube Live", icon: Radio, accent: "from-rose-500/20 to-violet-500/10 text-rose-100 ring-rose-500/25" },
|
||
{ id: "live_tiktok", zh: "TikTok HDMI", en: "TikTok HDMI", icon: MonitorPlay, accent: "from-cyan-500/20 to-sky-500/10 text-cyan-100 ring-cyan-500/25" },
|
||
{ id: "android", zh: "安卓投屏", en: "Android", icon: Smartphone, accent: "from-emerald-500/20 to-teal-500/10 text-emerald-100 ring-emerald-500/25" },
|
||
{ id: "services", zh: "服务编排", en: "Services", icon: Server, accent: "from-indigo-500/20 to-violet-500/10 text-indigo-100 ring-indigo-500/25" },
|
||
{ id: "network", zh: "网络 / WG", en: "Network", icon: Wifi, accent: "from-amber-500/20 to-orange-500/10 text-amber-100 ring-amber-500/25" },
|
||
{ id: "studio", zh: "工作室", en: "Studio", icon: Sparkles, accent: "from-fuchsia-500/20 to-pink-500/10 text-fuchsia-100 ring-fuchsia-500/25" },
|
||
];
|
||
|
||
const PINNED_LINK_KEYS = [
|
||
"control_plane",
|
||
"netdata",
|
||
"filebrowser",
|
||
"webtty",
|
||
"neko_browser",
|
||
"srs_http",
|
||
"youtube_events",
|
||
] as const;
|
||
|
||
function ringColor(pct: number) {
|
||
if (pct >= 90) return "stroke-rose-400";
|
||
if (pct >= 75) return "stroke-amber-400";
|
||
return "stroke-cyan-400";
|
||
}
|
||
|
||
function MetricRing({
|
||
label,
|
||
value,
|
||
sub,
|
||
pct,
|
||
icon: Icon,
|
||
theme,
|
||
}: {
|
||
label: string;
|
||
value: string;
|
||
sub: string;
|
||
pct?: number;
|
||
icon: typeof Cpu;
|
||
theme: PortalTheme;
|
||
}) {
|
||
const r = 18;
|
||
const c = 2 * Math.PI * r;
|
||
const dash = pct != null ? (pct / 100) * c : 0;
|
||
return (
|
||
<div
|
||
className={`group relative overflow-hidden rounded-2xl border p-3.5 transition hover:-translate-y-0.5 ${
|
||
theme === "light"
|
||
? "border-slate-200/90 bg-white/90 shadow-sm shadow-slate-200/40"
|
||
: "border-white/[0.07] bg-gradient-to-br from-white/[0.06] to-transparent shadow-lg shadow-black/20"
|
||
}`}
|
||
>
|
||
<div className="flex items-start justify-between gap-2">
|
||
<div className="min-w-0 flex-1">
|
||
<div className="flex items-center gap-2">
|
||
<Icon className={`h-4 w-4 shrink-0 ${theme === "light" ? "text-violet-600" : "text-violet-300/90"}`} />
|
||
<p className="text-[10px] font-semibold uppercase tracking-wider text-zinc-500">{label}</p>
|
||
</div>
|
||
<p className={`mt-2 font-mono text-xl font-bold leading-none ${theme === "light" ? "text-slate-900" : "text-white"}`}>{value}</p>
|
||
<p className="mt-1 text-[10px] text-zinc-500">{sub}</p>
|
||
</div>
|
||
{pct != null ? (
|
||
<svg className="h-11 w-11 shrink-0 -rotate-90" viewBox="0 0 44 44" aria-hidden>
|
||
<circle cx="22" cy="22" r={r} fill="none" className="stroke-white/10" strokeWidth="4" />
|
||
<circle
|
||
cx="22"
|
||
cy="22"
|
||
r={r}
|
||
fill="none"
|
||
className={`${ringColor(pct)} transition-all duration-500`}
|
||
strokeWidth="4"
|
||
strokeDasharray={`${dash} ${c}`}
|
||
strokeLinecap="round"
|
||
/>
|
||
<text x="22" y="24" textAnchor="middle" className="fill-zinc-400 text-[8px] font-bold rotate-90 origin-center">
|
||
{pct}%
|
||
</text>
|
||
</svg>
|
||
) : null}
|
||
</div>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
function Section({
|
||
id,
|
||
title,
|
||
subtitle,
|
||
defaultOpen = true,
|
||
theme,
|
||
children,
|
||
badge,
|
||
}: {
|
||
id: string;
|
||
title: string;
|
||
subtitle?: string;
|
||
defaultOpen?: boolean;
|
||
theme: PortalTheme;
|
||
children: ReactNode;
|
||
badge?: ReactNode;
|
||
}) {
|
||
const [open, setOpen] = useState(defaultOpen);
|
||
return (
|
||
<section id={id} className={`overflow-hidden rounded-2xl border ${theme === "light" ? "border-slate-200/90 bg-white/80" : "border-white/[0.07] bg-zinc-950/35"}`}>
|
||
<button
|
||
type="button"
|
||
onClick={() => setOpen((v) => !v)}
|
||
className={`flex w-full items-center gap-3 px-4 py-3.5 text-left transition ${
|
||
theme === "light" ? "hover:bg-slate-50" : "hover:bg-white/[0.03]"
|
||
}`}
|
||
aria-expanded={open}
|
||
>
|
||
<div className="min-w-0 flex-1">
|
||
<div className="flex flex-wrap items-center gap-2">
|
||
<h3 className={`text-sm font-semibold ${theme === "light" ? "text-slate-900" : "text-white"}`}>{title}</h3>
|
||
{badge}
|
||
</div>
|
||
{subtitle ? <p className="mt-0.5 text-[11px] text-zinc-500">{subtitle}</p> : null}
|
||
</div>
|
||
<ChevronDown className={`h-4 w-4 shrink-0 text-zinc-500 transition ${open ? "rotate-180" : ""}`} />
|
||
</button>
|
||
{open ? <div className="border-t border-white/[0.05] px-4 pb-4 pt-3">{children}</div> : null}
|
||
</section>
|
||
);
|
||
}
|
||
|
||
function DashboardSkeleton({ theme }: { theme: PortalTheme }) {
|
||
return (
|
||
<div className="space-y-4 animate-pulse">
|
||
<div className={`h-28 rounded-2xl border ${theme === "light" ? "bg-slate-100" : "bg-white/[0.04]"}`} />
|
||
<div className="grid gap-3 sm:grid-cols-2 xl:grid-cols-4">
|
||
{Array.from({ length: 4 }).map((_, i) => (
|
||
<div key={i} className={`h-24 rounded-2xl border ${theme === "light" ? "bg-slate-100" : "bg-white/[0.04]"}`} />
|
||
))}
|
||
</div>
|
||
<div className={`h-72 rounded-2xl border ${theme === "light" ? "bg-slate-100" : "bg-white/[0.04]"}`} />
|
||
</div>
|
||
);
|
||
}
|
||
|
||
export function DashboardOverview({
|
||
dash,
|
||
deployCheck,
|
||
dashErr,
|
||
loading,
|
||
theme,
|
||
t,
|
||
onNavigate,
|
||
nekoLinks,
|
||
nekoPortsLabel,
|
||
showStreamProbes,
|
||
quickLinks,
|
||
}: {
|
||
dash: HubDashboard | null;
|
||
deployCheck: DeploymentReport | null;
|
||
dashErr: string | null;
|
||
loading: boolean;
|
||
theme: PortalTheme;
|
||
t: TFn;
|
||
onNavigate: (view: ViewKey) => void;
|
||
nekoLinks: NekoBrowserLink[];
|
||
nekoPortsLabel: string;
|
||
showStreamProbes: boolean;
|
||
quickLinks: Record<string, string>;
|
||
}) {
|
||
const onlineServices = dash?.services?.filter((s) => s.running).length ?? 0;
|
||
const totalServices = dash?.services?.length ?? 0;
|
||
const memTotal = dash?.snapshot?.memory?.total || 0;
|
||
const memAvail = dash?.snapshot?.memory?.available ?? dash?.snapshot?.memory?.free ?? 0;
|
||
const memUsed = Math.max(0, memTotal - memAvail);
|
||
const diskTotal = dash?.snapshot?.disk?.total || 0;
|
||
const diskFree = dash?.snapshot?.disk?.free || 0;
|
||
const diskUsed = Math.max(0, diskTotal - diskFree);
|
||
|
||
const liveRows = dash?.live?.processes || [];
|
||
const digest = dash?.live_events?.process_digest || [];
|
||
const liveActive = digest.filter((r) => {
|
||
const s = (r.status || "").toLowerCase();
|
||
return s === "online" || s === "running" || s === "streaming";
|
||
}).length;
|
||
|
||
const pinnedLinks = useMemo(
|
||
() =>
|
||
PINNED_LINK_KEYS.map((key) => ({ key, url: quickLinks[key] }))
|
||
.filter((row) => row.url && /^https?:\/\//i.test(row.url)),
|
||
[quickLinks],
|
||
);
|
||
|
||
const criticalServices = useMemo(
|
||
() =>
|
||
(dash?.services || [])
|
||
.filter((s) => ["live-console", "live-edge", "srs", "neko", "shellcrash"].some((id) => s.service_id.includes(id.replace("live-", "")) || s.service_id === id))
|
||
.slice(0, 6),
|
||
[dash?.services],
|
||
);
|
||
|
||
if (loading && !dash) return <DashboardSkeleton theme={theme} />;
|
||
|
||
return (
|
||
<div className="space-y-5">
|
||
{dashErr ? (
|
||
<div className="rounded-2xl border border-rose-500/25 bg-rose-950/20 p-4 text-sm text-rose-200">
|
||
{t("无法加载仪表盘:", "Dashboard error: ")}
|
||
{dashErr}
|
||
</div>
|
||
) : null}
|
||
|
||
{/* Hero command strip */}
|
||
<motion.div
|
||
initial={{ opacity: 0, y: 10 }}
|
||
animate={{ opacity: 1, y: 0 }}
|
||
className={`relative overflow-hidden rounded-2xl border p-4 sm:p-5 ${
|
||
theme === "light"
|
||
? "border-violet-200/80 bg-gradient-to-br from-violet-50 via-white to-cyan-50 shadow-sm"
|
||
: "border-violet-500/20 bg-gradient-to-br from-violet-600/10 via-zinc-950/80 to-cyan-500/10"
|
||
}`}
|
||
>
|
||
<div className="pointer-events-none absolute -right-8 -top-8 h-40 w-40 rounded-full bg-fuchsia-500/15 blur-3xl" />
|
||
<div className="pointer-events-none absolute -bottom-10 left-1/3 h-32 w-32 rounded-full bg-cyan-500/10 blur-3xl" />
|
||
<div className="relative flex flex-col gap-4 lg:flex-row lg:items-center lg:justify-between">
|
||
<div className="min-w-0">
|
||
<div className="flex flex-wrap items-center gap-2">
|
||
<span className="inline-flex items-center gap-1.5 rounded-full bg-emerald-500/15 px-2.5 py-0.5 text-[10px] font-semibold text-emerald-200 ring-1 ring-emerald-500/30">
|
||
<span className="relative flex h-2 w-2">
|
||
<span className="absolute inline-flex h-full w-full animate-ping rounded-full bg-emerald-400 opacity-60" />
|
||
<span className="relative inline-flex h-2 w-2 rounded-full bg-emerald-400" />
|
||
</span>
|
||
{dash?.stack?.hostname || "live"}
|
||
</span>
|
||
{deployCheck?.ready ? (
|
||
<span className="rounded-full bg-emerald-500/10 px-2 py-0.5 text-[10px] font-medium text-emerald-200 ring-1 ring-emerald-500/20">
|
||
{t("交付就绪", "Deploy ready")}
|
||
</span>
|
||
) : deployCheck ? (
|
||
<span className="rounded-full bg-amber-500/10 px-2 py-0.5 text-[10px] font-medium text-amber-200 ring-1 ring-amber-500/20">
|
||
{t("待验收", "Needs checks")}
|
||
</span>
|
||
) : null}
|
||
{liveActive > 0 ? (
|
||
<span className="rounded-full bg-rose-500/15 px-2 py-0.5 text-[10px] font-semibold text-rose-100 ring-1 ring-rose-500/25">
|
||
{liveActive} {t("路直播活跃", "live lanes active")}
|
||
</span>
|
||
) : null}
|
||
</div>
|
||
<h2 className={`mt-2 text-lg font-bold tracking-tight sm:text-xl ${theme === "light" ? "text-slate-900" : "text-white"}`}>
|
||
{dash?.stack?.mdns_host || "live.local"}
|
||
<span className={`ml-2 text-sm font-normal ${theme === "light" ? "text-slate-500" : "text-zinc-500"}`}>
|
||
{(dash?.stack?.ips || []).join(" · ") || "—"}
|
||
</span>
|
||
</h2>
|
||
<p className="mt-1 text-[11px] text-zinc-500">
|
||
{dash?.stack?.machine} · {dash?.stack?.kernel} · Python {dash?.stack?.python || "—"}
|
||
</p>
|
||
</div>
|
||
<div className="flex flex-wrap gap-2">
|
||
{pinnedLinks.slice(0, 4).map((link) => (
|
||
<a
|
||
key={link.key}
|
||
href={normalizeBrowserReachableHttpUrl(link.url)}
|
||
target="_blank"
|
||
rel="noreferrer"
|
||
className={`inline-flex items-center gap-1.5 rounded-xl border px-3 py-2 text-[11px] font-medium transition hover:-translate-y-0.5 ${
|
||
theme === "light"
|
||
? "border-slate-200 bg-white text-slate-700 shadow-sm"
|
||
: "border-white/10 bg-black/30 text-zinc-200 hover:bg-black/45"
|
||
}`}
|
||
>
|
||
{link.key.replace(/_/g, " ")}
|
||
<ExternalLink className="h-3 w-3 opacity-60" />
|
||
</a>
|
||
))}
|
||
</div>
|
||
</div>
|
||
</motion.div>
|
||
|
||
{/* Quick nav */}
|
||
<div className="grid grid-cols-2 gap-2 sm:grid-cols-3 xl:grid-cols-6">
|
||
{QUICK_NAV.map((item, i) => (
|
||
<motion.button
|
||
key={item.id}
|
||
type="button"
|
||
initial={{ opacity: 0, y: 8 }}
|
||
animate={{ opacity: 1, y: 0 }}
|
||
transition={{ delay: i * 0.04 }}
|
||
whileHover={{ y: -2 }}
|
||
whileTap={{ scale: 0.98 }}
|
||
onClick={() => onNavigate(item.id)}
|
||
className={`flex items-center gap-2 rounded-xl border bg-gradient-to-br px-3 py-3 text-left text-[11px] font-semibold ring-1 transition ${item.accent}`}
|
||
>
|
||
<item.icon className="h-4 w-4 shrink-0 opacity-90" />
|
||
<span className="line-clamp-2 leading-snug">{t(item.zh, item.en)}</span>
|
||
<ArrowUpRight className="ml-auto h-3.5 w-3.5 shrink-0 opacity-50" />
|
||
</motion.button>
|
||
))}
|
||
</div>
|
||
|
||
{/* KPI rings */}
|
||
<div className="grid gap-2 sm:grid-cols-2 xl:grid-cols-4">
|
||
<MetricRing
|
||
theme={theme}
|
||
icon={Cpu}
|
||
label={t("CPU 1m", "CPU 1m")}
|
||
value={dash?.snapshot?.cpu_load?.["1m"]?.toFixed(2) ?? "—"}
|
||
sub={`5m ${dash?.snapshot?.cpu_load?.["5m"]?.toFixed(2) ?? "—"} · 15m ${dash?.snapshot?.cpu_load?.["15m"]?.toFixed(2) ?? "—"}`}
|
||
/>
|
||
<MetricRing
|
||
theme={theme}
|
||
icon={Activity}
|
||
label={t("内存", "Memory")}
|
||
value={formatBytes(memAvail)}
|
||
sub={`/ ${formatBytes(memTotal)}`}
|
||
pct={memTotal ? formatPercent(memUsed, memTotal) : undefined}
|
||
/>
|
||
<MetricRing
|
||
theme={theme}
|
||
icon={HardDrive}
|
||
label={t("磁盘", "Disk")}
|
||
value={formatBytes(diskFree)}
|
||
sub={t("可用", "free")}
|
||
pct={diskTotal ? formatPercent(diskUsed, diskTotal) : undefined}
|
||
/>
|
||
<MetricRing
|
||
theme={theme}
|
||
icon={Server}
|
||
label={t("服务", "Services")}
|
||
value={`${onlineServices}/${totalServices || "—"}`}
|
||
sub={formatUptime(dash?.snapshot?.uptime_seconds) + " " + t("运行", "uptime")}
|
||
/>
|
||
</div>
|
||
|
||
{/* Charts + 3D bento — fixed row height so both panels align */}
|
||
<div className="grid gap-4 xl:grid-cols-5 xl:items-stretch">
|
||
<motion.div
|
||
initial={{ opacity: 0, y: 8 }}
|
||
animate={{ opacity: 1, y: 0 }}
|
||
className={`flex h-[248px] flex-col overflow-hidden xl:col-span-3 rounded-2xl border p-3 backdrop-blur-xl ${
|
||
theme === "light" ? "border-slate-200/90 bg-white/85" : "border-white/[0.07] bg-zinc-950/40"
|
||
}`}
|
||
>
|
||
<OverviewCharts snapshot={dash?.snapshot ?? null} theme={theme} tr={t} compact />
|
||
</motion.div>
|
||
<motion.div
|
||
initial={{ opacity: 0, y: 8 }}
|
||
animate={{ opacity: 1, y: 0 }}
|
||
transition={{ delay: 0.05 }}
|
||
className={`flex h-[248px] flex-col overflow-hidden xl:col-span-2 rounded-2xl border p-3 ${
|
||
theme === "light"
|
||
? "border-fuchsia-200/80 bg-gradient-to-br from-fuchsia-50/90 via-white to-cyan-50/70"
|
||
: "border-fuchsia-500/20 bg-gradient-to-br from-fuchsia-500/10 via-zinc-950/60 to-cyan-500/10"
|
||
}`}
|
||
>
|
||
<LiveStudioScene3D
|
||
tr={t}
|
||
className="h-full"
|
||
liveActive={liveActive}
|
||
onOpenStudio={() => onNavigate("studio")}
|
||
/>
|
||
</motion.div>
|
||
</div>
|
||
|
||
{/* Live pulse + network strip */}
|
||
<div className="grid gap-4 lg:grid-cols-2">
|
||
<div
|
||
className={`rounded-2xl border p-4 ${
|
||
theme === "light" ? "border-violet-200/70 bg-white/90" : "border-violet-500/20 bg-gradient-to-br from-violet-500/[0.08] to-transparent"
|
||
}`}
|
||
>
|
||
<div className="flex items-center justify-between gap-2">
|
||
<h3 className={`text-sm font-semibold ${theme === "light" ? "text-slate-900" : "text-white"}`}>
|
||
{t("直播进程", "Live processes")}
|
||
</h3>
|
||
<span className="rounded-full bg-white/10 px-2 py-0.5 font-mono text-[10px] text-zinc-400">{dash?.live?.backend_mode || "—"}</span>
|
||
</div>
|
||
<ul className="mt-3 max-h-52 space-y-2 overflow-y-auto pr-1">
|
||
{(liveRows.length ? liveRows : digest).slice(0, 8).map((p) => {
|
||
const pm2 = "pm2" in p ? p.pm2 : "";
|
||
const label = ("label" in p && p.label) || pm2;
|
||
const status = ("process_status" in p && p.process_status) || ("status" in p && p.status) || "";
|
||
const laneHint = `${pm2} ${label}`.toLowerCase();
|
||
const laneView: ViewKey | null = laneHint.includes("tiktok") || laneHint.includes("hdmi")
|
||
? "live_tiktok"
|
||
: laneHint.includes("youtube") || laneHint.includes("yt")
|
||
? "live_youtube"
|
||
: null;
|
||
return (
|
||
<li
|
||
key={pm2 || label}
|
||
role={laneView ? "button" : undefined}
|
||
tabIndex={laneView ? 0 : undefined}
|
||
onClick={laneView ? () => onNavigate(laneView) : undefined}
|
||
onKeyDown={
|
||
laneView
|
||
? (e) => {
|
||
if (e.key === "Enter" || e.key === " ") {
|
||
e.preventDefault();
|
||
onNavigate(laneView);
|
||
}
|
||
}
|
||
: undefined
|
||
}
|
||
className={`flex items-center gap-3 rounded-xl border px-3 py-2 transition ${
|
||
theme === "light" ? "border-slate-200 bg-slate-50/80" : "border-white/[0.06] bg-black/25 hover:border-violet-400/20"
|
||
} ${laneView ? "cursor-pointer hover:-translate-y-px hover:border-violet-400/30" : ""}`}
|
||
>
|
||
<CirclePlay className="h-4 w-4 shrink-0 text-violet-300/80" />
|
||
<div className="min-w-0 flex-1">
|
||
<p className="truncate text-xs font-medium text-zinc-200">{label}</p>
|
||
<p className="truncate font-mono text-[10px] text-zinc-600">{pm2}</p>
|
||
</div>
|
||
<span className={`shrink-0 rounded-md px-2 py-0.5 text-[10px] font-medium ${statusPill(status || "")}`}>
|
||
{statusLabel(status || "", t)}
|
||
</span>
|
||
</li>
|
||
);
|
||
})}
|
||
{!liveRows.length && !digest.length ? (
|
||
<li className="py-6 text-center text-xs text-zinc-600">{t("暂无直播进程", "No live processes")}</li>
|
||
) : null}
|
||
</ul>
|
||
<div className="mt-3 grid grid-cols-2 gap-2">
|
||
<button
|
||
type="button"
|
||
onClick={() => onNavigate("live_youtube")}
|
||
className="rounded-xl bg-violet-500/20 py-2 text-[11px] font-semibold text-violet-100 ring-1 ring-violet-500/30 transition hover:bg-violet-500/30"
|
||
>
|
||
YouTube
|
||
</button>
|
||
<button
|
||
type="button"
|
||
onClick={() => onNavigate("live_tiktok")}
|
||
className="rounded-xl bg-cyan-500/20 py-2 text-[11px] font-semibold text-cyan-100 ring-1 ring-cyan-500/30 transition hover:bg-cyan-500/30"
|
||
>
|
||
TikTok
|
||
</button>
|
||
</div>
|
||
</div>
|
||
|
||
{dash?.network?.interfaces?.length ? (
|
||
<div className={`rounded-2xl border p-4 ${theme === "light" ? "border-cyan-200/70 bg-white/90" : "border-cyan-500/15 bg-cyan-500/[0.05]"}`}>
|
||
<h3 className={`flex items-center gap-2 text-sm font-semibold ${theme === "light" ? "text-slate-900" : "text-white"}`}>
|
||
<Wifi className="h-4 w-4 text-cyan-300" />
|
||
{t("网络吞吐", "Network throughput")}
|
||
</h3>
|
||
<div className="mt-3 grid grid-cols-2 gap-2">
|
||
<div className="rounded-xl border border-white/[0.06] bg-black/20 px-3 py-2.5">
|
||
<p className="text-[10px] uppercase text-cyan-300/70">↓ {t("下行", "Down")}</p>
|
||
<p className="mt-1 font-mono text-lg font-bold text-cyan-100">{formatRate(dash.network.total_rx_bps)}</p>
|
||
</div>
|
||
<div className="rounded-xl border border-white/[0.06] bg-black/20 px-3 py-2.5">
|
||
<p className="text-[10px] uppercase text-cyan-300/70">↑ {t("上行", "Up")}</p>
|
||
<p className="mt-1 font-mono text-lg font-bold text-cyan-100">{formatRate(dash.network.total_tx_bps)}</p>
|
||
</div>
|
||
</div>
|
||
<div className="mt-3 space-y-2">
|
||
{(dash.network.interfaces || []).slice(0, 3).map((iface) => (
|
||
<div key={iface.name} className="flex items-center justify-between gap-2 rounded-lg border border-white/[0.05] bg-black/20 px-3 py-2 font-mono text-[10px]">
|
||
<span className="font-semibold text-cyan-200/90">{iface.name}</span>
|
||
<span className="text-zinc-500">
|
||
↓ {formatRate(iface.rx_bps)} · ↑ {formatRate(iface.tx_bps)}
|
||
</span>
|
||
</div>
|
||
))}
|
||
</div>
|
||
</div>
|
||
) : null}
|
||
</div>
|
||
|
||
{/* Critical services mini grid */}
|
||
{criticalServices.length ? (
|
||
<div className="grid gap-2 sm:grid-cols-2 lg:grid-cols-3">
|
||
{criticalServices.map((s) => (
|
||
<div
|
||
key={s.service_id}
|
||
className={`flex items-center justify-between gap-2 rounded-xl border px-3 py-2.5 ${
|
||
theme === "light" ? "border-slate-200 bg-white" : "border-white/[0.06] bg-black/25"
|
||
}`}
|
||
>
|
||
<div className="min-w-0">
|
||
<p className="truncate text-xs font-medium text-zinc-200">{s.label}</p>
|
||
<p className="truncate text-[10px] text-zinc-600">{s.service_id}</p>
|
||
</div>
|
||
<span className={`shrink-0 rounded-full px-2 py-0.5 text-[10px] font-semibold ${statusPill(s.running ? "online" : s.status)}`}>
|
||
{s.running ? t("运行中", "Running") : s.status}
|
||
</span>
|
||
</div>
|
||
))}
|
||
</div>
|
||
) : null}
|
||
|
||
{/* Collapsible detail sections */}
|
||
<div className="space-y-3">
|
||
{deployCheck ? (
|
||
<Section
|
||
id="deploy"
|
||
theme={theme}
|
||
title={t("安装验收", "Deployment health")}
|
||
subtitle={t("API / 边缘反代 / mDNS 可用性", "API, edge proxy, mDNS")}
|
||
defaultOpen={!deployCheck.ready}
|
||
badge={
|
||
<span className={`rounded-full px-2 py-0.5 text-[10px] font-semibold ${deployCheck.ready ? "bg-emerald-500/15 text-emerald-200" : "bg-amber-500/15 text-amber-200"}`}>
|
||
{deployCheck.pass_count}/{deployCheck.total_count}
|
||
</span>
|
||
}
|
||
>
|
||
<div className="grid gap-3 lg:grid-cols-2">
|
||
<p className="text-sm text-zinc-300">
|
||
{deployCheck.ready
|
||
? t("必需检查已通过,控制面可交付。", "Required checks passed.")
|
||
: t("部分检查未通过,请查看失败项。", "Some checks failed.")}
|
||
</p>
|
||
<div className="flex flex-wrap gap-2">
|
||
{Object.entries(deployCheck.urls || {})
|
||
.filter(([, url]) => !!url)
|
||
.slice(0, 5)
|
||
.map(([key, url]) => (
|
||
<a key={key} href={normalizeBrowserReachableHttpUrl(url)} target="_blank" rel="noreferrer" className="rounded-lg border border-white/10 bg-white/5 px-2.5 py-1.5 text-[10px] text-zinc-300">
|
||
{key}
|
||
</a>
|
||
))}
|
||
</div>
|
||
</div>
|
||
{(deployCheck.failing_checks || []).length ? (
|
||
<ul className="mt-3 space-y-1.5">
|
||
{deployCheck.failing_checks!.slice(0, 4).map((item) => (
|
||
<li key={item.id} className="rounded-lg border border-amber-500/20 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-100">
|
||
{item.label}: {item.detail || "—"}
|
||
</li>
|
||
))}
|
||
</ul>
|
||
) : null}
|
||
</Section>
|
||
) : null}
|
||
|
||
{dash?.hardware ? (
|
||
<Section id="hardware" theme={theme} title={t("硬件能力", "Hardware profile")} subtitle={t("GPU / NPU / FFmpeg 策略", "GPU, NPU, FFmpeg")} defaultOpen={false}>
|
||
<div className="grid gap-3 font-mono text-[11px] text-zinc-400 sm:grid-cols-2">
|
||
<p>arch {String(dash.hardware.arch ?? "—")}</p>
|
||
<p>GPU {dash.hardware.gpu && typeof dash.hardware.gpu === "object" && (dash.hardware.gpu as { present?: boolean }).present ? t("有", "yes") : t("无", "no")}</p>
|
||
<p className="sm:col-span-2">
|
||
hwaccels{" "}
|
||
{((dash.hardware.ffmpeg_hwaccels as string[] | undefined) || []).join(", ") || "—"}
|
||
</p>
|
||
</div>
|
||
</Section>
|
||
) : null}
|
||
|
||
{dash?.stack?.neko_login ? (
|
||
<Section id="neko" theme={theme} title={`Neko ${t("登录", "sign-in")}`} subtitle={nekoPortsLabel || t("多实例", "multi-instance")} defaultOpen={false}>
|
||
<div className="flex flex-wrap gap-2">
|
||
{nekoLinks.map((link) => (
|
||
<a key={link.key} href={link.url} target="_blank" rel="noreferrer" className="rounded-lg border border-fuchsia-400/20 bg-black/25 px-3 py-2 text-[11px] text-fuchsia-100">
|
||
{link.label} · {link.accessLabel}
|
||
</a>
|
||
))}
|
||
</div>
|
||
<p className="mt-3 text-[11px] text-amber-200/85">
|
||
{t("昵称随意,密码须与环境变量一致(默认 12345678)。", "Display name is free; password must match NEKO_* (default 12345678).")}
|
||
</p>
|
||
</Section>
|
||
) : null}
|
||
|
||
{showStreamProbes && dash?.probes ? (
|
||
<Section id="probes" theme={theme} title={t("推流探针", "Stream probes")} subtitle="SRS · Neko" defaultOpen={false}>
|
||
<div className="grid gap-2 sm:grid-cols-2">
|
||
{dash.probes.srs ? (
|
||
<div className="rounded-xl border border-white/[0.06] bg-black/25 p-3 text-[11px]">
|
||
<p className="font-semibold text-white">SRS</p>
|
||
<p className="mt-1 text-zinc-500">
|
||
API {dash.probes.srs.api_ok ? "OK" : "—"} · :{dash.probes.srs.port} · RTT {dash.probes.srs.http?.latency_ms ?? dash.probes.srs.tcp?.latency_ms ?? "—"} ms
|
||
</p>
|
||
{dash.probes.srs.http?.error ? (
|
||
<p className="mt-1 text-amber-300/80">{dash.probes.srs.http.error}</p>
|
||
) : null}
|
||
</div>
|
||
) : null}
|
||
{dash.probes.neko ? (
|
||
<div className="rounded-xl border border-white/[0.06] bg-black/25 p-3 text-[11px]">
|
||
<p className="font-semibold text-white">Neko</p>
|
||
<p className="mt-1 text-zinc-500">
|
||
{dash.probes.neko.running_count}/{dash.probes.neko.required_count} {t("在线", "online")} · HTTP {dash.probes.neko.http?.http_code ?? "—"}
|
||
</p>
|
||
{dash.probes.neko.http?.error ? (
|
||
<p className="mt-1 text-amber-300/80">{dash.probes.neko.http.error}</p>
|
||
) : null}
|
||
</div>
|
||
) : null}
|
||
</div>
|
||
</Section>
|
||
) : null}
|
||
|
||
{(dash?.live_events?.pm2_tail?.length || digest.length) ? (
|
||
<Section id="feeds" theme={theme} title={t("事件流", "Event feed")} defaultOpen={false}>
|
||
<pre className="max-h-40 overflow-auto whitespace-pre-wrap rounded-lg border border-white/[0.05] bg-black/40 p-3 font-mono text-[10px] text-zinc-400">
|
||
{(dash?.live_events?.pm2_tail || []).slice(-12).join("\n") || t("暂无日志", "No logs")}
|
||
</pre>
|
||
</Section>
|
||
) : null}
|
||
</div>
|
||
</div>
|
||
);
|
||
}
|