Track HiveGrid Cloud planning reference
This commit is contained in:
1 parent
b3d5ea6764
commit
e341c5938a
5784 files changed
+1104929
-3
No files matched your search
+40
@@ -0,0 +1,40 @@
|
||||
// P4 Files (AK-P4a) §3 — chunked-upload chunk endpoint (resource route, action
|
||||
// only). The browser uploader PUTs/POSTs raw chunk bytes; we store them as a
|
||||
// temp object and track the FileUploadChunk. Gated: auth -> module -> files.write.
|
||||
|
||||
import type { ActionFunctionArgs } from "react-router";
|
||||
import { fileActionErrorResponse, loadFilesContext, requireFilesPermission } from "~/utils/integrations/fileAccess.server";
|
||||
import { FILE_UPLOAD_CHUNK_SIZE_BYTES } from "@toolctrl/view-models";
|
||||
import { storeUploadChunk } from "~/utils/integrations/fileService.server";
|
||||
|
||||
export const action = async ({ request, params }: ActionFunctionArgs) => {
|
||||
try {
|
||||
if (request.method !== "POST" && request.method !== "PUT") {
|
||||
return new Response("Method Not Allowed", { status: 405 });
|
||||
}
|
||||
const ctx = requireFilesPermission(await loadFilesContext({ request, params, requireModule: true }), "files.write");
|
||||
const uploadId = params.uploadId ?? "";
|
||||
const chunkIndex = Number.parseInt(params.index ?? "", 10);
|
||||
if (!uploadId || !Number.isInteger(chunkIndex)) {
|
||||
return Response.json({ error: "files.error.invalidUploadRequest" }, { status: 400 });
|
||||
}
|
||||
const bytes = new Uint8Array(await request.arrayBuffer());
|
||||
if (bytes.byteLength === 0) {
|
||||
return Response.json({ error: "files.error.emptyChunk" }, { status: 400 });
|
||||
}
|
||||
// Defensive upper bound so a malformed client cannot stream an oversized part.
|
||||
if (bytes.byteLength > FILE_UPLOAD_CHUNK_SIZE_BYTES) {
|
||||
return Response.json({ error: "files.error.chunkTooLarge" }, { status: 400 });
|
||||
}
|
||||
const result = await storeUploadChunk({
|
||||
tenantId: ctx.tenantId,
|
||||
userId: ctx.userId,
|
||||
uploadId,
|
||||
chunkIndex,
|
||||
bytes,
|
||||
});
|
||||
return Response.json(result);
|
||||
} catch (error) {
|
||||
return fileActionErrorResponse(error);
|
||||
}
|
||||
};
|
||||
Reference in new issue
Block a user