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";
const MetadataRow = ({ title, desc }: { title: string; desc: string | number | undefined | null }) => {
if (!desc) return <>>;
return (
{title}
|
{desc} |
);
};
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 (
播放量历史数据
{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}
|
))}
) : (
暂无历史数据。
)}
);
}