feat: add onHashProgress
This commit is contained in:
parent
a9cd7c54a9
commit
268df87b63
|
@ -1,4 +1,4 @@
|
||||||
import { AxiosProgressEvent } from "axios";
|
import {AxiosProgressEvent} from "axios";
|
||||||
import {
|
import {
|
||||||
DetailedError,
|
DetailedError,
|
||||||
HttpRequest,
|
HttpRequest,
|
||||||
|
@ -43,6 +43,11 @@ const PORTAL_FILE_FIELD_NAME = "file";
|
||||||
|
|
||||||
const TUS_ENDPOINT = "/s5/upload/tus";
|
const TUS_ENDPOINT = "/s5/upload/tus";
|
||||||
|
|
||||||
|
export interface HashProgressEvent {
|
||||||
|
bytes: number;
|
||||||
|
total: number;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Custom upload options.
|
* Custom upload options.
|
||||||
*
|
*
|
||||||
|
@ -59,6 +64,7 @@ export type CustomUploadOptions = BaseCustomOptions & {
|
||||||
largeFileSize?: number;
|
largeFileSize?: number;
|
||||||
retryDelays?: number[];
|
retryDelays?: number[];
|
||||||
onUploadProgress?: (progressEvent: AxiosProgressEvent) => void;
|
onUploadProgress?: (progressEvent: AxiosProgressEvent) => void;
|
||||||
|
onHashProgress?: (progressEvent: HashProgressEvent) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const DEFAULT_UPLOAD_OPTIONS = {
|
export const DEFAULT_UPLOAD_OPTIONS = {
|
||||||
|
@ -238,6 +244,10 @@ export async function getTusOptions(
|
||||||
const chunk = file.slice(position, position + chunkSize);
|
const chunk = file.slice(position, position + chunkSize);
|
||||||
hasher.update(new Uint8Array(await chunk.arrayBuffer()));
|
hasher.update(new Uint8Array(await chunk.arrayBuffer()));
|
||||||
position += chunkSize;
|
position += chunkSize;
|
||||||
|
customOptions.onHashProgress?.({
|
||||||
|
bytes: position,
|
||||||
|
total: file.size,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const b3hash = hasher.digest();
|
const b3hash = hasher.digest();
|
||||||
|
|
Loading…
Reference in New Issue