31 lines
1.4 KiB
TypeScript
31 lines
1.4 KiB
TypeScript
import { CHAT_PERMISSIONS } from "@hivegrid/chat";
|
|
import type { LoaderFunctionArgs } from "react-router";
|
|
|
|
import { loadChatContext, requireChatPermission } from "~/modules/chat/routes/chatAccess.server";
|
|
import { loadFilesContext, requireFilesPermission } from "~/utils/integrations/fileAccess.server";
|
|
import { getOwnedFileScanStatus } from "~/utils/integrations/fileService.server";
|
|
|
|
type LoaderData = { readonly scanStatus: "pending" | "clean" | "infected" | "skipped" };
|
|
|
|
/** Owner-only, tenant/RLS-bound status endpoint used by the chat composer after
|
|
* the chunk upload finishes. It intentionally exposes no file metadata. */
|
|
export async function loader({ request, params }: LoaderFunctionArgs): Promise<Response> {
|
|
const [chatContext, filesContext] = await Promise.all([
|
|
loadChatContext({ request, params }),
|
|
loadFilesContext({ request, params, requireModule: true }),
|
|
]);
|
|
requireChatPermission(chatContext, CHAT_PERMISSIONS.write);
|
|
requireFilesPermission(filesContext, "files.write");
|
|
if (chatContext.tenantId !== filesContext.tenantId || chatContext.userId !== filesContext.userId) {
|
|
return new Response(null, { status: 404 });
|
|
}
|
|
const scanStatus = await getOwnedFileScanStatus({
|
|
tenantId: chatContext.tenantId,
|
|
userId: chatContext.userId,
|
|
fileId: params.fileId ?? "",
|
|
});
|
|
return Response.json({ scanStatus } satisfies LoaderData, {
|
|
headers: { "cache-control": "private, no-store" },
|
|
});
|
|
}
|