sunnymh/app/api/manga/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

42 lines
963 B
TypeScript

import { prisma } from "@/lib/db";
import { signCoverUrls } from "@/lib/r2";
import { NextRequest } from "next/server";
export async function GET() {
const manga = await prisma.manga.findMany({
orderBy: { updatedAt: "desc" },
include: {
_count: { select: { chapters: true } },
},
});
const signedManga = await signCoverUrls(manga);
return Response.json(signedManga);
}
export async function POST(request: NextRequest) {
const body = await request.json();
const { title, description, coverUrl, slug, status } = body;
if (!title || !description || !coverUrl || !slug) {
return Response.json(
{ error: "Missing required fields: title, description, coverUrl, slug" },
{ status: 400 }
);
}
const manga = await prisma.manga.create({
data: {
title,
description,
coverUrl,
slug,
status: status || "PUBLISHED",
},
});
return Response.json(manga, { status: 201 });
}