disclosure-bureau/web/app/api/entities/[cls]/[id]/route.ts

16 lines
640 B
TypeScript

import { NextResponse } from "next/server";
import { readEntity, classKeyToFolder, type EntityClass } from "@/lib/wiki";
export async function GET(_req: Request, ctx: { params: Promise<{ cls: string; id: string }> }) {
const { cls, id } = await ctx.params;
const folder = classKeyToFolder(cls);
if (!folder) return NextResponse.json({ error: "invalid_class" }, { status: 400 });
const md = await readEntity(folder as EntityClass, id);
if (!md) return NextResponse.json({ error: "not_found" }, { status: 404 });
return NextResponse.json({
entity_id: id,
class: folder,
frontmatter: md.fm,
body: md.body,
});
}