-
Notifications
You must be signed in to change notification settings - Fork 264
Expand file tree
/
Copy pathroute.ts
More file actions
23 lines (18 loc) · 791 Bytes
/
route.ts
File metadata and controls
23 lines (18 loc) · 791 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
'use server';
import { getFolderContents } from "@/features/fileTree/api";
import { getFolderContentsRequestSchema } from "@/features/fileTree/types";
import { schemaValidationError, serviceErrorResponse } from "@/lib/serviceError";
import { isServiceError } from "@/lib/utils";
import { NextRequest } from "next/server";
export const POST = async (request: NextRequest) => {
const body = await request.json();
const parsed = await getFolderContentsRequestSchema.safeParseAsync(body);
if (!parsed.success) {
return serviceErrorResponse(schemaValidationError(parsed.error));
}
const response = await getFolderContents(parsed.data);
if (isServiceError(response)) {
return serviceErrorResponse(response);
}
return Response.json(response);
}