Skip to content

Commit

Permalink
fix: [BUG] File uploaded twice in documents application - EXO-74631
Browse files Browse the repository at this point in the history
Prior to this fix,In some cases documents may be uploaded twice in deifferent locations using the drag and drop, this commit avoid that by insuring that the good file will be uploaded in the good location.
  • Loading branch information
mkrout committed Oct 16, 2024
1 parent 055d455 commit a3ffa56
Showing 1 changed file with 51 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export default {
}.bind(this));
document.addEventListener('dragover', function () {
this.$refs.dropFileBox.classList.add('dragStart');
this.$refs.dropFileBox?.classList.add('dragStart');
}.bind(this));
/*
Expand All @@ -144,11 +144,11 @@ export default {
}.bind(this));
document.addEventListener('dragleave', function () {
this.$refs.dropFileBox.classList.remove('dragStart');
this.$refs.dropFileBox?.classList.remove('dragStart');
}.bind(this));
document.addEventListener('drop', function () {
this.$refs.dropFileBox.classList.remove('dragStart');
this.$refs.dropFileBox?.classList.remove('dragStart');
}.bind(this));
window.require(['SHARED/jquery'], function ($) {
Expand All @@ -162,60 +162,63 @@ export default {
this.$refs.uploadInput.click();
},
handleFileUpload: function (files) {
this.abortUploading = false;
const newFilesArray = Array.from(files);
if (this.$refs.uploadInput){
this.abortUploading = false;
const newFilesArray = Array.from(files);
newFilesArray.sort(function (file1, file2) {
return file1.size - file2.size;
});
this.newUploadedFiles = [];
const newAttachedFiles = [];
newFilesArray.forEach(file => {
const controller = new AbortController();
const signal = controller.signal;
newAttachedFiles.push({
originalFileObject: file,
fileDrive: this.currentDrive,
title: file.name,
size: file.size,
mimetype: file.type,
acl: file.acl,
uploadId: this.getNewUploadId(),
uploadProgress: 0,
destinationFolder: this.pathDestinationFolder,
pathDestinationFolderForFile: '',
isPublic: true,
signal: signal
newFilesArray.sort(function (file1, file2) {
return file1.size - file2.size;
});
});
const existingAttachedFiles = newAttachedFiles.filter(file => this.attachments.some(f => f.title === file.title));
if (existingAttachedFiles.length > 0) {
const existingFiles = existingAttachedFiles.length === 1 ? existingAttachedFiles.map(file => file.title) : existingAttachedFiles.length;
let sameFileErrorMessage = existingAttachedFiles.length === 1 ? this.$t('attachments.drawer.sameFile.error') : this.$t('attachments.drawer.sameFiles.error');
sameFileErrorMessage = sameFileErrorMessage.replace('{0}', `<b> ${existingFiles} </b>`);
document.dispatchEvent(new CustomEvent('alert-message', {detail: {
useHtml: true,
alertType: 'error',
alertMessage: sameFileErrorMessage,
}}));
}
this.newUploadedFiles = [];
const newAttachedFiles = [];
newFilesArray.forEach(file => {
const controller = new AbortController();
const signal = controller.signal;
newAttachedFiles.push({
originalFileObject: file,
fileDrive: this.currentDrive,
title: file.name,
size: file.size,
mimetype: file.type,
acl: file.acl,
uploadId: this.getNewUploadId(),
uploadProgress: 0,
destinationFolder: this.pathDestinationFolder,
pathDestinationFolderForFile: '',
isPublic: true,
signal: signal
});
});
newAttachedFiles.filter(file => !this.attachments.some(f => f.title === file.title)).every((newFile, index) => {
if (index === this.maxFilesCount || this.maxFilesCount === 0 || this.uploadedFilesCount >= this.maxFilesCount) {
const existingAttachedFiles = newAttachedFiles.filter(file => this.attachments.some(f => f.title === file.title));
if (existingAttachedFiles.length > 0) {
const existingFiles = existingAttachedFiles.length === 1 ? existingAttachedFiles.map(file => file.title) : existingAttachedFiles.length;
let sameFileErrorMessage = existingAttachedFiles.length === 1 ? this.$t('attachments.drawer.sameFile.error') : this.$t('attachments.drawer.sameFiles.error');
sameFileErrorMessage = sameFileErrorMessage.replace('{0}', `<b> ${existingFiles} </b>`);
document.dispatchEvent(new CustomEvent('alert-message', {detail: {
useHtml: true,
alertType: 'error',
alertMessage: this.maxFileCountErrorLabel,
alertMessage: sameFileErrorMessage,
}}));
return false;
} else {
this.queueUpload(newFile);
return true;
}
});
this.$refs.uploadInput.value = null;
newAttachedFiles.filter(file => !this.attachments.some(f => f.title === file.title)).every((newFile, index) => {
if (index === this.maxFilesCount || this.maxFilesCount === 0 || this.uploadedFilesCount >= this.maxFilesCount) {
document.dispatchEvent(new CustomEvent('alert-message', {detail: {
useHtml: true,
alertType: 'error',
alertMessage: this.maxFileCountErrorLabel,
}}));
return false;
} else {
this.queueUpload(newFile);
return true;
}
});
this.$refs.uploadInput.value = null;
}
},
queueUpload: function (file) {
const fileSizeInMb = file.size / this.BYTES_IN_MB;
Expand Down

0 comments on commit a3ffa56

Please sign in to comment.