diff --git a/changelog.md b/changelog.md index d9cd8441..af5ffc91 100644 --- a/changelog.md +++ b/changelog.md @@ -6,6 +6,7 @@ - Fixed issue when you perform composer update with private repository - Fixed issue where change in sorting option will duplicate the content in file view - Fixed issue where Dragged & Dropped folder from desktop didn't start uploading +- Fixed issue when you upload empty .txt file, it stops the upload process ## Version 2.2.0.6 #### Release date: 13. Jun 2022 diff --git a/resources/js/helpers/functionHelpers.js b/resources/js/helpers/functionHelpers.js index c5fb7a1d..66c00d2d 100644 --- a/resources/js/helpers/functionHelpers.js +++ b/resources/js/helpers/functionHelpers.js @@ -178,24 +178,22 @@ const FunctionHelpers = { return } - if (files.length === 0) return + if (files.length === 0) { + return + } - if (!this.$checkFileMimetype(files) || !this.$checkUploadLimit(files)) return // Push items to file queue - ;[...files].map((item) => { - store.commit('ADD_FILES_TO_QUEUE', { + if (!this.$checkFileMimetype(files) || !this.$checkUploadLimit(files)) { + return + } + + // Push items to file queue + [...files].map((item) => { + store.dispatch('pushFileToTheUploadQueue', { parent_id: store.getters.currentFolder ? store.getters.currentFolder.data.id : '', file: item, path: '/' + item.webkitRelativePath, }) }) - - // Start uploading if uploading process isn't running - if (store.getters.filesInQueueTotal === 0) { - this.$handleUploading(store.getters.fileQueue[0]) - } - - // Increase total files in upload bar - store.commit('INCREASE_FILES_IN_QUEUES_TOTAL', files.length) } Vue.prototype.$uploadDraggedFolderOrFile = async function (files, parent_id) { @@ -209,46 +207,12 @@ const FunctionHelpers = { } // Push file to the upload queue - if (file.name !== '.DS_Store') { - store.commit('ADD_FILES_TO_QUEUE', { - parent_id: parent_id || '', - path: filePath, - file: file, - }) - } - }) - - // Start uploading if uploading process isn't running - if (store.getters.filesInQueueTotal === 0) { - this.$handleUploading(store.getters.fileQueue[0]) - } - - // Increase total files in upload bar - store.commit('INCREASE_FILES_IN_QUEUES_TOTAL', files.length) - } - - Vue.prototype.$uploadDraggedFiles = async function (event, parent_id) { - // Show alert message when upload is disabled - if (store.getters.user && !store.getters.user.data.meta.restrictions.canUpload) { - Vue.prototype.$temporarilyDisabledUpload() - - return - } - - // Prevent submit empty files - if (event.dataTransfer.items.length === 0) return // Push items to file queue - ;[...event.dataTransfer.items].map((item) => { - store.commit('ADD_FILES_TO_QUEUE', { + store.dispatch('pushFileToTheUploadQueue', { parent_id: parent_id || '', - file: item.getAsFile(), + path: filePath, + file: file, }) }) - - // Start uploading if uploading process isn't running - if (store.getters.filesInQueueTotal == 0) this.$handleUploading(store.getters.fileQueue[0]) - - // Increase total files in upload bar - store.commit('INCREASE_FILES_IN_QUEUES_TOTAL', [...event.dataTransfer.items].length) } Vue.prototype.$handleUploading = async function (item) { diff --git a/resources/js/store/modules/fileFunctions.js b/resources/js/store/modules/fileFunctions.js index 5261ad11..249e4dce 100644 --- a/resources/js/store/modules/fileFunctions.js +++ b/resources/js/store/modules/fileFunctions.js @@ -375,6 +375,28 @@ const actions = { }) .catch(() => Vue.prototype.$isSomethingWrong()) }, + pushFileToTheUploadQueue: ({commit, getters}, item) => { + // Prevent to upload file with 0kb file size + if (item.file.size === 0) { + events.$emit('toaster', { + type: 'danger', + message: `The file ${item.file.name} can't be uploaded`, + }) + } + + if (item.file.size !== 0 && item.file.name !== '.DS_Store') { + // commit file to the upload queue + commit('ADD_FILES_TO_QUEUE', item) + + // Start uploading if uploading process isn't running + if (getters.filesInQueueTotal === 0) { + Vue.prototype.$handleUploading(getters.fileQueue[0]) + } + + // Increase total files in upload bar + commit('INCREASE_FILES_IN_QUEUES_TOTAL') + } + } } const mutations = { @@ -396,8 +418,8 @@ const mutations = { UPLOADING_FILE_PROGRESS(state, percentage) { state.uploadingProgress = percentage }, - INCREASE_FILES_IN_QUEUES_TOTAL(state, count) { - state.filesInQueueTotal += count + INCREASE_FILES_IN_QUEUES_TOTAL(state) { + state.filesInQueueTotal += 1 }, INCREASE_FILES_IN_QUEUE_UPLOADED(state) { state.filesInQueueUploaded++