"use client"; import { useCallback, useEffect, useState } from "react"; import Link from "next/link"; import { Loader2, RefreshCw, ShieldCheck } from "lucide-react"; import { Shell } from "@/components/Shell"; import { YtChannelProfileSnippet, type YtProfileSnippet } from "@/components/YtChannelProfileSnippet"; import { useToast } from "@/components/Toast"; import { fetchJson } from "@/lib/api"; type ChannelRow = { id: string; name?: string; youtube_channel_id?: string; handle?: string; thumb_url?: string; oauth_ok?: number; oauth_error?: string; oauth_profile_id?: string; brand_hint?: string; authorized?: boolean; enabled?: boolean; ypp_ok?: number; yt_profile?: YtProfileSnippet | null; }; export default function YoutubeOAuthHealthPage() { const toast = useToast(); const [rows, setRows] = useState([]); const [loading, setLoading] = useState(true); const [probing, setProbing] = useState(false); const load = useCallback(async () => { setLoading(true); try { const data = await fetchJson<{ channels?: ChannelRow[] }>("/api/youtube/oauth-health"); setRows(data.channels || []); } catch (e) { toast.push((e as Error).message, "error"); } finally { setLoading(false); } }, [toast]); useEffect(() => { void load(); }, [load]); async function probeAll() { setProbing(true); try { await fetchJson("/api/youtube/oauth-health/probe", { method: "POST" }); toast.push("OAuth 探测完成", "ok"); await load(); } catch (e) { toast.push((e as Error).message, "error"); } finally { setProbing(false); } } const okCount = rows.filter((r) => r.oauth_ok === 1).length; return (

YouTube 频道健康

OAuth / YPP / Google 品牌名对照 · 重授权请选品牌名而非 YouTube 标题

批量重授权
已授权 {okCount} / {rows.length} · 失败 {rows.filter((r) => r.oauth_ok === 0).length} · 未探测{" "} {rows.filter((r) => r.oauth_ok === -1).length}
{loading ? (
) : (
{rows.map((ch) => (
账号 {ch.oauth_profile_id || "—"} ·{" "} {ch.oauth_ok === 1 ? "OAuth OK" : ch.oauth_ok === 0 ? "OAuth 失败" : "未探测"}
{ch.brand_hint ? (
Google 品牌:{ch.brand_hint}
) : null} {ch.ypp_ok === 1 ?
YPP · 获利
: null} {ch.oauth_error ?
{ch.oauth_error}
: null}
))}
)}
); }