Initial reader-api backend extracted from reader

This commit is contained in:
2026-03-24 13:55:10 +07:00
parent 56f8f5ccfc
commit 24f070d14e
69 changed files with 12167 additions and 1 deletions
+45
View File
@@ -0,0 +1,45 @@
import { NextResponse } from "next/server"
import { getServerSession } from "next-auth/next"
import { authOptions } from "@/lib/auth"
import { prisma } from "@/lib/prisma"
export async function GET(
req: Request,
context: { params: Promise<{ id: string }> }
) {
const { id } = await context.params
const session = await getServerSession(authOptions)
if (!session || (session.user.role !== "MOD" && session.user.role !== "ADMIN")) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 })
}
try {
const novel = await prisma.novel.findFirst({
where: session.user.role === "ADMIN"
? { id }
: {
id,
OR: [
{ uploaderId: session.user.id },
{ uploaderId: null },
],
},
include: {
series: true,
genres: {
include: {
genre: true
}
}
}
})
if (!novel) {
return NextResponse.json({ error: "Novel not found" }, { status: 404 })
}
return NextResponse.json(novel)
} catch (error) {
return NextResponse.json({ error: "Failed to fetch novel details" }, { status: 500 })
}
}