import { format } from "date-fns"; import { zhCN } from "date-fns/locale"; import { getAllSnapshots } from "@/lib/db/snapshots/getAllSnapshots"; import { getAidFromBV } from "@/lib/db/bilibili_metadata/getAidFromBV"; import { getVideoMetadata } from "@/lib/db/bilibili_metadata/getVideoMetadata"; import { aidExists as idExists } from "@/lib/db/bilibili_metadata/aidExists"; import { notFound } from "next/navigation"; import { BiliVideoMetadataType, VideoSnapshotType } from "@cvsa/core"; import { Metadata } from "next"; const MetadataRow = ({ title, desc }: { title: string; desc: string | number | undefined | null }) => { if (!desc) return <>; return ( {title} {desc} ); }; export async function generateMetadata({ params }: { params: Promise<{ id: string }> }): Promise { const backendURL = process.env.BACKEND_URL; const { id } = await params; const res = await fetch(`${backendURL}/video/${id}/info`); if (!res.ok) { return { title: "页面未找到 - 中 V 档案馆" }; } const data = await res.json(); return { title: `${data.title} - 歌曲信息 - 中 V 档案馆` }; } export default async function VideoInfoPage({ params }: { params: Promise<{ id: string }> }) { const { id } = await params; let videoInfo: BiliVideoMetadataType | null = null; let snapshots: VideoSnapshotType[] = []; async function getVideoAid(videoId: string | string[] | undefined) { if (!videoId) return null; const videoIdStr = Array.isArray(videoId) ? videoId[0] : videoId; if (videoIdStr?.startsWith("av")) { return parseInt(videoIdStr.slice(2)); } else if (videoIdStr?.startsWith("BV")) { return getAidFromBV(videoIdStr); } return parseInt(videoIdStr); } const aid = await getVideoAid(id); if (!aid) { return notFound(); } const exists = await idExists(aid); if (!exists) { return notFound(); } try { const videoData = await getVideoMetadata(aid); const snapshotsData = await getAllSnapshots(aid); videoInfo = videoData; if (snapshotsData) { snapshots = snapshotsData; } } catch (e) { console.error(e); } if (!videoInfo) { return notFound(); } return (

视频信息:{" "} av{videoInfo.aid}

基本信息

播放量历史数据

{snapshots && snapshots.length > 0 ? (
{snapshots.map((snapshot) => ( ))}
创建时间 观看 硬币 点赞 收藏 分享 弹幕 评论
{format(new Date(snapshot.created_at), "yyyy-MM-dd HH:mm:ss", { locale: zhCN })} {snapshot.views} {snapshot.coins} {snapshot.likes} {snapshot.favorites} {snapshot.shares} {snapshot.danmakus} {snapshot.replies}
) : (

暂无历史数据。

)}
); }