From 9a9221dfee8413452f27aedcc0195dbc8303a75c Mon Sep 17 00:00:00 2001 From: Aminejv Date: Fri, 8 Oct 2021 17:37:57 +0100 Subject: [PATCH] feat(upload-utilities): - add function to retry all the failed uploads - add function to clear the queue's cache --- common/upload-utilities.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/common/upload-utilities.js b/common/upload-utilities.js index d0d641f0..2075f57e 100644 --- a/common/upload-utilities.js +++ b/common/upload-utilities.js @@ -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, }; }