feat: implement abort upload functionality (#2673)

This commit is contained in:
M A E R Y O authored and GitHub committed 2023-08-27 23:59:49 +02:00
1 parent 95fec7f694
commit a404fb043d
5 files changed
+55 -6

No files matched your search

+22
View File
@@ -6,6 +6,7 @@ import { fetchURL } from "./utils";
const RETRY_BASE_DELAY = 1000;
const RETRY_MAX_DELAY = 20000;
const CURRENT_UPLOAD_LIST = {};
export async function upload(
filePath,
@@ -34,6 +35,7 @@ export async function upload(
"X-Auth": store.state.jwt,
},
onError: function (error) {
delete CURRENT_UPLOAD_LIST[filePath];
reject("Upload failed: " + error);
},
onProgress: function (bytesUploaded) {
@@ -44,10 +46,12 @@ export async function upload(
}
},
onSuccess: function () {
delete CURRENT_UPLOAD_LIST[filePath];
resolve();
},
});
upload.start();
CURRENT_UPLOAD_LIST[filePath] = upload;
});
}
@@ -88,3 +92,21 @@ export async function useTus(content) {
function isTusSupported() {
return tus.isSupported === true;
}
export function abortUpload(filePath) {
const upload = CURRENT_UPLOAD_LIST[filePath];
if (upload) {
upload.abort();
delete CURRENT_UPLOAD_LIST[filePath];
}
}
export function abortAllUploads() {
for (let filePath in CURRENT_UPLOAD_LIST) {
const upload = CURRENT_UPLOAD_LIST[filePath];
if (upload) {
upload.abort();
delete CURRENT_UPLOAD_LIST[filePath];
}
}
}