从 GitHub 同步 Win x64 安装包到 S3,并提供配置下载与同步 API。 Co-authored-by: Cursor <cursoragent@cursor.com>
282 lines
11 KiB
TypeScript
282 lines
11 KiB
TypeScript
"use client";
|
||
|
||
import { useEffect, useMemo, useState } from "react";
|
||
import Link from "next/link";
|
||
import { usePathname, useRouter } from "next/navigation";
|
||
import { Menu, X as CloseIcon } from "lucide-react";
|
||
|
||
import { BrandMark, LivePulse } from "@/components/ui";
|
||
import { GlobalEventAlerts } from "@/components/GlobalEventAlerts";
|
||
import { PwaInstallBanner } from "@/components/PwaInstallBanner";
|
||
import { fetchJson } from "@/lib/api";
|
||
import {
|
||
YouTubeLiveContextProvider,
|
||
useYouTubeLiveCount,
|
||
useYouTubeLiveMap,
|
||
useYouTubeLiveProviderValue,
|
||
} from "@/lib/youtubeLive";
|
||
|
||
const NAV = [
|
||
{ href: "/", label: "概览", emoji: "📡" },
|
||
{ href: "/slots", label: "时段", emoji: "🕐" },
|
||
{ href: "/sessions", label: "场次", emoji: "🎬" },
|
||
{ href: "/anchors", label: "主播", emoji: "👤" },
|
||
{ href: "/covers", label: "截图", emoji: "🖼️" },
|
||
{ href: "/events", label: "事件", emoji: "⚡" },
|
||
{ href: "/rooms", label: "直播间", emoji: "🏠" },
|
||
{ href: "/groups", label: "分组", emoji: "📺" },
|
||
{ href: "/youtube", label: "YouTube", emoji: "▶️" },
|
||
{ href: "/shorts", label: "Shorts", emoji: "📱" },
|
||
{ href: "/tiktok", label: "TikTok", emoji: "🎵" },
|
||
{ href: "/x", label: "X", emoji: "𝕏" },
|
||
{ href: "/clash", label: "Clash", emoji: "🧿" },
|
||
{ href: "/downloads", label: "下载", emoji: "⬇️" },
|
||
{ href: "/blacklist", label: "黑名单", emoji: "🚫" },
|
||
{ href: "/settings", label: "设置", emoji: "⚙️" },
|
||
];
|
||
|
||
/** Bottom bar: 概览 / TikTok / X / Shorts + 更多(YouTube 仅在「更多」) */
|
||
const MOBILE_PRIMARY = ["/", "/tiktok", "/x", "/shorts"];
|
||
|
||
function navActive(pathname: string, href: string) {
|
||
return pathname === href || (href !== "/" && pathname.startsWith(href));
|
||
}
|
||
|
||
export function Shell({ children }: { children: React.ReactNode }) {
|
||
const liveCtx = useYouTubeLiveProviderValue();
|
||
return (
|
||
<YouTubeLiveContextProvider value={liveCtx}>
|
||
<ShellFrame>{children}</ShellFrame>
|
||
</YouTubeLiveContextProvider>
|
||
);
|
||
}
|
||
|
||
function ShellFrame({ children }: { children: React.ReactNode }) {
|
||
const pathname = usePathname();
|
||
const router = useRouter();
|
||
const ytLiveCount = useYouTubeLiveCount();
|
||
const { map: ytLiveMap } = useYouTubeLiveMap();
|
||
const [username, setUsername] = useState("");
|
||
const [moreOpen, setMoreOpen] = useState(false);
|
||
|
||
useEffect(() => {
|
||
void fetchJson("/api/auth/status")
|
||
.then((d) => setUsername(String(d.username || "")))
|
||
.catch(() => setUsername(""));
|
||
}, [pathname]);
|
||
|
||
useEffect(() => {
|
||
setMoreOpen(false);
|
||
}, [pathname]);
|
||
|
||
useEffect(() => {
|
||
if (!moreOpen) return;
|
||
const prev = document.body.style.overflow;
|
||
document.body.style.overflow = "hidden";
|
||
return () => {
|
||
document.body.style.overflow = prev;
|
||
};
|
||
}, [moreOpen]);
|
||
|
||
const primaryNav = useMemo(
|
||
() => NAV.filter((n) => MOBILE_PRIMARY.includes(n.href)),
|
||
[],
|
||
);
|
||
const moreActive = useMemo(
|
||
() => NAV.some((n) => !MOBILE_PRIMARY.includes(n.href) && navActive(pathname, n.href)),
|
||
[pathname],
|
||
);
|
||
|
||
async function logout() {
|
||
try {
|
||
await fetchJson("/api/auth/logout", { method: "POST" });
|
||
} catch {
|
||
/* ignore */
|
||
}
|
||
router.replace("/login");
|
||
router.refresh();
|
||
}
|
||
|
||
return (
|
||
<div className="relative min-h-[100dvh] overflow-x-clip">
|
||
<GlobalEventAlerts />
|
||
<div className="ambient-orb a" />
|
||
<div className="ambient-orb b" />
|
||
<div className="ambient-orb c" />
|
||
|
||
<div className="relative z-10 mx-auto flex min-h-[100dvh] max-w-7xl flex-col px-3 pb-[calc(4.5rem+env(safe-area-inset-bottom))] pt-[max(0.75rem,env(safe-area-inset-top))] sm:px-6 md:pb-10 md:pt-5">
|
||
<header className="mb-4 animate-fade-up border-b border-white/10 pb-4 sm:mb-6 sm:pb-5">
|
||
<div className="flex items-start justify-between gap-3">
|
||
<div className="flex min-w-0 items-start gap-2.5 sm:gap-3">
|
||
<BrandMark className="mt-0.5 h-9 w-9 shrink-0 sm:mt-1 sm:h-12 sm:w-12" />
|
||
<div className="min-w-0">
|
||
<p className="font-display text-[10px] uppercase tracking-[0.24em] text-teal-300/90 sm:text-xs sm:tracking-[0.28em]">
|
||
Live Radar
|
||
</p>
|
||
<h1 className="font-display text-xl font-bold tracking-tight text-white sm:text-3xl md:text-4xl">
|
||
直播监控中心
|
||
</h1>
|
||
<p className="mt-0.5 hidden max-w-2xl text-sm text-slate-400 sm:mt-1 sm:block">
|
||
抖音 + YouTube · 开播捕捉 · 停播结场 · 时长统计 · 截图存证
|
||
</p>
|
||
{ytLiveCount > 0 ? (
|
||
<div className="mt-1.5 flex flex-wrap items-center gap-2 sm:mt-2">
|
||
<Link href="/groups">
|
||
<LivePulse label={`YouTube ${ytLiveCount} 路在播`} />
|
||
</Link>
|
||
{ytLiveMap?.checked_at ? (
|
||
<span className="hidden text-[10px] text-slate-500 sm:inline">
|
||
轮询 {Math.max(0, Math.round(Date.now() / 1000 - Number(ytLiveMap.checked_at)))}s 前
|
||
</span>
|
||
) : null}
|
||
</div>
|
||
) : (
|
||
<div className="mt-1.5 hidden flex-wrap items-center gap-2 text-[11px] text-slate-500 sm:mt-2 sm:flex">
|
||
{ytLiveMap?.svc_error ? (
|
||
<span className="text-amber-300" title={ytLiveMap.svc_error}>
|
||
⚠ YouTube 探测异常(轮询兜底中)
|
||
</span>
|
||
) : (
|
||
<span>YouTube 直播轮询中</span>
|
||
)}
|
||
</div>
|
||
)}
|
||
</div>
|
||
</div>
|
||
<div className="flex shrink-0 flex-wrap items-center justify-end gap-1.5 sm:gap-2">
|
||
{username ? (
|
||
<span className="hidden rounded-xl border border-white/10 bg-white/5 px-3 py-1.5 text-xs text-slate-300 sm:inline">
|
||
{username}
|
||
</span>
|
||
) : null}
|
||
<button
|
||
type="button"
|
||
onClick={() => setMoreOpen(true)}
|
||
className="inline-flex h-9 w-9 items-center justify-center rounded-xl border border-white/10 bg-white/5 text-slate-300 hover:bg-white/10 md:hidden"
|
||
aria-label="打开菜单"
|
||
>
|
||
<Menu className="h-4 w-4" />
|
||
</button>
|
||
<button
|
||
type="button"
|
||
onClick={() => void logout()}
|
||
className="rounded-xl border border-white/10 bg-white/5 px-2.5 py-1.5 text-[11px] text-slate-400 hover:bg-white/10 hover:text-white sm:px-3 sm:text-xs"
|
||
>
|
||
退出
|
||
</button>
|
||
</div>
|
||
</div>
|
||
|
||
<nav className="mt-4 hidden max-w-full flex-wrap gap-2 md:flex">
|
||
{NAV.map((item) => {
|
||
const active = navActive(pathname, item.href);
|
||
return (
|
||
<Link
|
||
key={item.href}
|
||
href={item.href}
|
||
className={`nav-chip rounded-xl px-3 py-1.5 text-sm ${
|
||
active
|
||
? "active bg-white/15 text-white ring-1 ring-teal-400/30"
|
||
: "bg-white/5 text-slate-400 hover:bg-white/10 hover:text-white"
|
||
}`}
|
||
>
|
||
<span className="mr-1.5">{item.emoji}</span>
|
||
{item.label}
|
||
</Link>
|
||
);
|
||
})}
|
||
</nav>
|
||
</header>
|
||
|
||
<main className="page-enter flex-1">{children}</main>
|
||
<footer className="hidden border-t border-white/5 py-4 text-center text-[11px] text-slate-600 md:block">
|
||
Douyin + YouTube Monitor · realtime radar
|
||
</footer>
|
||
</div>
|
||
|
||
<PwaInstallBanner />
|
||
|
||
{/* Mobile bottom tab bar */}
|
||
<nav className="fixed inset-x-0 bottom-0 z-40 border-t border-white/10 bg-[#071018]/95 px-1 pt-1 backdrop-blur-md md:hidden pb-[env(safe-area-inset-bottom)]">
|
||
<div className="mx-auto flex max-w-lg items-stretch justify-between gap-0.5">
|
||
{primaryNav.map((item) => {
|
||
const active = navActive(pathname, item.href);
|
||
return (
|
||
<Link
|
||
key={item.href}
|
||
href={item.href}
|
||
className={`flex min-h-[3rem] min-w-0 flex-1 flex-col items-center justify-center gap-0.5 rounded-lg px-1 py-1.5 text-[10px] ${
|
||
active ? "text-teal-200" : "text-slate-500"
|
||
}`}
|
||
>
|
||
<span className="text-base leading-none">{item.emoji}</span>
|
||
<span className="truncate">{item.label}</span>
|
||
</Link>
|
||
);
|
||
})}
|
||
<button
|
||
type="button"
|
||
onClick={() => setMoreOpen(true)}
|
||
className={`flex min-h-[3rem] min-w-0 flex-1 flex-col items-center justify-center gap-0.5 rounded-lg px-1 py-1.5 text-[10px] ${
|
||
moreActive || moreOpen ? "text-teal-200" : "text-slate-500"
|
||
}`}
|
||
>
|
||
<span className="text-base leading-none">⋯</span>
|
||
<span className="truncate">更多</span>
|
||
</button>
|
||
</div>
|
||
</nav>
|
||
|
||
{/* Mobile more sheet */}
|
||
{moreOpen ? (
|
||
<div className="fixed inset-0 z-50 md:hidden" role="dialog" aria-modal="true">
|
||
<button
|
||
type="button"
|
||
className="absolute inset-0 bg-black/60"
|
||
aria-label="关闭菜单"
|
||
onClick={() => setMoreOpen(false)}
|
||
/>
|
||
<div className="absolute inset-x-0 bottom-0 max-h-[85dvh] overflow-y-auto rounded-t-2xl border border-white/10 bg-[#0b1520] px-4 pb-[calc(1rem+env(safe-area-inset-bottom))] pt-3 shadow-2xl">
|
||
<div className="mb-3 flex items-center justify-between">
|
||
<div>
|
||
<p className="text-sm font-medium text-slate-100">全部功能</p>
|
||
<p className="text-[11px] text-slate-500">点选页面 · 支持手机操作</p>
|
||
</div>
|
||
<button
|
||
type="button"
|
||
onClick={() => setMoreOpen(false)}
|
||
className="inline-flex h-9 w-9 items-center justify-center rounded-xl border border-white/10 bg-white/5 text-slate-300"
|
||
aria-label="关闭"
|
||
>
|
||
<CloseIcon className="h-4 w-4" />
|
||
</button>
|
||
</div>
|
||
{username ? (
|
||
<p className="mb-3 text-xs text-slate-400">当前账号:{username}</p>
|
||
) : null}
|
||
<div className="grid grid-cols-3 gap-2 sm:grid-cols-4">
|
||
{NAV.map((item) => {
|
||
const active = navActive(pathname, item.href);
|
||
return (
|
||
<Link
|
||
key={item.href}
|
||
href={item.href}
|
||
className={`flex min-h-[4.5rem] flex-col items-center justify-center gap-1 rounded-xl border px-2 py-3 text-center text-xs ${
|
||
active
|
||
? "border-teal-400/40 bg-teal-500/10 text-teal-100"
|
||
: "border-white/10 bg-white/[0.03] text-slate-300"
|
||
}`}
|
||
>
|
||
<span className="text-xl leading-none">{item.emoji}</span>
|
||
<span>{item.label}</span>
|
||
</Link>
|
||
);
|
||
})}
|
||
</div>
|
||
</div>
|
||
</div>
|
||
) : null}
|
||
</div>
|
||
);
|
||
}
|