mirror of
https://github.com/sourcebot-dev/sourcebot.git
synced 2025-12-15 05:45:20 +00:00
35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
'use server';
|
|
|
|
import { fileSourceRequestSchema } from "@/lib/schemas";
|
|
import { getFileSource } from "@/lib/server/searchService";
|
|
import { schemaValidationError, serviceErrorResponse } from "@/lib/serviceError";
|
|
import { isServiceError } from "@/lib/utils";
|
|
import { NextRequest } from "next/server";
|
|
import { withAuth, withOrgMembership } from "@/actions";
|
|
import { FileSourceRequest } from "@/lib/types";
|
|
|
|
export const POST = async (request: NextRequest) => {
|
|
const body = await request.json();
|
|
const parsed = await fileSourceRequestSchema.safeParseAsync(body);
|
|
if (!parsed.success) {
|
|
return serviceErrorResponse(
|
|
schemaValidationError(parsed.error)
|
|
);
|
|
}
|
|
|
|
|
|
const response = await postSource(parsed.data, request.headers.get("X-Org-Domain")!);
|
|
if (isServiceError(response)) {
|
|
return serviceErrorResponse(response);
|
|
}
|
|
|
|
return Response.json(response);
|
|
}
|
|
|
|
|
|
const postSource = (request: FileSourceRequest, domain: string) =>
|
|
withAuth(async (session) =>
|
|
withOrgMembership(session, domain, async (orgId) => {
|
|
const response = await getFileSource(request, orgId);
|
|
return response;
|
|
}));
|