mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-18 08:12:15 +00:00
Fixed issue when you upload empty .txt file, it stops the upload process
This commit is contained in:
62
resources/js/helpers/functionHelpers.js
vendored
62
resources/js/helpers/functionHelpers.js
vendored
@@ -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) {
|
||||
|
||||
26
resources/js/store/modules/fileFunctions.js
vendored
26
resources/js/store/modules/fileFunctions.js
vendored
@@ -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++
|
||||
|
||||
Reference in New Issue
Block a user