New pages and APIs for cross-platform jobs, YouTube OAuth health, mobile ops, settings audit, optional DB backup, quota/disk alerts, and clip archive replay. All new behavior defaults off to avoid changing production pipelines. Co-authored-by: Cursor <cursoragent@cursor.com>
151 lines
5.3 KiB
TypeScript
151 lines
5.3 KiB
TypeScript
"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<ChannelRow[]>([]);
|
||
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 (
|
||
<Shell>
|
||
<div className="mx-auto max-w-6xl space-y-4 p-4 md:p-6">
|
||
<div className="flex flex-wrap items-center justify-between gap-3">
|
||
<div>
|
||
<h1 className="text-lg font-semibold text-slate-100">YouTube 频道健康</h1>
|
||
<p className="mt-1 text-xs text-slate-500">
|
||
OAuth / YPP / Google 品牌名对照 · 重授权请选品牌名而非 YouTube 标题
|
||
</p>
|
||
</div>
|
||
<div className="flex gap-2">
|
||
<button
|
||
type="button"
|
||
onClick={() => void load()}
|
||
className="inline-flex items-center gap-1 rounded-lg border border-white/10 px-3 py-1.5 text-xs"
|
||
>
|
||
<RefreshCw className="h-3.5 w-3.5" /> 刷新
|
||
</button>
|
||
<button
|
||
type="button"
|
||
disabled={probing}
|
||
onClick={() => void probeAll()}
|
||
className="inline-flex items-center gap-1 rounded-lg border border-teal-500/30 bg-teal-500/10 px-3 py-1.5 text-xs text-teal-100"
|
||
>
|
||
{probing ? <Loader2 className="h-3.5 w-3.5 animate-spin" /> : <ShieldCheck className="h-3.5 w-3.5" />}
|
||
探测 OAuth
|
||
</button>
|
||
<Link href="/shorts/reauth-batch" className="rounded-lg border border-white/10 px-3 py-1.5 text-xs">
|
||
批量重授权
|
||
</Link>
|
||
</div>
|
||
</div>
|
||
|
||
<div className="rounded-xl border border-white/10 bg-black/25 px-4 py-3 text-sm text-slate-300">
|
||
已授权 <span className="text-teal-300">{okCount}</span> / {rows.length} ·
|
||
失败 {rows.filter((r) => r.oauth_ok === 0).length} · 未探测{" "}
|
||
{rows.filter((r) => r.oauth_ok === -1).length}
|
||
</div>
|
||
|
||
{loading ? (
|
||
<div className="flex justify-center py-16 text-slate-500">
|
||
<Loader2 className="h-6 w-6 animate-spin" />
|
||
</div>
|
||
) : (
|
||
<div className="grid gap-3 md:grid-cols-2">
|
||
{rows.map((ch) => (
|
||
<div
|
||
key={ch.id}
|
||
className={`rounded-xl border p-4 ${
|
||
ch.oauth_ok === 1
|
||
? "border-teal-500/25 bg-teal-500/5"
|
||
: ch.oauth_ok === 0
|
||
? "border-rose-500/30 bg-rose-500/5"
|
||
: "border-white/10 bg-black/20"
|
||
}`}
|
||
>
|
||
<YtChannelProfileSnippet
|
||
profile={
|
||
ch.yt_profile || {
|
||
title: ch.name,
|
||
custom_url: ch.handle,
|
||
thumbnails: ch.thumb_url ? { default: { url: ch.thumb_url } } : undefined,
|
||
}
|
||
}
|
||
fallbackName={ch.name}
|
||
fallbackChannelId={ch.youtube_channel_id}
|
||
/>
|
||
<div className="mt-2 space-y-1 text-[11px] text-slate-400">
|
||
<div>
|
||
账号 {ch.oauth_profile_id || "—"} ·{" "}
|
||
{ch.oauth_ok === 1 ? "OAuth OK" : ch.oauth_ok === 0 ? "OAuth 失败" : "未探测"}
|
||
</div>
|
||
{ch.brand_hint ? (
|
||
<div className="text-amber-200/90">Google 品牌:{ch.brand_hint}</div>
|
||
) : null}
|
||
{ch.ypp_ok === 1 ? <div className="text-teal-300">YPP · 获利</div> : null}
|
||
{ch.oauth_error ? <div className="text-rose-300">{ch.oauth_error}</div> : null}
|
||
</div>
|
||
</div>
|
||
))}
|
||
</div>
|
||
)}
|
||
</div>
|
||
</Shell>
|
||
);
|
||
}
|