From 1ff5f205b2c4829a571021139fa7e3abf48518cb Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Mon, 18 Mar 2024 18:51:41 -0400 Subject: [PATCH] feat: add callback and emit to track hashing progress --- app/components/lib/uppy.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/app/components/lib/uppy.ts b/app/components/lib/uppy.ts index 9a433ce..bda8c9a 100644 --- a/app/components/lib/uppy.ts +++ b/app/components/lib/uppy.ts @@ -8,7 +8,7 @@ import DropTarget, {type DropTargetOptions} from "./uppy-dropzone" import {useSdk} from "~/components/lib/sdk-context.js"; import UppyFileUpload from "~/components/lib/uppy-file-upload.js"; import {PROTOCOL_S5, Sdk} from "@lumeweb/portal-sdk"; -import {S5Client} from "@lumeweb/s5-js"; +import {S5Client, HashProgressEvent} from "@lumeweb/s5-js"; const LISTENING_EVENTS = [ "upload", @@ -98,7 +98,18 @@ export function useUppy({ const file = uppyInstance.current?.getFile(fileID) as UppyFile // @ts-ignore if (file.uploader === "tus") { - const options = await sdk.protocols!().get(PROTOCOL_S5).getSdk().getTusOptions(file.data as File) + const hashProgressCb = (event: HashProgressEvent) => { + uppyInstance.current?.emit("preprocess-progress", file, { + uploadStarted: false, + bytesUploaded: 0, + preprocess: { + mode: "determinate", + message: "Hashing file...", + value: Math.round((event.total / event.total) * 100) + } + }) + } + const options = await sdk.protocols!().get(PROTOCOL_S5).getSdk().getTusOptions(file.data as File, {}, {onHashProgress: hashProgressCb}) uppyInstance.current?.setFileState(fileID, { tus: options, meta: {