douyinWEB/frontend/src/components/YtRelayOpsHero.tsx
eric d409e416da Ship physical dual-edge stack, Studio CDP live metrics, and ops tooling.
Capture Neko/WG/network hubs, Studio viewer charts, physical deploy docs, and one-shot scripts so VPS vs physical can be toggled later without losing WIP.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-04 22:42:40 -05:00

324 lines
12 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use client";
import type { ReactNode } from "react";
import {
Clock,
Cpu,
Loader2,
MonitorPlay,
Radio,
RefreshCw,
Sparkles,
Zap,
} from "lucide-react";
import { EnableSwitch } from "@/components/EnableSwitch";
export type RelayOpsHeroProps = {
relayEnabled: boolean;
timeSlotModeOn: boolean;
exclusiveLiveOn: boolean;
relayBusy: boolean;
busy: boolean;
douyinLiveCount: number | string;
pushingCount: number;
workerRunning: boolean;
nowLabel: string;
keyedChannelCount: number;
exclusiveWinnerName?: string;
nekoPausedCount?: number;
nekoEnabledCount: number;
qualityPresetId: string;
qualityPresets: Array<{
id: string;
label: string;
description?: string;
recommended_for_vps?: boolean;
active?: boolean;
}>;
qualityHint?: string;
lastError?: string;
onToggleRelay: (on: boolean) => void;
onToggleTimeSlot: (on: boolean) => void;
onToggleExclusive: (on: boolean) => void;
onQualityChange: (id: string) => void;
onRefreshAvatars: () => void;
onRefresh: () => void;
createForm: ReactNode;
};
function MetricPill({
label,
value,
tone = "slate",
pulse,
}: {
label: string;
value: ReactNode;
tone?: "slate" | "teal" | "rose" | "amber";
pulse?: boolean;
}) {
const tones = {
slate: "border-white/10 bg-black/35 text-slate-100",
teal: "border-teal-400/25 bg-teal-500/10 text-teal-50",
rose: "border-rose-400/30 bg-rose-500/10 text-rose-50",
amber: "border-amber-400/30 bg-amber-500/10 text-amber-50",
};
return (
<div
className={`relative overflow-hidden rounded-2xl border px-3.5 py-3 transition duration-300 ${tones[tone]}`}
>
{pulse ? (
<span className="absolute right-2.5 top-2.5 h-1.5 w-1.5 animate-pulse rounded-full bg-rose-400 shadow-[0_0_8px_rgba(251,113,133,0.8)]" />
) : null}
<div className="text-[10px] font-medium uppercase tracking-[0.16em] text-slate-500">{label}</div>
<div className="mt-1 text-lg font-semibold tabular-nums tracking-tight">{value}</div>
</div>
);
}
function PolicyCard({
title,
subtitle,
icon,
accent,
children,
active,
}: {
title: string;
subtitle: string;
icon: ReactNode;
accent: string;
children: ReactNode;
active?: boolean;
}) {
return (
<div
className={`group relative overflow-hidden rounded-2xl border p-3.5 transition duration-300 ${
active
? `${accent} shadow-[0_12px_40px_-24px_rgba(45,212,191,0.55)]`
: "border-white/10 bg-black/25 hover:border-white/15 hover:bg-black/35"
}`}
>
<div className="pointer-events-none absolute -right-6 -top-8 h-24 w-24 rounded-full bg-white/[0.03] blur-2xl transition group-hover:bg-white/[0.06]" />
<div className="relative flex items-start justify-between gap-3">
<div className="min-w-0">
<div className="flex items-center gap-2">
<span className="flex h-8 w-8 items-center justify-center rounded-xl bg-white/5 text-slate-200 ring-1 ring-white/10">
{icon}
</span>
<div>
<div className="text-sm font-medium text-slate-100">{title}</div>
<p className="mt-0.5 text-[11px] leading-relaxed text-slate-500">{subtitle}</p>
</div>
</div>
</div>
<div className="shrink-0 pt-0.5">{children}</div>
</div>
</div>
);
}
/** Hero ops strip for YouTube 分配 — schedule vs resource policy made obvious. */
export function YtRelayOpsHero({
relayEnabled,
timeSlotModeOn,
exclusiveLiveOn,
relayBusy,
busy,
douyinLiveCount,
pushingCount,
workerRunning,
nowLabel,
keyedChannelCount,
exclusiveWinnerName,
nekoPausedCount = 0,
nekoEnabledCount,
qualityPresetId,
qualityPresets,
qualityHint,
lastError,
onToggleRelay,
onToggleTimeSlot,
onToggleExclusive,
onQualityChange,
onRefreshAvatars,
onRefresh,
createForm,
}: RelayOpsHeroProps) {
const pushing = Number(pushingCount || 0) > 0;
return (
<section className="animate-fade-up overflow-hidden rounded-[1.35rem] border border-white/10 bg-gradient-to-br from-[#121a28]/95 via-[#0c1420]/90 to-[#101828]/92 shadow-[0_24px_80px_-48px_rgba(0,0,0,0.9)]">
<div className="relative border-b border-white/[0.06] px-4 py-4 sm:px-5">
<div className="pointer-events-none absolute inset-0 bg-[radial-gradient(680px_180px_at_12%_-20%,rgba(255,45,85,0.16),transparent_55%),radial-gradient(520px_160px_at_88%_0%,rgba(45,212,191,0.12),transparent_50%)]" />
<div className="relative flex flex-wrap items-start justify-between gap-3">
<div className="min-w-0 max-w-2xl">
<div className="inline-flex items-center gap-1.5 rounded-full border border-rose-400/20 bg-rose-500/10 px-2.5 py-0.5 text-[10px] font-medium uppercase tracking-[0.2em] text-rose-200/90">
<Sparkles className="h-3 w-3" />
Live Relay
</div>
<h3 className="mt-2 font-display text-xl font-semibold tracking-tight text-slate-50 sm:text-2xl">
转播分配
</h3>
<p className="mt-1.5 text-sm leading-relaxed text-slate-400">
{timeSlotModeOn
? `排班中:${keyedChannelCount || "N"} 个有 KEY 频道平分 24h(北京时间),源取当前在播抖音。`
: "精选列表推流:频道 + KEY → 抖音池 → 精选地址。打开自动推流后由 Worker 调度。"}
{exclusiveLiveOn
? " 资源策略为「独占」:开播时只保留一路 FFmpeg,并暂停其他 Neko(适合 VPS)。"
: " 资源策略为「多开」:可同时保留多个 Neko 预热(适合物理机)。"}
</p>
</div>
<div className="flex flex-wrap items-center gap-2">
<button
type="button"
disabled={busy}
onClick={onRefreshAvatars}
className="inline-flex items-center gap-1.5 rounded-xl border border-white/10 bg-white/[0.04] px-3 py-2 text-sm text-slate-200 transition hover:bg-white/[0.08] disabled:opacity-40"
title="从 YouTube 拉取并固化到 S3"
>
{busy ? <Loader2 className="h-3.5 w-3.5 animate-spin" /> : <RefreshCw className="h-3.5 w-3.5" />}
刷新头像
</button>
<button
type="button"
onClick={onRefresh}
className="inline-flex items-center gap-1.5 rounded-xl border border-white/10 bg-white/[0.04] px-3 py-2 text-sm text-slate-200 transition hover:bg-white/[0.08]"
>
{busy ? <Loader2 className="h-3.5 w-3.5 animate-spin" /> : <RefreshCw className="h-3.5 w-3.5" />}
刷新
</button>
</div>
</div>
</div>
<div className="space-y-4 px-4 py-4 sm:px-5">
<div className="grid gap-2 sm:grid-cols-2 lg:grid-cols-4">
<MetricPill label="抖音在播" value={douyinLiveCount} tone="teal" />
<MetricPill label="推流中" value={pushingCount} tone={pushing ? "rose" : "slate"} pulse={pushing} />
<MetricPill label="Worker" value={workerRunning ? "运行" : "停"} tone={workerRunning ? "teal" : "slate"} />
<MetricPill label="北京时段" value={nowLabel || "—"} />
</div>
<div className="grid gap-3 lg:grid-cols-3">
<PolicyCard
title="自动推流"
subtitle="总开关。关闭后只保留手动「开始」的会话。"
icon={<Zap className="h-4 w-4 text-rose-300" />}
accent="border-rose-400/30 bg-rose-500/[0.08]"
active={relayEnabled}
>
<EnableSwitch
checked={relayEnabled}
busy={relayBusy}
accent="pink"
size="md"
label={relayEnabled ? "开" : "关"}
onChange={onToggleRelay}
/>
</PolicyCard>
<PolicyCard
title="时间段排班"
subtitle="只决定谁在何时推流;不再强制独占 Neko。"
icon={<Clock className="h-4 w-4 text-teal-300" />}
accent="border-teal-400/30 bg-teal-500/[0.08]"
active={timeSlotModeOn}
>
<EnableSwitch
checked={timeSlotModeOn}
busy={relayBusy}
accent="teal"
size="md"
label={timeSlotModeOn ? "开" : "关"}
onChange={onToggleTimeSlot}
/>
</PolicyCard>
<PolicyCard
title="单路独占"
subtitle="VPS 省资源建议开;物理机多 Neko 预热请关。"
icon={<Cpu className="h-4 w-4 text-amber-300" />}
accent="border-amber-400/30 bg-amber-500/[0.08]"
active={exclusiveLiveOn}
>
<EnableSwitch
checked={exclusiveLiveOn}
busy={relayBusy}
accent="amber"
size="md"
label={exclusiveLiveOn ? "开" : "关"}
onChange={onToggleExclusive}
/>
</PolicyCard>
</div>
{(timeSlotModeOn || (exclusiveLiveOn && exclusiveWinnerName) || nekoEnabledCount > 0) && (
<div className="flex flex-wrap gap-2">
{timeSlotModeOn ? (
<span className="inline-flex items-center gap-1.5 rounded-full border border-teal-400/25 bg-teal-500/10 px-3 py-1 text-[11px] text-teal-100">
<Radio className="h-3 w-3" />
排班 · {keyedChannelCount} 频道
{keyedChannelCount > 0 ? ` · ≈${(24 / keyedChannelCount).toFixed(1)}h/档` : " · 请先配置 KEY"}
<span className="text-teal-200/60">· 源=在播抖音</span>
</span>
) : null}
{exclusiveLiveOn && exclusiveWinnerName ? (
<span className="inline-flex items-center gap-1.5 rounded-full border border-amber-400/25 bg-amber-500/10 px-3 py-1 text-[11px] text-amber-100">
<MonitorPlay className="h-3 w-3" />
独占中 · {exclusiveWinnerName}
{nekoPausedCount > 0 ? (
<span className="text-amber-200/70">· 已暂停 {nekoPausedCount} 个 Neko</span>
) : null}
</span>
) : null}
{!exclusiveLiveOn ? (
<span className="inline-flex items-center gap-1.5 rounded-full border border-sky-400/20 bg-sky-500/10 px-3 py-1 text-[11px] text-sky-100">
<MonitorPlay className="h-3 w-3" />
多开模式 · Neko 启用标记 {nekoEnabledCount}
</span>
) : null}
</div>
)}
<div className="rounded-2xl border border-white/10 bg-black/30 px-3.5 py-3">
<div className="flex flex-wrap items-center justify-between gap-3">
<div className="min-w-0">
<div className="text-[10px] font-medium uppercase tracking-[0.16em] text-slate-500">转推画质</div>
<p className="mt-0.5 text-xs text-slate-400">
VPS 建议 Ultra;物理机可开 720p。切换后推流会自动重启。
</p>
</div>
<select
value={qualityPresetId || "720p"}
disabled={relayBusy}
onChange={(e) => onQualityChange(e.target.value)}
className="min-w-[13rem] rounded-xl border border-white/10 bg-slate-950/80 px-3 py-2 text-sm text-slate-100 outline-none ring-rose-400/0 transition focus:ring-2 focus:ring-rose-400/30 disabled:opacity-50"
>
{qualityPresets.map((p) => (
<option key={p.id} value={p.id}>
{p.label}
{p.recommended_for_vps ? " · 4核VPS" : ""}
</option>
))}
</select>
</div>
{qualityHint ? <p className="mt-2 text-[11px] text-slate-500">{qualityHint}</p> : null}
</div>
{lastError ? (
<div className="rounded-xl border border-rose-400/25 bg-rose-500/10 px-3 py-2 text-[11px] text-rose-100">
{lastError}
</div>
) : null}
<div className="rounded-2xl border border-dashed border-white/10 bg-black/20 p-3.5">
<div className="mb-2 text-[10px] font-medium uppercase tracking-[0.16em] text-slate-500">新建分组</div>
{createForm}
</div>
</div>
</section>
);
}