Disable worker because it looks not need with async requests
This commit is contained in:
parent
252fb1b4f1
commit
aa61eb1083
|
@ -66,7 +66,7 @@ type Props = {
|
||||||
* If true, the upload will run in a separate web worker.
|
* If true, the upload will run in a separate web worker.
|
||||||
* Default is !!window.Worker.
|
* Default is !!window.Worker.
|
||||||
*/
|
*/
|
||||||
useWorker?: boolean;
|
// useWorker?: boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply custom css variables.
|
* Apply custom css variables.
|
||||||
|
@ -106,7 +106,7 @@ export function Upload({
|
||||||
onDeleteItem,
|
onDeleteItem,
|
||||||
onSuccess,
|
onSuccess,
|
||||||
provider = defaultProvider,
|
provider = defaultProvider,
|
||||||
useWorker = !!window.Worker,
|
// useWorker = !!window.Worker,
|
||||||
}: Props) {
|
}: Props) {
|
||||||
const { deleteFile, files, uploadFiles, warning } = useUploadStategy(
|
const { deleteFile, files, uploadFiles, warning } = useUploadStategy(
|
||||||
multiple ? "multiple" : "single",
|
multiple ? "multiple" : "single",
|
||||||
|
@ -189,7 +189,7 @@ export function Upload({
|
||||||
id={id}
|
id={id}
|
||||||
onSuccess={onSuccess}
|
onSuccess={onSuccess}
|
||||||
provider={provider}
|
provider={provider}
|
||||||
useWorker={useWorker}
|
// useWorker={useWorker}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</>
|
</>
|
||||||
|
|
|
@ -30,7 +30,7 @@ type UploadFileProps = {
|
||||||
id: string;
|
id: string;
|
||||||
onSuccess: ((cid: string) => void) | undefined;
|
onSuccess: ((cid: string) => void) | undefined;
|
||||||
provider: () => Promise<CodexData["upload"]>;
|
provider: () => Promise<CodexData["upload"]>;
|
||||||
useWorker: boolean;
|
// useWorker: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
type State = {
|
type State = {
|
||||||
|
@ -128,7 +128,7 @@ export function UploadFile({
|
||||||
id,
|
id,
|
||||||
onSuccess,
|
onSuccess,
|
||||||
provider,
|
provider,
|
||||||
useWorker,
|
// useWorker,
|
||||||
}: UploadFileProps) {
|
}: UploadFileProps) {
|
||||||
const abort = useRef<(() => void) | null>(null);
|
const abort = useRef<(() => void) | null>(null);
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
@ -214,41 +214,42 @@ export function UploadFile({
|
||||||
reader.readAsDataURL(file);
|
reader.readAsDataURL(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (useWorker) {
|
|
||||||
worker.current = new Worker(new URL("./worker", import.meta.url), {
|
|
||||||
type: "module",
|
|
||||||
});
|
|
||||||
|
|
||||||
provider().then(() => {
|
|
||||||
worker.current?.postMessage({ type: "init", upload: "" });
|
|
||||||
});
|
|
||||||
|
|
||||||
worker.current.onmessage = function (e) {
|
|
||||||
const data = e.data;
|
|
||||||
|
|
||||||
if (e.data.type === "progress") {
|
|
||||||
onProgress(data.loaded, data.total);
|
|
||||||
} else if (e.data.type === "completed") {
|
|
||||||
onInternalSuccess(e.data.value.data);
|
|
||||||
} else if (e.data.error) {
|
|
||||||
// TODO report with sentry
|
|
||||||
dispatch({ type: "error", error: e.data.error });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
worker.current.onerror = function (e) {
|
|
||||||
// TODO report to sentry
|
|
||||||
console.error("Error in worker:", e);
|
|
||||||
dispatch({ type: "error", error: e.message });
|
|
||||||
worker.current?.terminate();
|
|
||||||
};
|
|
||||||
|
|
||||||
worker.current.postMessage({ type: "file", file });
|
|
||||||
} else {
|
|
||||||
console.info("running file !!");
|
|
||||||
mutateAsync(file);
|
mutateAsync(file);
|
||||||
}
|
|
||||||
}, [file, mutateAsync, onInternalSuccess, useWorker, provider]);
|
// if (useWorker) {
|
||||||
|
// worker.current = new Worker(new URL("./worker", import.meta.url), {
|
||||||
|
// type: "module",
|
||||||
|
// });
|
||||||
|
|
||||||
|
// provider().then(() => {
|
||||||
|
// worker.current?.postMessage({ type: "init", upload: "" });
|
||||||
|
// });
|
||||||
|
|
||||||
|
// worker.current.onmessage = function (e) {
|
||||||
|
// const data = e.data;
|
||||||
|
|
||||||
|
// if (e.data.type === "progress") {
|
||||||
|
// onProgress(data.loaded, data.total);
|
||||||
|
// } else if (e.data.type === "completed") {
|
||||||
|
// onInternalSuccess(e.data.value.data);
|
||||||
|
// } else if (e.data.error) {
|
||||||
|
// // TODO report with sentry
|
||||||
|
// dispatch({ type: "error", error: e.data.error });
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
|
||||||
|
// worker.current.onerror = function (e) {
|
||||||
|
// // TODO report to sentry
|
||||||
|
// console.error("Error in worker:", e);
|
||||||
|
// dispatch({ type: "error", error: e.message });
|
||||||
|
// worker.current?.terminate();
|
||||||
|
// };
|
||||||
|
|
||||||
|
// worker.current.postMessage({ type: "file", file });
|
||||||
|
// } else {
|
||||||
|
// mutateAsync(file);
|
||||||
|
// }
|
||||||
|
}, [file, mutateAsync, onInternalSuccess, provider]);
|
||||||
|
|
||||||
const onCancel = () => {
|
const onCancel = () => {
|
||||||
if (worker.current) {
|
if (worker.current) {
|
||||||
|
|
Loading…
Reference in New Issue