From 9d9e91453341f7abfa4c6407d7f1c112ef2e2e93 Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Wed, 8 Dec 2021 19:35:35 +0100 Subject: [PATCH] fix: add file extension filter to drag&drop fileupload in gcode files Signed-off-by: Stefan Dej --- src/components/panels/GcodefilesPanel.vue | 16 ++++++++++++++-- src/locales/en.json | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/components/panels/GcodefilesPanel.vue b/src/components/panels/GcodefilesPanel.vue index 2e119073..f5ed4d78 100644 --- a/src/components/panels/GcodefilesPanel.vue +++ b/src/components/panels/GcodefilesPanel.vue @@ -727,11 +727,23 @@ export default class GcodefilesPanel extends Mixins(BaseMixin) { this.dropzone.opacity = 0 if (e.dataTransfer.files.length) { + const files = [...e.dataTransfer.files].filter((file: File) => { + const format = file.name.slice(file.name.lastIndexOf('.')) + + if (!validGcodeExtensions.includes(format)) { + this.$toast.error(this.$t('Files.WrongFileUploaded', { filename: file.name }).toString()) + + return false + } + + return true + }) + this.$store.dispatch('socket/addLoading', { name: 'gcodeUpload' }) let successFiles = [] this.uploadSnackbar.number = 0 - this.uploadSnackbar.max = e.dataTransfer.files.length - for (const file of e.dataTransfer.files) { + this.uploadSnackbar.max = files.length + for (const file of files) { this.uploadSnackbar.number++ const result = await this.doUploadFile(file) successFiles.push(result) diff --git a/src/locales/en.json b/src/locales/en.json index e88c12d6..26706268 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -161,6 +161,7 @@ "PrintTime": "Print Time", "Slicer": "Slicer", "Downloading": "Downloading", + "WrongFileUploaded": "Upload was denied for {filename}. Wrong file format!", "SuccessfullyUploaded": "Upload of {filename} successful!", "SuccessfullyRenamed": "Successfully renamed {filename}.", "SuccessfullyMoved": "Successfully moved {filename}.",