Files
soul-yongping/app/api/book/stats/route.ts

27 lines
636 B
TypeScript

/**
* 书籍统计 API - 供关于页等展示章节数量
* GET /api/book/stats -> { success, data: { totalChapters } }
*/
import { NextResponse } from 'next/server'
import { prisma } from '@/lib/prisma'
export async function GET() {
try {
const totalChapters = await prisma.chapters.count({
where: { status: 'published' }
})
return NextResponse.json({
success: true,
data: {
totalChapters,
},
})
} catch (e) {
console.warn('[Book Stats] 查询失败:', (e as Error).message)
return NextResponse.json({
success: true,
data: { totalChapters: 0 },
})
}
}