import { notFound } from "next/navigation"; import { prisma } from "@/lib/db"; import { PageReader } from "@/components/PageReader"; import { encodeId } from "@/lib/hashids"; import type { Metadata } from "next"; type Props = { params: Promise<{ slug: string; chapter: string }>; searchParams: Promise<{ resume?: string }>; }; export async function generateMetadata({ params, }: { params: Promise<{ slug: string; chapter: string }>; }): Promise { const { slug, chapter } = await params; const chapterNum = parseInt(chapter, 10); if (isNaN(chapterNum)) return { title: "Not Found" }; const manga = await prisma.manga.findUnique({ where: { slug } }); if (!manga) return { title: "Not Found" }; return { title: `${manga.title} — Ch. ${chapterNum}`, description: `Read chapter ${chapterNum} of ${manga.title}`, }; } export default async function ChapterReaderPage({ params, searchParams, }: Props) { const { slug, chapter } = await params; const { resume } = await searchParams; const chapterNum = parseInt(chapter, 10); if (isNaN(chapterNum)) notFound(); const [manga, initialChapterMeta] = await Promise.all([ prisma.manga.findUnique({ where: { slug }, include: { chapters: { orderBy: { number: "asc" }, include: { _count: { select: { pages: true } }, }, }, }, }), prisma.page.findMany({ where: { chapter: { number: chapterNum, manga: { slug } } }, orderBy: { number: "asc" }, select: { number: true, width: true, height: true }, }), ]); if (!manga) notFound(); const currentChapter = manga.chapters.find((c) => c.number === chapterNum); if (!currentChapter) notFound(); const allChapters = manga.chapters.map((c) => ({ id: encodeId(c.id), number: c.number, title: c.title, totalPages: c._count.pages, })); return ( ); }