diff --git a/src/files-ui/core/index.ts b/src/files-ui/core/index.ts index 8d276ea53da35f4a9e3ff85c1f9fe40d25f32083..0c918711726ce820aca4736f3bf15383de4348f8 100644 --- a/src/files-ui/core/index.ts +++ b/src/files-ui/core/index.ts @@ -118,7 +118,8 @@ export { addExtraData, addHeaders, sanitizeArrExtFile, - unexpectedErrorUploadResult + unexpectedErrorUploadResult, + setNextUploadStatus } from "./upload"; export { diff --git a/src/files-ui/core/upload/index.ts b/src/files-ui/core/upload/index.ts index 514079648c4726a5fbe13c5fc831139150f9e2bd..db4a27dee64f6f27f61da69ab6a2d38979525ab4 100644 --- a/src/files-ui/core/upload/index.ts +++ b/src/files-ui/core/upload/index.ts @@ -30,5 +30,6 @@ export { completeUploadResult, sanitizeArrExtFile, unableToUploadResult, - unexpectedErrorUploadResult + unexpectedErrorUploadResult, + setNextUploadStatus } from "./utils.upload"; diff --git a/src/files-ui/core/upload/utils.upload.ts b/src/files-ui/core/upload/utils.upload.ts index 2c07d1a37581b01825c94bbeaf386edd10bdc36d..121f7a5c9eba7dc98547f37b26a424315ac78256 100644 --- a/src/files-ui/core/upload/utils.upload.ts +++ b/src/files-ui/core/upload/utils.upload.ts @@ -116,21 +116,42 @@ export const sleepTransition = ( } export const sanitizeArrExtFile = (arrExtFile: ExtFileInstance[]): ExtFile[] => { - /* console.log("sanitizeArrExtFile", arrExtFile.length, arrExtFile.filter((extFileInstance: ExtFileInstance) => extFileInstance.extraData?.deleted) - .map((extFileInstance: ExtFileInstance) => extFileInstance.toExtFile()).length); - */ - return arrExtFile.filter((extFileInstance: ExtFileInstance) => !extFileInstance.extraData?.deleted) .map((extFileInstance: ExtFileInstance) => { - if (extFileInstance.uploadStatus === "aborted") { - if(!extFileInstance.uploadMessage){ - extFileInstance.uploadMessage="Upload aborted"; - } - extFileInstance.uploadStatus = "error"; + if (extFileInstance.uploadStatus === "aborted" + && !extFileInstance.uploadMessage) { + extFileInstance.uploadMessage = "Upload aborted by user"; + //extFileInstance.uploadStatus = "error"; } return extFileInstance.toExtFile() }); +} +/** + * + * @param extFileInstance + * @param extFileobj + */ +export const setNextUploadStatus = ( + extFileInstance: ExtFileInstance, + extFileobj: ExtFile) => { + + const prevStatus: UPLOADSTATUS | undefined = extFileInstance.uploadStatus; + const nextStstaus: UPLOADSTATUS | undefined = extFileobj.uploadStatus; + + if ( + prevStatus === "preparing" && + ["aborted", undefined].includes(nextStstaus) + ) { + extFileInstance.uploadStatus = undefined; + } else if ( + prevStatus === "uploading" && + ["aborted", undefined].includes(nextStstaus) + ) { + extFileInstance.uploadStatus = "aborted"; + + } + extFileInstance.uploadMessage = extFileobj.uploadMessage; } \ No newline at end of file