sunnymh/app/api/search/route.ts
yiekheng 4f5d74e1c8 Squashed 'manga-site/' content from commit f2ef775
git-subtree-dir: manga-site
git-subtree-split: f2ef775f7095dc2b107b576cd4053593e89dd887
2026-04-12 18:47:51 +08:00

29 lines
629 B
TypeScript

import { prisma } from "@/lib/db";
import { signCoverUrls } from "@/lib/r2";
export async function GET(request: Request) {
const { searchParams } = new URL(request.url);
const q = searchParams.get("q")?.trim();
if (!q || q.length < 2) {
return Response.json([]);
}
const results = await prisma.manga.findMany({
where: {
status: "PUBLISHED",
title: { contains: q, mode: "insensitive" },
},
select: {
id: true,
title: true,
slug: true,
coverUrl: true,
},
take: 8,
orderBy: { title: "asc" },
});
return Response.json(await signCoverUrls(results));
}