"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 ( {children} ); } 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 (

Live Radar

直播监控中心

抖音 + YouTube · 开播捕捉 · 停播结场 · 时长统计 · 截图存证

{ytLiveCount > 0 ? (
{ytLiveMap?.checked_at ? ( 轮询 {Math.max(0, Math.round(Date.now() / 1000 - Number(ytLiveMap.checked_at)))}s 前 ) : null}
) : (
{ytLiveMap?.svc_error ? ( ⚠ YouTube 探测异常(轮询兜底中) ) : ( YouTube 直播轮询中 )}
)}
{username ? ( {username} ) : null}
{children}
Douyin + YouTube Monitor · realtime radar
{/* Mobile bottom tab bar */} {/* Mobile more sheet */} {moreOpen ? (
{username ? (

当前账号:{username}

) : null}
{NAV.map((item) => { const active = navActive(pathname, item.href); return ( {item.emoji} {item.label} ); })}
) : null}
); }