2024-09-10 06:16:41 +00:00
|
|
|
'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";
|
2025-01-28 18:39:59 +00:00
|
|
|
import { getCurrentUserOrg } from "@/auth";
|
2024-09-10 06:16:41 +00:00
|
|
|
|
|
|
|
|
export const POST = async (request: NextRequest) => {
|
2025-01-28 18:39:59 +00:00
|
|
|
const orgId = await getCurrentUserOrg();
|
|
|
|
|
if (isServiceError(orgId)) {
|
2025-01-30 18:23:47 +00:00
|
|
|
return serviceErrorResponse(orgId);
|
2025-01-28 18:39:59 +00:00
|
|
|
}
|
|
|
|
|
|
2024-09-10 06:16:41 +00:00
|
|
|
const body = await request.json();
|
|
|
|
|
const parsed = await fileSourceRequestSchema.safeParseAsync(body);
|
|
|
|
|
if (!parsed.success) {
|
|
|
|
|
return serviceErrorResponse(
|
|
|
|
|
schemaValidationError(parsed.error)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-28 18:39:59 +00:00
|
|
|
const response = await getFileSource(parsed.data, orgId);
|
2024-09-10 06:16:41 +00:00
|
|
|
if (isServiceError(response)) {
|
|
|
|
|
return serviceErrorResponse(response);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Response.json(response);
|
|
|
|
|
}
|