douyin-archive/app/page.tsx
2025-10-20 13:06:06 +08:00

61 lines
1.9 KiB
TypeScript

import { prisma } from "@/lib/prisma";
import FeedMasonry from "./components/FeedMasonry";
import type { FeedItem } from "./types/feed";
export default async function Home() {
const [videos, posts] = await Promise.all([
prisma.video.findMany({
orderBy: { created_at: "desc" },
take: 60,
include: { author: true },
}),
prisma.imagePost.findMany({
orderBy: { created_at: "desc" },
take: 60,
include: { author: true, images: { orderBy: { order: "asc" }, take: 1 } },
}),
]);
const feed: FeedItem[] = [
...videos.map((v) => ({
type: "video" as const,
aweme_id: v.aweme_id,
created_at: v.created_at,
desc: v.desc,
video_url: v.video_url,
cover_url: v.cover_url ?? null,
width: v.width ?? null,
height: v.height ?? null,
author: { nickname: v.author.nickname, avatar_url: v.author.avatar_url ?? null },
likes: Number(v.digg_count)
})),
...posts.map((p) => ({
type: "image" as const,
aweme_id: p.aweme_id,
created_at: p.created_at,
desc: p.desc,
cover_url: p.images?.[0]?.url ?? null,
width: p.images?.[0]?.width ?? null,
height: p.images?.[0]?.height ?? null,
author: { nickname: p.author.nickname, avatar_url: p.author.avatar_url ?? null },
likes: Number(p.digg_count)
})),
]
//.sort(() => Math.random() - 0.5)
.sort((a, b) => +new Date(b.created_at) - +new Date(a.created_at));
return (
<main className="min-h-screen w-full px-4 py-8 md:py-12">
<h1 className="text-2xl md:text-3xl font-semibold tracking-tight mb-6">
</h1>
{(() => {
const initial = feed.slice(0, 24);
const cursor = initial.length > 0 ? new Date(initial[initial.length - 1].created_at as any).toISOString() : null;
return <FeedMasonry initialItems={initial} initialCursor={cursor} />;
})()}
</main>
);
}