Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
+9
-35
@@ -10,6 +10,7 @@ import { type LoaderFunctionArgs, useLoaderData } from "react-router";
|
||||
import { buildFileUploadVM, type FileUploadVM } from "@hivegrid/view-models";
|
||||
import { getTranslations } from "~/locale/i18next.server";
|
||||
import { loadFilesContext, notFoundResponse, requireFilesPermission } from "~/utils/integrations/fileAccess.server";
|
||||
import { uploadFileInChunks, UploadFileClientError } from "~/utils/files/uploadFileClient";
|
||||
import { FileUploadPage, type FileUploadDisplayItem } from "~/components/screens/files/FileUploadPage";
|
||||
import ServerError from "~/components/ui/errors/ServerError";
|
||||
|
||||
@@ -32,7 +33,6 @@ type QueueItem = FileUploadDisplayItem;
|
||||
export default function FilesUploadRoute() {
|
||||
const { vm, tenantSlug } = useLoaderData<LoaderData>();
|
||||
const [items, setItems] = useState<QueueItem[]>([]);
|
||||
const chunkSize = vm.status === "ready" && vm.data ? vm.data.chunkSizeBytes : 5 * 1024 * 1024;
|
||||
|
||||
const update = useCallback((clientId: string, patch: Partial<QueueItem>) => {
|
||||
setItems((current) => current.map((item) => (item.clientId === clientId ? { ...item, ...patch } : item)));
|
||||
@@ -42,44 +42,18 @@ export default function FilesUploadRoute() {
|
||||
async (file: File, clientId: string) => {
|
||||
try {
|
||||
update(clientId, { status: "uploading", progressPercent: 0 });
|
||||
const initRes = await fetch(`/${tenantSlug}/files/upload/init`, {
|
||||
method: "POST",
|
||||
headers: { "content-type": "application/json" },
|
||||
body: JSON.stringify({ originalFilename: file.name, mimeType: file.type || "application/octet-stream", totalSizeBytes: file.size }),
|
||||
await uploadFileInChunks({
|
||||
tenantSlug,
|
||||
file,
|
||||
onProgress: (percent) => update(clientId, { progressPercent: percent }),
|
||||
onProcessing: () => update(clientId, { status: "processing" }),
|
||||
});
|
||||
if (!initRes.ok) {
|
||||
const body = (await initRes.json().catch(() => ({}))) as { error?: string };
|
||||
update(clientId, { status: "error", errorKey: body.error ?? "files.error.invalidUploadRequest" });
|
||||
return;
|
||||
}
|
||||
const { uploadId, totalChunks } = (await initRes.json()) as { uploadId: string; chunkSize: number; totalChunks: number };
|
||||
for (let index = 0; index < totalChunks; index += 1) {
|
||||
const slice = file.slice(index * chunkSize, (index + 1) * chunkSize);
|
||||
const chunkRes = await fetch(`/${tenantSlug}/files/upload/${uploadId}/chunk/${index}`, { method: "POST", body: slice });
|
||||
if (!chunkRes.ok) {
|
||||
const body = (await chunkRes.json().catch(() => ({}))) as { error?: string };
|
||||
update(clientId, { status: "error", errorKey: body.error ?? "files.error.uploadIncomplete" });
|
||||
return;
|
||||
}
|
||||
update(clientId, { progressPercent: Math.round(((index + 1) / totalChunks) * 100) });
|
||||
}
|
||||
update(clientId, { status: "processing" });
|
||||
const completeRes = await fetch(`/${tenantSlug}/files/upload/${uploadId}/complete`, {
|
||||
method: "POST",
|
||||
headers: { "content-type": "application/json" },
|
||||
body: JSON.stringify({}),
|
||||
});
|
||||
if (!completeRes.ok) {
|
||||
const body = (await completeRes.json().catch(() => ({}))) as { error?: string };
|
||||
update(clientId, { status: "error", errorKey: body.error ?? "files.error.uploadIncomplete" });
|
||||
return;
|
||||
}
|
||||
update(clientId, { status: "done", progressPercent: 100 });
|
||||
} catch {
|
||||
update(clientId, { status: "error", errorKey: "files.error.uploadIncomplete" });
|
||||
} catch (error) {
|
||||
update(clientId, { status: "error", errorKey: error instanceof UploadFileClientError ? error.errorKey : "files.error.uploadIncomplete" });
|
||||
}
|
||||
},
|
||||
[chunkSize, tenantSlug, update],
|
||||
[tenantSlug, update],
|
||||
);
|
||||
|
||||
const onFiles = useCallback(
|
||||
|
||||
Reference in new issue
Block a user