import { NextRequest } from 'next/server' import { prisma } from '../../../../lib/prisma' export async function GET( req: NextRequest, context: { params: Promise<{ id: string }> } ) { // 优先从动态路由 params(Promise)获取,其次从 URL 最后一段兜底 let id: string | undefined try { const { id: idFromParams } = await context.params id = idFromParams } catch { // ignore } if (!id) { id = new URL(req.url).pathname.split('/').pop() || undefined } if (!id) { return Response.json({ error: 'missing id' }, { status: 400 }) } const report = await prisma.report.findUnique({ where: { id } }) if (!report) { return Response.json({ error: 'not found' }, { status: 404 }) } return Response.json(report) }