lastwebnovel-app/server/api/chapters/[novelId]/[chapterId].ts
2026-04-11 22:55:16 +02:00

19 lines
519 B
TypeScript

import type { Chapter } from '~/types'
export default defineEventHandler(async (event): Promise<Chapter | null> => {
const novelId = getRouterParam(event, 'novelId')
const chapterId = getRouterParam(event, 'chapterId')
const chapters = await queryCollection('content').all() as Chapter[]
const chapter = chapters.find(c => c._path === `/novels/${novelId}/${chapterId}`)
if (!chapter) {
throw createError({
statusCode: 404,
statusMessage: 'Chapter not found'
})
}
return chapter
})