Same-named channels are split into account sections with colored Client badges on cards, schedule rows, and job lists. Co-authored-by: Cursor <cursoragent@cursor.com>
183 lines
6.3 KiB
TypeScript
183 lines
6.3 KiB
TypeScript
"use client";
|
|
|
|
import { ExternalLink, Loader2, X } from "lucide-react";
|
|
import { useEffect, useState, type ReactNode } from "react";
|
|
|
|
import { Modal } from "@/components/Modal";
|
|
import { OauthClientBadge } from "@/components/OauthClientBadge";
|
|
import { fetchJson, fmtTs } from "@/lib/api";
|
|
|
|
type JobDetail = {
|
|
id: string;
|
|
status: string;
|
|
anchor_name?: string;
|
|
room_id?: string;
|
|
channel_name?: string;
|
|
channel_pk?: string;
|
|
oauth_profile_id?: string;
|
|
push_date?: string;
|
|
clip_path?: string;
|
|
clip_ready?: boolean;
|
|
clip_seconds?: number;
|
|
youtube_url?: string;
|
|
youtube_video_id?: string;
|
|
error?: string;
|
|
attempts?: number;
|
|
session_id?: string;
|
|
source_url?: string;
|
|
created_at?: number;
|
|
updated_at?: number;
|
|
upload_at?: number;
|
|
started_at?: number;
|
|
finished_at?: number;
|
|
preview_title?: string;
|
|
preview_description?: string;
|
|
};
|
|
|
|
const STATUS_STYLE: Record<string, string> = {
|
|
pending: "bg-slate-500/20 text-slate-200",
|
|
recording: "bg-sky-500/20 text-sky-100",
|
|
recorded: "bg-indigo-500/20 text-indigo-100",
|
|
scheduled: "bg-amber-500/20 text-amber-100",
|
|
uploading: "bg-violet-500/20 text-violet-100",
|
|
uploaded: "bg-teal-500/20 text-teal-100",
|
|
failed: "bg-rose-500/20 text-rose-100",
|
|
};
|
|
|
|
function Row({ label, children }: { label: string; children: ReactNode }) {
|
|
return (
|
|
<div className="grid grid-cols-[88px_1fr] gap-2 border-t border-white/5 py-2 text-xs first:border-t-0">
|
|
<div className="text-slate-500">{label}</div>
|
|
<div className="min-w-0 text-slate-200">{children}</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export function ShortsJobDetailModal({
|
|
jobId,
|
|
onClose,
|
|
}: {
|
|
jobId: string | null;
|
|
onClose: () => void;
|
|
}) {
|
|
const [job, setJob] = useState<JobDetail | null>(null);
|
|
const [loading, setLoading] = useState(false);
|
|
const [err, setErr] = useState("");
|
|
|
|
useEffect(() => {
|
|
if (!jobId) {
|
|
setJob(null);
|
|
return;
|
|
}
|
|
let cancelled = false;
|
|
setLoading(true);
|
|
setErr("");
|
|
void fetchJson(`/api/shorts/jobs/${jobId}`)
|
|
.then((data) => {
|
|
if (!cancelled) setJob(data.job || data);
|
|
})
|
|
.catch((e) => {
|
|
if (!cancelled) setErr((e as Error).message);
|
|
})
|
|
.finally(() => {
|
|
if (!cancelled) setLoading(false);
|
|
});
|
|
return () => {
|
|
cancelled = true;
|
|
};
|
|
}, [jobId]);
|
|
|
|
const clipUrl = job?.clip_ready ? `/api/shorts/jobs/${job.id}/clip` : "";
|
|
|
|
return (
|
|
<Modal open={Boolean(jobId)} onClose={onClose} panelClassName="w-full max-w-lg rounded-2xl border border-white/10 bg-[#0b1626] p-0 shadow-2xl">
|
|
<div className="flex items-start justify-between gap-3 border-b border-white/10 px-5 py-4">
|
|
<div className="min-w-0">
|
|
<p className="text-xs uppercase tracking-wider text-teal-300/80">任务详情</p>
|
|
<h3 className="mt-1 truncate font-display text-lg font-semibold text-white">
|
|
{job?.anchor_name || job?.room_id || jobId || "—"}
|
|
</h3>
|
|
</div>
|
|
<button type="button" onClick={onClose} className="rounded-lg p-1 text-slate-400 hover:bg-white/5 hover:text-white">
|
|
<X className="h-4 w-4" />
|
|
</button>
|
|
</div>
|
|
<div className="max-h-[70vh] overflow-y-auto px-5 py-4">
|
|
{loading ? (
|
|
<div className="flex items-center justify-center gap-2 py-12 text-sm text-slate-400">
|
|
<Loader2 className="h-4 w-4 animate-spin" />
|
|
加载中…
|
|
</div>
|
|
) : err ? (
|
|
<p className="py-8 text-center text-sm text-rose-300">{err}</p>
|
|
) : job ? (
|
|
<>
|
|
{clipUrl ? (
|
|
<video
|
|
src={clipUrl}
|
|
controls
|
|
playsInline
|
|
preload="metadata"
|
|
className="mb-4 aspect-[9/16] max-h-64 w-full rounded-xl bg-black object-contain"
|
|
/>
|
|
) : null}
|
|
<Row label="状态">
|
|
<span className={`inline-block rounded-md px-2 py-0.5 text-[11px] ${STATUS_STYLE[job.status] || "bg-white/10"}`}>
|
|
{job.status}
|
|
</span>
|
|
</Row>
|
|
<Row label="频道">
|
|
<div className="flex flex-wrap items-center gap-2">
|
|
<OauthClientBadge profileId={job.oauth_profile_id} size="sm" />
|
|
<span>{job.channel_name || "—"}</span>
|
|
</div>
|
|
</Row>
|
|
<Row label="北京日">{job.push_date || "—"}</Row>
|
|
<Row label="排程上传">{job.upload_at ? fmtTs(Number(job.upload_at)) : "—"}</Row>
|
|
<Row label="创建">{job.created_at ? fmtTs(Number(job.created_at)) : "—"}</Row>
|
|
<Row label="尝试次数">{String(job.attempts ?? 0)}</Row>
|
|
<Row label="成片">
|
|
{job.clip_ready ? `${Math.round(Number(job.clip_seconds || 15))}s · 可预览` : job.clip_path ? "路径失效" : "无"}
|
|
</Row>
|
|
{job.preview_title ? (
|
|
<Row label="标题预览">
|
|
<span className="break-words text-slate-300">{job.preview_title}</span>
|
|
</Row>
|
|
) : null}
|
|
{job.error ? (
|
|
<Row label="错误">
|
|
<span className="break-words text-rose-300">{job.error}</span>
|
|
</Row>
|
|
) : null}
|
|
{job.youtube_url ? (
|
|
<Row label="YouTube">
|
|
<a href={job.youtube_url} target="_blank" rel="noreferrer" className="inline-flex items-center gap-1 text-teal-300 hover:underline">
|
|
已发布
|
|
<ExternalLink className="h-3 w-3" />
|
|
</a>
|
|
</Row>
|
|
) : null}
|
|
{job.session_id ? (
|
|
<Row label="场次">
|
|
<a href={`/sessions?highlight=${job.session_id}`} className="font-mono text-[10px] text-sky-300 hover:underline">
|
|
{job.session_id.slice(0, 8)}…
|
|
</a>
|
|
</Row>
|
|
) : null}
|
|
{job.source_url ? (
|
|
<Row label="来源">
|
|
<a href={job.source_url} target="_blank" rel="noreferrer" className="break-all text-sky-300 hover:underline">
|
|
{job.source_url}
|
|
</a>
|
|
</Row>
|
|
) : null}
|
|
<Row label="任务 ID">
|
|
<span className="break-all font-mono text-[10px] text-slate-500">{job.id}</span>
|
|
</Row>
|
|
</>
|
|
) : null}
|
|
</div>
|
|
</Modal>
|
|
);
|
|
}
|