import { DateTime } from "luxon"; import { useParams } from "@solidjs/router"; import { createResource } from "solid-js"; import { Suspense } from "solid-js"; import { For } from "solid-js"; import { useCachedFetch } from "~/lib/dbCache"; import { dbMain } from "~/drizzle"; import { bilibiliMetadata, videoSnapshot } from "~db/main/schema"; import { desc, eq } from "drizzle-orm"; import { BilibiliMetadataType, VideoSnapshotType } from "~db/outerSchema"; import { Context, useRequestContext } from "~/components/requestContext"; import { Header } from "~/components/shell/Header"; async function getAllSnapshots(aid: number, context: Context) { "use server"; return useCachedFetch( async () => { return dbMain .select() .from(videoSnapshot) .where(eq(videoSnapshot.aid, aid)) .orderBy(desc(videoSnapshot.createdAt)); }, "all-snapshots", context, [aid] ); } async function getVideoMetadata(avORbv: number | string, context: Context) { "use server"; if (typeof avORbv === "number") { return useCachedFetch( async () => { return dbMain.select().from(bilibiliMetadata).where(eq(bilibiliMetadata.aid, avORbv)).limit(1); }, "bili-metadata", context, [avORbv] ); } else { return useCachedFetch( async () => { return dbMain.select().from(bilibiliMetadata).where(eq(bilibiliMetadata.bvid, avORbv)).limit(1); }, "bili-metadata", context, [avORbv] ); } } const MetadataRow = ({ title, desc }: { title: string; desc: string | number | undefined | null }) => { if (!desc) return <>; return ( {title} {desc} ); }; export default function VideoInfoPage() { const params = useParams(); const { id } = params; const context = useRequestContext(); const [data] = createResource(async () => { let videoInfo: BilibiliMetadataType | null = null; let snapshots: VideoSnapshotType[] = []; try { const videoData = await getVideoMetadata(id, context); if (videoData.length === 0) { return null; } const snapshotsData = await getAllSnapshots(videoData[0].aid, context); videoInfo = videoData[0]; if (snapshotsData) { snapshots = snapshotsData; } } catch (e) { console.error(e); } if (!videoInfo) { return null; } const title = `${videoInfo.title} - 歌曲信息 - 中 V 档案馆`; return { v: videoInfo, s: snapshots, t: title }; }); return ( <>
loading
}> {data()?.t} {data()?.t}

视频信息:{" "} av{data()?.v.aid}

基本信息

播放量历史数据

{(snapshot) => ( )}
创建时间 观看 硬币 点赞 收藏 分享 弹幕 评论
{DateTime.fromJSDate(new Date(snapshot.createdAt)).toFormat( "yyyy-MM-dd HH:mm:ss" )} {snapshot.views} {snapshot.coins} {snapshot.likes} {snapshot.favorites} {snapshot.shares} {snapshot.danmakus} {snapshot.replies}
); }