"use client"; import { useState } from "react"; import Link from "next/link"; import { ExternalLink, Loader2, RefreshCw, Square } from "lucide-react"; import { ImageLightbox } from "@/components/ImageLightbox"; import { Modal } from "@/components/Modal"; import { RoomQuickActions } from "@/components/RoomQuickActions"; import { fetchJson, fmtDuration, fmtTs, sessionCoverSrc } from "@/lib/api"; export type SessionDetail = { id: string; anchor_name?: string; source_url?: string; room_id?: string; room_pk?: 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 [zoom, setZoom] = useState(false); 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 || "—"}

onUpdated?.(current)} onError={(m) => setErr(m)} /> {isActive ? ( ) : null}
{err ?
{err}
: null}
{cover ? ( ) : (
暂无截图
)}
直播间 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 || "—"}
{current.anchor_name ? ( 本主播场次 ) : null} {current.room_id ? ( 本房事件 ) : null} {current.anchor_name || current.room_id ? ( 相关截图 ) : null} {current.anchor_name ? ( 主播画像 ) : null}
) : null}
{zoom && cover ? ( setZoom(false)} /> ) : null} ); }