From 395e12cbc6e22459508023daabba87b62a65050e Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Mon, 8 Mar 2021 21:00:43 +0200 Subject: better error/warnings --- src/components/settings_modal/settings_modal.js | 54 ++++++++++++++++++++++-- src/components/settings_modal/settings_modal.vue | 8 ++-- 2 files changed, 54 insertions(+), 8 deletions(-) (limited to 'src/components') diff --git a/src/components/settings_modal/settings_modal.js b/src/components/settings_modal/settings_modal.js index 7f6ccccb..f88184ca 100644 --- a/src/components/settings_modal/settings_modal.js +++ b/src/components/settings_modal/settings_modal.js @@ -19,6 +19,9 @@ import { faWindowMinimize } from '@fortawesome/free-regular-svg-icons' +const PLEROMAFE_SETTINGS_MAJOR_VERSION = 1 +const PLEROMAFE_SETTINGS_MINOR_VERSION = 0 + library.add( faTimes, faWindowMinimize, @@ -65,12 +68,52 @@ const SettingsModal = { this.$store.dispatch('togglePeekSettingsModal') }, importValidator (data) { - return data._pleroma_settings_version[0] === 1 + if (!Array.isArray(data._pleroma_settings_version)) { + return { + messageKey: 'settings.file_import_export.invalid_file' + } + } + + const [major, minor] = data._pleroma_settings_version + + if (major > PLEROMAFE_SETTINGS_MAJOR_VERSION) { + return { + messageKey: 'settings.file_export_import.errors.file_too_new', + messageArgs: { + fileMajor: major, + feMajor: PLEROMAFE_SETTINGS_MAJOR_VERSION + } + } + } + + if (major < PLEROMAFE_SETTINGS_MAJOR_VERSION) { + return { + messageKey: 'settings.file_export_import.errors.file_too_old', + messageArgs: { + fileMajor: major, + feMajor: PLEROMAFE_SETTINGS_MAJOR_VERSION + } + } + } + + if (minor > PLEROMAFE_SETTINGS_MINOR_VERSION) { + this.$store.dispatch('pushGlobalNotice', { + level: 'warning', + messageKey: 'settings.file_export_import.errors.file_slightly_new', + }) + } + + return true }, - onImportFailure () { - this.$store.dispatch('pushGlobalNotice', { messageKey: 'settings.invalid_settings_imported', level: 'error' }) + onImportFailure (result) { + if (result.error) { + this.$store.dispatch('pushGlobalNotice', { messageKey: 'settings.invalid_settings_imported', level: 'error' }) + } else { + this.$store.dispatch('pushGlobalNotice', { ...result.validationResult, level: 'error' }) + } }, onImport (data) { + if (data) this.$store.dispatch('loadSettings', data) }, restore () { @@ -99,7 +142,10 @@ const SettingsModal = { ) } const clone = cloneDeep(sample) - clone._pleroma_settings_version = [1, 0] + clone._pleroma_settings_version = [ + PLEROMAFE_SETTINGS_MAJOR_VERSION, + PLEROMAFE_SETTINGS_MINOR_VERSION + ] return clone } }, diff --git a/src/components/settings_modal/settings_modal.vue b/src/components/settings_modal/settings_modal.vue index a142bcd1..c37608e2 100644 --- a/src/components/settings_modal/settings_modal.vue +++ b/src/components/settings_modal/settings_modal.vue @@ -67,7 +67,7 @@ class="btn button-default" :title="$t('general.close')" > - {{ $t("settings.backup_restore") }} + {{ $t("settings.file_export_import.backup_restore") }} @@ -85,7 +85,7 @@ {{ $t("settings.backup_settings") }} + />{{ $t("settings.file_export_import.backup_settings") }} -- cgit v1.2.3-70-g09d2