75ed8e233b
Add moderator/admin backend APIs and client features for managing novels and chapters. New endpoints include mod chapter routes (paginated list, single GET, PUT, DELETE, and bulk optimize), mod novel routes (create, GET by id, update, delete), genre CRUD, user bookmarks, novel comments, and rating endpoints. Update EPUB import to use a shared slugify util. Enhance moderator UI: chapter manager gains pagination, bulk optimization preview/apply, edit/delete dialogs; novel client adds genre management and edit/delete flows. Also update Prisma schema, add a DB wipe script, remove unused lib/data.ts, and adjust related types/utils and bookmark context.
48 lines
1.6 KiB
TypeScript
48 lines
1.6 KiB
TypeScript
import { NextResponse } from "next/server"
|
|
import { getServerSession } from "next-auth/next"
|
|
import { authOptions } from "@/lib/auth"
|
|
import { prisma } from "@/lib/prisma"
|
|
|
|
export async function POST(req: Request, { params }: { params: Promise<{ id: string }> }) {
|
|
try {
|
|
const session = await getServerSession(authOptions)
|
|
if (!session?.user?.id) {
|
|
return NextResponse.json({ error: "Unauthorized" }, { status: 401 })
|
|
}
|
|
|
|
const { id: novelId } = await params
|
|
const body = await req.json()
|
|
const { content, chapterId } = body
|
|
|
|
if (!content || typeof content !== "string") {
|
|
return NextResponse.json({ error: "Content is required" }, { status: 400 })
|
|
}
|
|
|
|
const newComment = await prisma.comment.create({
|
|
data: {
|
|
content: content.trim(),
|
|
userId: session.user.id,
|
|
novelId,
|
|
chapterId: chapterId || null
|
|
},
|
|
include: {
|
|
user: true
|
|
}
|
|
})
|
|
|
|
return NextResponse.json({
|
|
id: newComment.id,
|
|
userId: newComment.user.id,
|
|
username: newComment.user.name || "User",
|
|
avatarColor: newComment.user.image || "bg-primary",
|
|
novelId: newComment.novelId,
|
|
chapterId: newComment.chapterId,
|
|
content: newComment.content,
|
|
createdAt: newComment.createdAt.toISOString().split("T")[0]
|
|
})
|
|
} catch (error) {
|
|
console.error("POST Comment Error", error)
|
|
return NextResponse.json({ error: "Internal Server Error" }, { status: 500 })
|
|
}
|
|
}
|