From 8660cf8ef88e567c7454659a59af79d0c05f5fbd Mon Sep 17 00:00:00 2001 From: siparker Date: Mon, 20 Mar 2023 15:43:20 +0000 Subject: [PATCH 1/5] Update GcodefilesPanel.vue Added Scan Metadata option in the gcode file right click menu to call the Metascan Moonraker endpoint to process files that are not auto processed because they are on a network mount or other drive that doesnt support inotify. added a small delay to allow for thumbnail processing as it sometimes took two scans to get the meta and thumbnail. --- src/components/panels/GcodefilesPanel.vue | 40 +++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/components/panels/GcodefilesPanel.vue b/src/components/panels/GcodefilesPanel.vue index aae54289a..84d7339fb 100644 --- a/src/components/panels/GcodefilesPanel.vue +++ b/src/components/panels/GcodefilesPanel.vue @@ -345,6 +345,13 @@ {{ mdiVideo3d }} {{ $t('Files.View3D') }} + + {{ mdiMagnify }} + {{ $t('Files.ScanMeta') }} + {{ mdiCloudDownload }} {{ $t('Files.Download') }} @@ -589,6 +596,7 @@ import { } from '@mdi/js' import StartPrintDialog from '@/components/dialogs/StartPrintDialog.vue' import ControlMixin from '@/components/mixins/control' +import axios from 'axios' interface contextMenu { shown: boolean @@ -1376,6 +1384,38 @@ export default class GcodefilesPanel extends Mixins(BaseMixin, ControlMixin) { this.$router.push({ path: '/viewer', query: { filename: 'gcodes' + this.currentPath + '/' + item.filename } }) } + scanMeta(item: FileStateFile) { + const filepath = this.currentPath + '/' + item.filename + const file = filepath.slice(0, 1) === '/' ? filepath.slice(1) : filepath + const data = { + filename: file, + } + item.small_thumbnail = undefined + axios + .post(this.apiUrl + '/server/files/metascan', data, { + headers: { 'Content-Type': 'multipart/form-data' }, + }) + .then((response) => { + const $this = this + const text = $this.$t('Files.ScanMetaSuccess').toString() + if (response.data.result.thumbnails) { + setTimeout(function () { + if (item.small_thumbnail) { + return true + } + $this.$store.dispatch('files/requestMetadata', { + filename: 'gcodes' + $this.currentPath + '/' + item.filename, + }) + }, 500) + } + this.$toast.success(text) + }) + .catch(() => { + const text = this.$t('Files.ScanMetaError').toString() + this.$toast.error(text) + }) + } + deleteSelectedFiles() { this.selectedFiles.forEach((item: FileStateGcodefile) => { if (item.isDirectory) { From 20ab9cf9165b75751fcb9e29338b5f60d3e6ec25 Mon Sep 17 00:00:00 2001 From: siparker Date: Mon, 20 Mar 2023 15:45:15 +0000 Subject: [PATCH 2/5] Update en.json added supporting phrases for the scan metadata option in gcode files. --- src/locales/en.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/locales/en.json b/src/locales/en.json index 03eae8fae..92334b81f 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -227,7 +227,10 @@ "Total": "Total", "UploadNewGcode": "Upload new G-Code", "Used": "Used", - "View3D": "View 3D" + "View3D": "View 3D", + "ScanMeta": "Scan Metadata", + "ScanMetaSuccess": "Successfully scanned metadata.", + "ScanMetaError": "There was an error scanning for metadata." }, "FullscreenUpload": { "CannotUploadFile": "Cannot upload file!", From 2a9353263f1489ca3885e99f4d409ece7824ca85 Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Sun, 2 Apr 2023 12:06:52 +0200 Subject: [PATCH 3/5] refactor: use websocket instead of http request Signed-off-by: Stefan Dej --- src/components/panels/GcodefilesPanel.vue | 32 +++-------------------- src/locales/en.json | 7 +++-- src/store/files/actions.ts | 22 ++++++++++++++++ 3 files changed, 28 insertions(+), 33 deletions(-) diff --git a/src/components/panels/GcodefilesPanel.vue b/src/components/panels/GcodefilesPanel.vue index 84d7339fb..c3e719f9b 100644 --- a/src/components/panels/GcodefilesPanel.vue +++ b/src/components/panels/GcodefilesPanel.vue @@ -1385,35 +1385,9 @@ export default class GcodefilesPanel extends Mixins(BaseMixin, ControlMixin) { } scanMeta(item: FileStateFile) { - const filepath = this.currentPath + '/' + item.filename - const file = filepath.slice(0, 1) === '/' ? filepath.slice(1) : filepath - const data = { - filename: file, - } - item.small_thumbnail = undefined - axios - .post(this.apiUrl + '/server/files/metascan', data, { - headers: { 'Content-Type': 'multipart/form-data' }, - }) - .then((response) => { - const $this = this - const text = $this.$t('Files.ScanMetaSuccess').toString() - if (response.data.result.thumbnails) { - setTimeout(function () { - if (item.small_thumbnail) { - return true - } - $this.$store.dispatch('files/requestMetadata', { - filename: 'gcodes' + $this.currentPath + '/' + item.filename, - }) - }, 500) - } - this.$toast.success(text) - }) - .catch(() => { - const text = this.$t('Files.ScanMetaError').toString() - this.$toast.error(text) - }) + this.$store.dispatch('files/scanMetadata', { + filename: 'gcodes' + this.currentPath + '/' + item.filename, + }) } deleteSelectedFiles() { diff --git a/src/locales/en.json b/src/locales/en.json index 92334b81f..1c7d2f9a3 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -216,6 +216,8 @@ "Rename": "Rename", "RenameDirectory": "Rename Directory", "RenameFile": "Rename File", + "ScanMeta": "Scan Metadata", + "ScanMetaSuccess": "Successfully scanned metadata from: {filename}.", "Search": "Search", "SetupCurrentList": "Setup current list", "Slicer": "Slicer", @@ -227,10 +229,7 @@ "Total": "Total", "UploadNewGcode": "Upload new G-Code", "Used": "Used", - "View3D": "View 3D", - "ScanMeta": "Scan Metadata", - "ScanMetaSuccess": "Successfully scanned metadata.", - "ScanMetaError": "There was an error scanning for metadata." + "View3D": "View 3D" }, "FullscreenUpload": { "CannotUploadFile": "Cannot upload file!", diff --git a/src/store/files/actions.ts b/src/store/files/actions.ts index 8de05b111..9e2942c9e 100644 --- a/src/store/files/actions.ts +++ b/src/store/files/actions.ts @@ -137,6 +137,28 @@ export const actions: ActionTree = { } }, + scanMetadata({ commit }, payload: { filename: string }) { + const rootPath = payload.filename.slice(0, payload.filename.indexOf('/')) + if (rootPath === 'gcodes') { + const requestFilename = payload.filename.slice(7) + commit('setMetadataRequested', { filename: requestFilename }) + Vue.$socket.emit( + 'server.files.metascan', + { filename: requestFilename }, + { action: 'files/getScanMetadata' } + ) + } + }, + + getScanMetadata({ dispatch }, payload: { filename: string }) { + if (payload !== undefined && payload.filename !== '') { + dispatch('getMetadata', payload) + + const filename = payload.filename + Vue.$toast.success(i18n.t('Files.ScanMetaSuccess', { filename }).toString()) + } + }, + requestMetadata({ commit }, payload: { filename: string }) { const rootPath = payload.filename.slice(0, payload.filename.indexOf('/')) if (rootPath === 'gcodes') { From 2471433b853dee7839533cd5062b83c020b31bbc Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Sun, 2 Apr 2023 12:08:01 +0200 Subject: [PATCH 4/5] locale(de): add german locale Signed-off-by: Stefan Dej --- src/locales/de.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/locales/de.json b/src/locales/de.json index 75606221c..1525e38b7 100644 --- a/src/locales/de.json +++ b/src/locales/de.json @@ -216,6 +216,8 @@ "Rename": "Umbenennen", "RenameDirectory": "Verzeichnis umbenennen", "RenameFile": "Datei umbenennen", + "ScanMeta": "Metadaten scannen", + "ScanMetaSuccess": "Metadaten von {filename} wurden erfolgreich gescannt.", "Search": "Suchen", "SetupCurrentList": "Einstellungen", "Slicer": "Slicer", From d79616a7c257d73058419bc512e79c7b58e96116 Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Mon, 10 Apr 2023 09:26:03 +0200 Subject: [PATCH 5/5] refactor: remove unused axios import Signed-off-by: Stefan Dej --- src/components/panels/GcodefilesPanel.vue | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/panels/GcodefilesPanel.vue b/src/components/panels/GcodefilesPanel.vue index c3e719f9b..d22c3aee3 100644 --- a/src/components/panels/GcodefilesPanel.vue +++ b/src/components/panels/GcodefilesPanel.vue @@ -596,7 +596,6 @@ import { } from '@mdi/js' import StartPrintDialog from '@/components/dialogs/StartPrintDialog.vue' import ControlMixin from '@/components/mixins/control' -import axios from 'axios' interface contextMenu { shown: boolean