"use client"; import { useState } from "react"; import { ExternalLink, Loader2, RefreshCw, Square } from "lucide-react"; import { Modal } from "@/components/Modal"; import { fetchJson, fmtDuration, fmtTs, sessionCoverSrc } from "@/lib/api"; export type SessionDetail = { id: string; anchor_name?: string; source_url?: string; room_id?: string; title?: string; started_at?: number; ended_at?: number | null; duration_seconds?: number; cover_url?: string; cover_proxy_url?: string; status?: string; end_reason?: string; }; type Props = { session: SessionDetail | null; onClose: () => void; onUpdated?: (session: SessionDetail) => void; extraRows?: Array<{ label: string; value: React.ReactNode }>; }; export function SessionDetailModal({ session, onClose, onUpdated, extraRows }: Props) { const [busy, setBusy] = useState(""); const [err, setErr] = useState(""); const [local, setLocal] = useState(null); const current = local && local.id === session?.id ? local : session; const cover = sessionCoverSrc(current || undefined); const isActive = Boolean(current && !current.ended_at); async function recapture() { if (!current?.id) return; setBusy("cover"); setErr(""); try { await fetchJson(`/api/sessions/${current.id}/recapture`, { method: "POST", body: "{}" }); const data = await fetchJson(`/api/sessions/${current.id}`); const next = (data.session || data) as SessionDetail; setLocal(next); onUpdated?.(next); } catch (e) { setErr((e as Error).message); } finally { setBusy(""); } } async function endNow() { if (!current?.id) return; if (!confirm(`确认手动结束「${current.anchor_name || current.room_id}」这场?`)) return; setBusy("end"); setErr(""); try { const data = await fetchJson(`/api/sessions/${current.id}/end`, { method: "POST" }); const next = (data.session || data) as SessionDetail; setLocal(next); onUpdated?.(next); } catch (e) { setErr((e as Error).message); } finally { setBusy(""); } } return ( {current ? ( <>

{current.anchor_name || "直播间详情"}

{current.title || "—"}

{isActive ? ( ) : null}
{err ?
{err}
: null}
{cover ? ( // eslint-disable-next-line @next/next/no-img-element ) : (
暂无截图
)}
直播间 URL
{current.source_url ? ( {current.source_url} ) : ( "—" )}
房间号
{current.room_id || "—"}
{extraRows?.map((row) => (
{row.label}
{row.value}
))}
开播
{fmtTs(current.started_at)}
停播
{current.ended_at ? fmtTs(current.ended_at) : "进行中"}
总时长
{fmtDuration(current.duration_seconds)}
结束原因
{current.end_reason || "—"}
) : null}
); }