MCPcopy Create free account
hub / github.com/code100x/daily-code / POST

Function POST

apps/web/app/api/AddTracks/route.ts:6–33  ·  view source on GitHub ↗
(req: NextRequest)

Source from the content-addressed store, hash-verified

4import { authOptions } from "../../../lib/auth";
5
6export async function POST(req: NextRequest) {
7 const session = await getServerSession(authOptions);
8
9 if (!session?.user?.admin) {
10 return NextResponse.json({ message: "Unauthorized" }, { status: 401 });
11 }
12 const body = await req.json();
13 const notionId = body.notionId;
14 const notion = getNotionClient();
15 try {
16 const recordMap = await fetchNotionPage(notion, notionId);
17 if (!recordMap?.block) {
18 return NextResponse.json({ message: "Failed to load Notion page" }, { status: 502 });
19 }
20 const data = Object.keys(recordMap.block).filter((key) => {
21 const block = recordMap.block[key];
22 return block?.role !== "none"
23 }).map((key) => {
24 const block = recordMap.block[key];
25 return {
26 notionDocId: block?.value.id,
27 title: block?.value?.properties?.title[0][0],
28 };
29 });
30 data.shift();
31 data.pop();
32 return NextResponse.json(data);
33 } catch (e) {
34 return NextResponse.json(e);
35 }
36}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected