feat(upload-utilities):

- add function to retry all the failed uploads

- add function to clear the queue's cache
This commit is contained in:
Aminejv 2021-10-08 17:37:57 +01:00
parent 4703961ba7
commit 9a9221dfee

View File

@ -31,6 +31,7 @@ const storeFileInCache = ({ file, slate }) =>
(UploadStore.failedFilesCache[getFileKey(file)] = { file, slate });
const removeFileFromCache = ({ fileKey }) => delete UploadStore.failedFilesCache[fileKey];
const getFileFromCache = ({ fileKey }) => UploadStore.failedFilesCache[fileKey] || {};
const getFailedFilesCache = () => UploadStore.failedFilesCache;
// NOTE(amine): UploadAbort utilities
const registerFileUploading = ({ fileKey }) => (UploadAbort.currentUploadingFile = fileKey);
@ -163,6 +164,13 @@ export function createUploadProvider({
addToUploadQueue({ files: [file], slate });
};
const retryAll = () => {
const failedFilesCache = getFailedFilesCache();
Object.entries(failedFilesCache).forEach(([key]) => {
retry({ fileKey: key });
});
};
const cancel = ({ fileKey }) => {
if (onCancel) onCancel({ fileKeys: [fileKey] });
@ -212,11 +220,18 @@ export function createUploadProvider({
}
};
const clearUploadCache = () => {
UploadStore.failedFilesCache = {};
UploadStore.uploadedFiles = {};
};
return {
upload: addToUploadQueue,
uploadLink: addLinkToUploadQueue,
retry,
retryAll,
cancel,
cancelAll,
clearUploadCache,
};
}