758 lines
30 KiB
TypeScript
758 lines
30 KiB
TypeScript
"use client";
|
||
|
||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||
import Link from "next/link";
|
||
import {
|
||
CheckCircle2,
|
||
Circle,
|
||
Clock3,
|
||
ExternalLink,
|
||
KeyRound,
|
||
Loader2,
|
||
Music2,
|
||
Plus,
|
||
RefreshCw,
|
||
Trash2,
|
||
Upload,
|
||
Zap,
|
||
} from "lucide-react";
|
||
|
||
import { Shell } from "@/components/Shell";
|
||
import { useConfirm } from "@/components/ConfirmDialog";
|
||
import { useToast } from "@/components/Toast";
|
||
import { PageLoader } from "@/components/ui";
|
||
import { fetchJson, fmtTs, todayBeijingISO } from "@/lib/api";
|
||
|
||
type SetupStep = { id: string; title: string; url?: string; done: boolean };
|
||
|
||
type Channel = {
|
||
id: string;
|
||
name: string;
|
||
tiktok_username?: string;
|
||
enabled?: boolean;
|
||
authorized?: boolean;
|
||
oauth_ok?: number;
|
||
oauth_error?: string;
|
||
privacy_level?: string;
|
||
title_template?: string;
|
||
description_template?: string;
|
||
note?: string;
|
||
};
|
||
|
||
type BoardChannel = {
|
||
id: string;
|
||
name?: string;
|
||
tiktok_username?: string;
|
||
enabled?: boolean;
|
||
authorized?: boolean;
|
||
used: number;
|
||
scheduled: number;
|
||
uploaded: number;
|
||
pending: number;
|
||
gap?: number;
|
||
max_met?: boolean;
|
||
daily_max?: number;
|
||
};
|
||
|
||
type Upcoming = {
|
||
id: string;
|
||
anchor_name?: string;
|
||
channel_name?: string;
|
||
upload_at?: number;
|
||
status?: string;
|
||
can_upload_now?: boolean;
|
||
};
|
||
|
||
type Job = {
|
||
id: string;
|
||
anchor_name?: string;
|
||
channel_name?: string;
|
||
status?: string;
|
||
push_date?: string;
|
||
error?: string;
|
||
clip_ready?: boolean;
|
||
tiktok_publish_id?: string;
|
||
created_at?: number;
|
||
finished_at?: number;
|
||
};
|
||
|
||
export default function TikTokPage() {
|
||
const toast = useToast();
|
||
const confirm = useConfirm();
|
||
const leftPanelRef = useRef<HTMLElement>(null);
|
||
const rightPanelRef = useRef<HTMLElement>(null);
|
||
|
||
const [loading, setLoading] = useState(true);
|
||
const [status, setStatus] = useState<any>(null);
|
||
const [channels, setChannels] = useState<Channel[]>([]);
|
||
const [jobs, setJobs] = useState<Job[]>([]);
|
||
const [jobTotal, setJobTotal] = useState(0);
|
||
|
||
const [clientKey, setClientKey] = useState("");
|
||
const [clientSecret, setClientSecret] = useState("");
|
||
const [savingCreds, setSavingCreds] = useState(false);
|
||
|
||
const [showForm, setShowForm] = useState(false);
|
||
const [editId, setEditId] = useState("");
|
||
const [formName, setFormName] = useState("TikTok 账号");
|
||
const [formPrivacy, setFormPrivacy] = useState("SELF_ONLY");
|
||
const [formTitle, setFormTitle] = useState("{anchor} #fyp");
|
||
const [formDesc, setFormDesc] = useState("{anchor}\n{url}");
|
||
|
||
const [uploadingId, setUploadingId] = useState("");
|
||
|
||
const load = useCallback(async () => {
|
||
const iso = todayBeijingISO();
|
||
const [st, j] = await Promise.all([
|
||
fetchJson("/api/tiktok/status"),
|
||
fetchJson(`/api/tiktok/jobs?push_date=${iso}&limit=30`),
|
||
]);
|
||
setStatus(st);
|
||
setChannels(st?.channels || []);
|
||
setJobs(j?.jobs || []);
|
||
setJobTotal(j?.total || 0);
|
||
setLoading(false);
|
||
}, []);
|
||
|
||
useEffect(() => {
|
||
void load();
|
||
const t = setInterval(() => void load(), 12000);
|
||
return () => clearInterval(t);
|
||
}, [load]);
|
||
|
||
useEffect(() => {
|
||
const left = leftPanelRef.current;
|
||
const right = rightPanelRef.current;
|
||
if (!left || !right) return;
|
||
const sync = () => {
|
||
right.style.maxHeight = `${left.getBoundingClientRect().height}px`;
|
||
};
|
||
sync();
|
||
const ro = new ResizeObserver(sync);
|
||
ro.observe(left);
|
||
return () => ro.disconnect();
|
||
});
|
||
|
||
useEffect(() => {
|
||
const params = new URLSearchParams(window.location.search);
|
||
const oauth = params.get("oauth");
|
||
if (oauth === "ok") {
|
||
toast.push(`TikTok 授权成功:${params.get("title") || ""}`, "ok");
|
||
window.history.replaceState({}, "", "/tiktok");
|
||
} else if (oauth === "error") {
|
||
toast.push(`授权失败:${params.get("msg") || ""}`, "err");
|
||
window.history.replaceState({}, "", "/tiktok");
|
||
}
|
||
}, [toast]);
|
||
|
||
const setup = status?.setup;
|
||
const setupDone = setup?.steps?.every((s: SetupStep) => s.done);
|
||
const board = status?.board || {};
|
||
const boardChannels: BoardChannel[] = board.channels || [];
|
||
const upcoming: Upcoming[] = board.upcoming || [];
|
||
const beijingWindow = board.beijing_window || "";
|
||
const oauthConfigured = status?.oauth_configured;
|
||
const redirectUri = status?.oauth_redirect_uri || "";
|
||
|
||
const togglePipeline = async () => {
|
||
const on = status?.enabled;
|
||
await fetchJson(on ? "/api/tiktok/stop" : "/api/tiktok/start", { method: "POST" });
|
||
toast.push(on ? "TikTok 已暂停" : "TikTok 已启动", "ok");
|
||
void load();
|
||
};
|
||
|
||
const saveCredentials = async () => {
|
||
if (!clientKey.trim()) {
|
||
toast.push("请填写 Client Key", "err");
|
||
return;
|
||
}
|
||
setSavingCreds(true);
|
||
try {
|
||
await fetchJson("/api/tiktok/oauth/config", {
|
||
method: "POST",
|
||
body: JSON.stringify({ client_key: clientKey.trim(), client_secret: clientSecret.trim() }),
|
||
});
|
||
toast.push("凭证已保存", "ok");
|
||
setClientSecret("");
|
||
void load();
|
||
} catch (e: any) {
|
||
toast.push(e?.message || "保存失败", "err");
|
||
} finally {
|
||
setSavingCreds(false);
|
||
}
|
||
};
|
||
|
||
const addChannel = async () => {
|
||
await fetchJson("/api/tiktok/channels", {
|
||
method: "POST",
|
||
body: JSON.stringify({
|
||
name: formName,
|
||
privacy_level: formPrivacy,
|
||
title_template: formTitle,
|
||
description_template: formDesc,
|
||
}),
|
||
});
|
||
toast.push("账号已添加,请点击「授权」", "ok");
|
||
setShowForm(false);
|
||
void load();
|
||
};
|
||
|
||
const saveChannel = async () => {
|
||
if (!editId) return;
|
||
await fetchJson(`/api/tiktok/channels/${editId}`, {
|
||
method: "PATCH",
|
||
body: JSON.stringify({
|
||
name: formName,
|
||
privacy_level: formPrivacy,
|
||
title_template: formTitle,
|
||
description_template: formDesc,
|
||
}),
|
||
});
|
||
toast.push("已保存", "ok");
|
||
setShowForm(false);
|
||
setEditId("");
|
||
void load();
|
||
};
|
||
|
||
const removeChannel = async (id: string) => {
|
||
const ok = await confirm({
|
||
title: "删除 TikTok 账号",
|
||
message: "确定删除此账号?",
|
||
confirmLabel: "删除",
|
||
destructive: true,
|
||
});
|
||
if (!ok) return;
|
||
await fetchJson(`/api/tiktok/channels/${id}`, { method: "DELETE" });
|
||
toast.push("已删除", "ok");
|
||
void load();
|
||
};
|
||
|
||
const authorize = (id: string) => {
|
||
window.location.href = `/api/tiktok/oauth/start?channel_pk=${encodeURIComponent(id)}`;
|
||
};
|
||
|
||
const sampleNow = async () => {
|
||
const r = await fetchJson("/api/tiktok/sample-now", { method: "POST" });
|
||
toast.push(`已取样 ${r.enqueued || 0} 条`, "ok");
|
||
void load();
|
||
};
|
||
|
||
const uploadNow = async (jobId: string) => {
|
||
setUploadingId(jobId);
|
||
try {
|
||
await fetchJson(`/api/tiktok/jobs/${jobId}/upload-now`, { method: "POST" });
|
||
toast.push("上传成功", "ok");
|
||
void load();
|
||
} catch (e: any) {
|
||
toast.push(e?.message || "上传失败", "err");
|
||
} finally {
|
||
setUploadingId("");
|
||
}
|
||
};
|
||
|
||
const retryJob = async (jobId: string) => {
|
||
await fetchJson(`/api/tiktok/jobs/${jobId}/retry`, { method: "POST" });
|
||
toast.push("已重新排队", "ok");
|
||
void load();
|
||
};
|
||
|
||
const startEdit = (ch: Channel) => {
|
||
setEditId(ch.id);
|
||
setFormName(ch.name || "TikTok 账号");
|
||
setFormPrivacy(ch.privacy_level || "SELF_ONLY");
|
||
setFormTitle(ch.title_template || "{anchor} #fyp");
|
||
setFormDesc(ch.description_template || "{anchor}\n{url}");
|
||
setShowForm(true);
|
||
};
|
||
|
||
const statusLabel = useMemo(
|
||
() => ({
|
||
pending: "待录制",
|
||
recording: "录制中",
|
||
recorded: "成片就绪",
|
||
scheduled: "已排程",
|
||
uploading: "上传中",
|
||
uploaded: "已上传",
|
||
failed: "失败",
|
||
}),
|
||
[],
|
||
);
|
||
|
||
if (loading && !status) {
|
||
return (
|
||
<Shell>
|
||
<PageLoader label="加载 TikTok…" />
|
||
</Shell>
|
||
);
|
||
}
|
||
|
||
return (
|
||
<Shell>
|
||
<div className="mx-auto max-w-7xl px-4 py-6 sm:px-6">
|
||
{/* Header */}
|
||
<div className="mb-6 flex flex-wrap items-center justify-between gap-3">
|
||
<div>
|
||
<h1 className="font-display flex items-center gap-2 text-xl font-semibold text-slate-50">
|
||
<Music2 className="h-6 w-6 text-pink-400" />
|
||
TikTok 自动上传
|
||
</h1>
|
||
<p className="mt-1 text-sm text-slate-500">独立模块 · 不影响 Shorts · 抖音直播录屏 → TikTok</p>
|
||
</div>
|
||
<div className="flex flex-wrap items-center gap-2">
|
||
<button
|
||
type="button"
|
||
onClick={() => void load()}
|
||
className="rounded-xl border border-white/10 bg-white/5 px-3 py-2 text-sm text-slate-200 hover:bg-white/10"
|
||
>
|
||
<RefreshCw className="mr-1 inline h-4 w-4" />
|
||
刷新
|
||
</button>
|
||
{setupDone && (
|
||
<>
|
||
<button
|
||
type="button"
|
||
onClick={() => void sampleNow()}
|
||
className="rounded-xl border border-pink-500/30 bg-pink-500/10 px-3 py-2 text-sm text-pink-200 hover:bg-pink-500/20"
|
||
>
|
||
立即取样
|
||
</button>
|
||
<button
|
||
type="button"
|
||
onClick={() => void togglePipeline()}
|
||
className={`rounded-xl px-4 py-2 text-sm font-medium ${
|
||
status?.enabled
|
||
? "border border-amber-500/40 bg-amber-500/15 text-amber-200"
|
||
: "bg-pink-500 text-white hover:bg-pink-400"
|
||
}`}
|
||
>
|
||
{status?.enabled ? "暂停自动上传" : "启动自动上传"}
|
||
</button>
|
||
</>
|
||
)}
|
||
</div>
|
||
</div>
|
||
|
||
{/* Setup wizard */}
|
||
{!setupDone && (
|
||
<section className="mb-6 rounded-2xl border border-pink-500/25 bg-gradient-to-br from-pink-500/10 to-transparent p-5">
|
||
<h2 className="mb-1 text-base font-medium text-slate-100">🚀 三步完成配置(约 5 分钟)</h2>
|
||
<p className="mb-4 text-sm text-slate-400">按顺序完成下面步骤,即可自动上传。未审核应用只能发「仅自己可见」。</p>
|
||
|
||
<div className="mb-5 space-y-3">
|
||
{(setup?.steps || []).map((step: SetupStep, i: number) => (
|
||
<div key={step.id} className="flex items-start gap-3 rounded-xl border border-white/10 bg-black/20 p-3">
|
||
{step.done ? (
|
||
<CheckCircle2 className="mt-0.5 h-5 w-5 shrink-0 text-teal-400" />
|
||
) : (
|
||
<Circle className="mt-0.5 h-5 w-5 shrink-0 text-slate-500" />
|
||
)}
|
||
<div className="min-w-0 flex-1">
|
||
<div className="text-sm text-slate-200">
|
||
{i + 1}. {step.title}
|
||
</div>
|
||
{step.url && !step.done && (
|
||
<a
|
||
href={step.url}
|
||
target="_blank"
|
||
rel="noreferrer"
|
||
className="mt-1 inline-flex items-center gap-1 text-xs text-pink-300 hover:underline"
|
||
>
|
||
打开官方文档 <ExternalLink className="h-3 w-3" />
|
||
</a>
|
||
)}
|
||
</div>
|
||
</div>
|
||
))}
|
||
</div>
|
||
|
||
{!oauthConfigured && (
|
||
<div className="rounded-xl border border-white/10 bg-black/30 p-4">
|
||
<h3 className="mb-3 text-sm font-medium text-slate-100">填写 TikTok 应用凭证</h3>
|
||
<p className="mb-3 text-xs text-slate-500">
|
||
Redirect URI 填:<code className="text-pink-300">{redirectUri}</code>
|
||
</p>
|
||
<div className="grid gap-3 sm:grid-cols-2">
|
||
<label className="block text-xs text-slate-400">
|
||
Client Key
|
||
<input
|
||
value={clientKey}
|
||
onChange={(e) => setClientKey(e.target.value)}
|
||
placeholder="从 TikTok 开发者后台复制"
|
||
className="mt-1 w-full rounded-lg border border-white/10 bg-black/40 px-3 py-2 text-sm text-slate-100"
|
||
/>
|
||
</label>
|
||
<label className="block text-xs text-slate-400">
|
||
Client Secret
|
||
<input
|
||
type="password"
|
||
value={clientSecret}
|
||
onChange={(e) => setClientSecret(e.target.value)}
|
||
placeholder="从 TikTok 开发者后台复制"
|
||
className="mt-1 w-full rounded-lg border border-white/10 bg-black/40 px-3 py-2 text-sm text-slate-100"
|
||
/>
|
||
</label>
|
||
</div>
|
||
<button
|
||
type="button"
|
||
disabled={savingCreds}
|
||
onClick={() => void saveCredentials()}
|
||
className="mt-3 rounded-lg bg-pink-500 px-4 py-2 text-sm font-medium text-white hover:bg-pink-400 disabled:opacity-50"
|
||
>
|
||
{savingCreds ? "保存中…" : "保存凭证"}
|
||
</button>
|
||
</div>
|
||
)}
|
||
|
||
{oauthConfigured && channels.length === 0 && (
|
||
<button
|
||
type="button"
|
||
onClick={() => {
|
||
setEditId("");
|
||
setShowForm(true);
|
||
}}
|
||
className="mt-2 flex items-center gap-2 rounded-xl bg-pink-500 px-4 py-2.5 text-sm font-medium text-white hover:bg-pink-400"
|
||
>
|
||
<Plus className="h-4 w-4" />
|
||
添加第一个 TikTok 账号
|
||
</button>
|
||
)}
|
||
|
||
{setup?.note_unaudited && (
|
||
<p className="mt-4 text-xs text-amber-300/90">⚠️ {setup.note_unaudited}</p>
|
||
)}
|
||
</section>
|
||
)}
|
||
|
||
{/* Summary cards */}
|
||
{setupDone && (
|
||
<div className="mb-6 grid gap-3 sm:grid-cols-2 lg:grid-cols-4">
|
||
<div className="rounded-2xl border border-white/10 bg-black/25 p-4">
|
||
<div className="text-xs text-slate-500">今日剩余配额</div>
|
||
<div className="mt-1 text-2xl font-semibold text-pink-300">{status?.quota_gap ?? "—"}</div>
|
||
<div className="text-[11px] text-slate-500">{beijingWindow}</div>
|
||
</div>
|
||
<div className="rounded-2xl border border-white/10 bg-black/25 p-4">
|
||
<div className="text-xs text-slate-500">抖音直播中</div>
|
||
<div className="mt-1 text-2xl font-semibold text-teal-300">{status?.douyin_live_count ?? 0}</div>
|
||
<div className="text-[11px] text-slate-500">可取样来源</div>
|
||
</div>
|
||
<div className="rounded-2xl border border-white/10 bg-black/25 p-4">
|
||
<div className="text-xs text-slate-500">即将上传</div>
|
||
<div className="mt-1 text-2xl font-semibold text-amber-300">{upcoming.length}</div>
|
||
<div className="text-[11px] text-slate-500">已排程素材</div>
|
||
</div>
|
||
<div className="rounded-2xl border border-white/10 bg-black/25 p-4">
|
||
<div className="text-xs text-slate-500">运行状态</div>
|
||
<div className="mt-1 flex items-center gap-2">
|
||
<span className={`h-2 w-2 rounded-full ${status?.enabled ? "bg-teal-400" : "bg-slate-500"}`} />
|
||
<span className="text-sm text-slate-200">{status?.enabled ? "自动上传中" : "已暂停"}</span>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
)}
|
||
|
||
{/* Control bar */}
|
||
{oauthConfigured && (
|
||
<div className="mb-6 flex flex-wrap items-center gap-2">
|
||
<button
|
||
type="button"
|
||
onClick={() => {
|
||
setEditId("");
|
||
setFormName("TikTok 账号");
|
||
setShowForm(true);
|
||
}}
|
||
className="flex items-center gap-1 rounded-xl border border-white/10 bg-white/5 px-3 py-2 text-sm text-slate-200 hover:bg-white/10"
|
||
>
|
||
<Plus className="h-4 w-4" />
|
||
新增账号
|
||
</button>
|
||
<Link
|
||
href="https://developers.tiktok.com/apps"
|
||
target="_blank"
|
||
className="flex items-center gap-1 rounded-xl border border-white/10 px-3 py-2 text-xs text-slate-400 hover:text-slate-200"
|
||
>
|
||
<ExternalLink className="h-3 w-3" />
|
||
开发者后台
|
||
</Link>
|
||
</div>
|
||
)}
|
||
|
||
{/* Channel form */}
|
||
{showForm && (
|
||
<section className="mb-6 rounded-2xl border border-white/10 bg-black/30 p-4">
|
||
<h3 className="mb-3 text-sm font-medium text-slate-100">{editId ? "编辑账号" : "新增 TikTok 账号"}</h3>
|
||
<div className="grid gap-3 sm:grid-cols-2">
|
||
<label className="text-xs text-slate-400">
|
||
显示名称
|
||
<input
|
||
value={formName}
|
||
onChange={(e) => setFormName(e.target.value)}
|
||
className="mt-1 w-full rounded-lg border border-white/10 bg-black/40 px-3 py-2 text-sm"
|
||
/>
|
||
</label>
|
||
<label className="text-xs text-slate-400">
|
||
可见性
|
||
<select
|
||
value={formPrivacy}
|
||
onChange={(e) => setFormPrivacy(e.target.value)}
|
||
className="mt-1 w-full rounded-lg border border-white/10 bg-black/40 px-3 py-2 text-sm"
|
||
>
|
||
<option value="SELF_ONLY">仅自己可见(未审核应用)</option>
|
||
<option value="MUTUAL_FOLLOW_FRIENDS">互关好友</option>
|
||
<option value="PUBLIC_TO_EVERYONE">公开(需审核通过)</option>
|
||
</select>
|
||
</label>
|
||
<label className="text-xs text-slate-400 sm:col-span-2">
|
||
标题模板
|
||
<input
|
||
value={formTitle}
|
||
onChange={(e) => setFormTitle(e.target.value)}
|
||
className="mt-1 w-full rounded-lg border border-white/10 bg-black/40 px-3 py-2 text-sm"
|
||
/>
|
||
</label>
|
||
</div>
|
||
<div className="mt-3 flex gap-2">
|
||
<button
|
||
type="button"
|
||
onClick={() => void (editId ? saveChannel() : addChannel())}
|
||
className="rounded-lg bg-pink-500 px-4 py-2 text-sm text-white hover:bg-pink-400"
|
||
>
|
||
保存
|
||
</button>
|
||
<button
|
||
type="button"
|
||
onClick={() => setShowForm(false)}
|
||
className="rounded-lg border border-white/10 px-4 py-2 text-sm text-slate-400"
|
||
>
|
||
取消
|
||
</button>
|
||
</div>
|
||
</section>
|
||
)}
|
||
|
||
{/* Two-column board */}
|
||
{channels.length > 0 && (
|
||
<div className="mb-6 grid gap-4 xl:grid-cols-[1.4fr_1fr] xl:items-start">
|
||
<section ref={leftPanelRef} className="rounded-2xl border border-white/10 bg-black/25 p-4">
|
||
<div className="mb-3 flex items-center justify-between">
|
||
<h3 className="text-sm font-medium text-slate-100">账号配额({channels.length})</h3>
|
||
<span className="text-[11px] text-slate-500">北京日 {beijingWindow || "—"} · 每账号 9 条/日</span>
|
||
</div>
|
||
<div className="grid gap-3 sm:grid-cols-2">
|
||
{(boardChannels.length ? boardChannels : channels).map((ch) => {
|
||
const full = channels.find((x) => x.id === ch.id);
|
||
const pct = Math.min(100, Math.round(((ch.used || 0) / Math.max(1, ch.daily_max || 9)) * 100));
|
||
return (
|
||
<div
|
||
key={ch.id}
|
||
className={`rounded-xl border bg-gradient-to-br from-white/[0.04] to-transparent p-3 ${
|
||
ch.max_met ? "border-teal-500/30" : "border-white/10"
|
||
}`}
|
||
>
|
||
<div className="flex items-start justify-between gap-2">
|
||
<div className="min-w-0">
|
||
<div className="truncate font-medium text-slate-100">{ch.name || "未命名"}</div>
|
||
<div className="truncate text-[10px] text-slate-500">{ch.tiktok_username || "—"}</div>
|
||
</div>
|
||
<span className={`text-[10px] ${full?.authorized ? "text-teal-300" : "text-rose-300"}`}>
|
||
{full?.authorized ? "已授权" : "未授权"}
|
||
</span>
|
||
</div>
|
||
<div className="mt-2 h-1.5 overflow-hidden rounded-full bg-white/10">
|
||
<div className="h-full rounded-full bg-pink-500/70" style={{ width: `${pct}%` }} />
|
||
</div>
|
||
<div className="mt-2 flex flex-wrap gap-2 text-[10px] text-slate-400">
|
||
<span>已传 {ch.uploaded ?? 0}</span>
|
||
<span>排程 {ch.scheduled ?? 0}</span>
|
||
<span>待录 {ch.pending ?? 0}</span>
|
||
<span className={ch.max_met ? "text-teal-300" : "text-amber-300"}>
|
||
{ch.max_met ? "已满" : `余 ${ch.gap ?? 0}`}
|
||
</span>
|
||
</div>
|
||
<div className="mt-2 flex flex-wrap gap-1">
|
||
<button
|
||
type="button"
|
||
onClick={() => authorize(ch.id)}
|
||
className="inline-flex items-center gap-1 rounded-lg bg-pink-500/15 px-2 py-1 text-[11px] text-pink-200"
|
||
>
|
||
<KeyRound className="h-3 w-3" />
|
||
授权
|
||
</button>
|
||
{full && (
|
||
<button
|
||
type="button"
|
||
onClick={() => startEdit(full)}
|
||
className="rounded-lg bg-white/5 px-2 py-1 text-[11px]"
|
||
>
|
||
编辑
|
||
</button>
|
||
)}
|
||
<button
|
||
type="button"
|
||
onClick={() => void removeChannel(ch.id)}
|
||
className="inline-flex items-center gap-1 rounded-lg bg-rose-500/10 px-2 py-1 text-[11px] text-rose-200"
|
||
>
|
||
<Trash2 className="h-3 w-3" />
|
||
</button>
|
||
</div>
|
||
</div>
|
||
);
|
||
})}
|
||
</div>
|
||
</section>
|
||
|
||
<section
|
||
ref={rightPanelRef}
|
||
className="flex flex-col overflow-hidden rounded-2xl border border-white/10 bg-black/25 p-4"
|
||
>
|
||
<div className="mb-3 flex items-center justify-between">
|
||
<div className="flex items-center gap-2">
|
||
<Clock3 className="h-4 w-4 text-amber-300" />
|
||
<h3 className="text-sm font-medium text-slate-100">即将上传</h3>
|
||
</div>
|
||
<span className="rounded-full border border-amber-500/25 bg-amber-500/10 px-2 py-0.5 text-xs text-amber-200">
|
||
素材 {upcoming.length}
|
||
</span>
|
||
</div>
|
||
<div className="min-h-0 flex-1 space-y-2 overflow-y-auto pr-1">
|
||
{upcoming.length === 0 ? (
|
||
<div className="rounded-xl border border-dashed border-white/10 py-8 text-center text-sm text-slate-500">
|
||
暂无排程。启动自动上传后,系统会从抖音直播中取样。
|
||
</div>
|
||
) : (
|
||
upcoming.map((u) => (
|
||
<div
|
||
key={u.id}
|
||
className="flex items-center justify-between gap-2 rounded-xl border border-white/10 bg-white/[0.03] p-3"
|
||
>
|
||
<div className="min-w-0">
|
||
<div className="truncate text-sm text-slate-100">{u.anchor_name || "—"}</div>
|
||
<div className="truncate text-[10px] text-slate-500">
|
||
{u.channel_name} · {u.upload_at ? fmtTs(u.upload_at) : "—"}
|
||
</div>
|
||
</div>
|
||
{u.can_upload_now && (
|
||
<button
|
||
type="button"
|
||
disabled={uploadingId === u.id}
|
||
onClick={() => void uploadNow(u.id)}
|
||
className="shrink-0 rounded-lg bg-teal-500/20 px-2 py-1 text-[11px] text-teal-200 hover:bg-teal-500/30 disabled:opacity-50"
|
||
>
|
||
{uploadingId === u.id ? (
|
||
<Loader2 className="h-3 w-3 animate-spin" />
|
||
) : (
|
||
<>
|
||
<Upload className="mr-1 inline h-3 w-3" />
|
||
立即上传
|
||
</>
|
||
)}
|
||
</button>
|
||
)}
|
||
</div>
|
||
))
|
||
)}
|
||
</div>
|
||
</section>
|
||
</div>
|
||
)}
|
||
|
||
{/* Jobs table */}
|
||
{setupDone && (
|
||
<section className="rounded-2xl border border-white/10 bg-black/25 p-4">
|
||
<div className="mb-3 flex items-center justify-between">
|
||
<h3 className="text-sm font-medium text-slate-100">任务流水(今日 {jobTotal})</h3>
|
||
</div>
|
||
<div className="overflow-x-auto">
|
||
<table className="w-full text-left text-sm">
|
||
<thead>
|
||
<tr className="border-b border-white/10 text-xs text-slate-500">
|
||
<th className="py-2 pr-3">主播</th>
|
||
<th className="py-2 pr-3">账号</th>
|
||
<th className="py-2 pr-3">状态</th>
|
||
<th className="py-2 pr-3">时间</th>
|
||
<th className="py-2">操作</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
{jobs.length === 0 ? (
|
||
<tr>
|
||
<td colSpan={5} className="py-8 text-center text-slate-500">
|
||
暂无任务
|
||
</td>
|
||
</tr>
|
||
) : (
|
||
jobs.map((j) => (
|
||
<tr key={j.id} className="border-b border-white/5">
|
||
<td className="py-2 pr-3 text-slate-200">{j.anchor_name || "—"}</td>
|
||
<td className="py-2 pr-3 text-slate-400">{j.channel_name || "—"}</td>
|
||
<td className="py-2 pr-3">
|
||
<span
|
||
className={
|
||
j.status === "uploaded"
|
||
? "text-teal-300"
|
||
: j.status === "failed"
|
||
? "text-rose-300"
|
||
: "text-slate-400"
|
||
}
|
||
>
|
||
{statusLabel[j.status as keyof typeof statusLabel] || j.status}
|
||
</span>
|
||
{j.error && (
|
||
<div className="max-w-xs truncate text-[10px] text-rose-400/80" title={j.error}>
|
||
{j.error}
|
||
</div>
|
||
)}
|
||
</td>
|
||
<td className="py-2 pr-3 text-xs text-slate-500">
|
||
{j.finished_at ? fmtTs(j.finished_at) : j.created_at ? fmtTs(j.created_at) : "—"}
|
||
</td>
|
||
<td className="py-2">
|
||
<div className="flex gap-1">
|
||
{j.clip_ready && j.status !== "uploaded" && (
|
||
<button
|
||
type="button"
|
||
disabled={uploadingId === j.id}
|
||
onClick={() => void uploadNow(j.id)}
|
||
className="rounded bg-teal-500/15 px-2 py-0.5 text-[10px] text-teal-200"
|
||
>
|
||
上传
|
||
</button>
|
||
)}
|
||
{j.status === "failed" && (
|
||
<button
|
||
type="button"
|
||
onClick={() => void retryJob(j.id)}
|
||
className="rounded bg-white/5 px-2 py-0.5 text-[10px]"
|
||
>
|
||
重试
|
||
</button>
|
||
)}
|
||
</div>
|
||
</td>
|
||
</tr>
|
||
))
|
||
)}
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
</section>
|
||
)}
|
||
|
||
{/* Quick help */}
|
||
<section className="mt-6 rounded-2xl border border-white/5 bg-black/15 p-4 text-xs text-slate-500">
|
||
<div className="mb-2 flex items-center gap-2 font-medium text-slate-400">
|
||
<Zap className="h-4 w-4 text-pink-400" />
|
||
使用说明
|
||
</div>
|
||
<ol className="list-inside list-decimal space-y-1">
|
||
<li>在 TikTok 开发者后台创建应用,申请 <code className="text-pink-300">video.publish</code> 权限</li>
|
||
<li>Redirect URI 填:<code className="text-pink-300">{redirectUri}</code></li>
|
||
<li>保存 Client Key / Secret → 添加账号 → 点击「授权」</li>
|
||
<li>点击「启动自动上传」,系统会自动从抖音直播取样、录屏、错峰上传</li>
|
||
</ol>
|
||
</section>
|
||
</div>
|
||
</Shell>
|
||
);
|
||
}
|