fix import

This commit is contained in:
Henry Jameson 2026-04-05 13:29:16 +03:00
commit c1d7d2fa63
2 changed files with 42 additions and 39 deletions

View file

@ -143,11 +143,25 @@ const SettingsModal = {
}) })
} }
}, },
onImport(data) { onImport(input) {
if (data) { if (!input) return
const { _pleroma_settings_version, ...data } = input
Object.entries(data).forEach(([path, value]) => { Object.entries(data).forEach(([path, value]) => {
const definition = ROOT_CONFIG_DEFINITIONS[path]
const finalValue = validateSetting({
path,
value,
definition,
throwError: false,
defaultState: ROOT_CONFIG,
})
if (finalValue === undefined) return
if (LOCAL_ONLY_KEYS.has(path)) { if (LOCAL_ONLY_KEYS.has(path)) {
useLocalConfigStore().set({ path, value }) useLocalConfigStore().set({ path, value: finalValue })
} else { } else {
if (path.startsWith('muteFilters')) { if (path.startsWith('muteFilters')) {
Object.keys( Object.keys(
@ -165,27 +179,16 @@ const SettingsModal = {
}) })
}) })
} else { } else {
const definition = ROOT_CONFIG_DEFINITIONS[path]
const finalValue = validateSetting({
path: `simple.${path}`,
value,
definition,
throwError: false,
defaultState: ROOT_CONFIG,
})
if (finalValue !== undefined) { if (finalValue !== undefined) {
useSyncConfigStore().setPreference({ useSyncConfigStore().setPreference({
path: `simple.${path}`, path: `simple.${path}`,
value, value: finalValue,
}) })
} }
} }
} }
}) })
useSyncConfigStore().pushSyncConfig() useSyncConfigStore().pushSyncConfig()
}
}, },
restore() { restore() {
this.dataImporter.importData() this.dataImporter.importData()

View file

@ -738,7 +738,7 @@ export const validateSetting = ({
}) => { }) => {
if (value === undefined) return // only null is allowed as missing value if (value === undefined) return // only null is allowed as missing value
if (get(defaultState, path) === undefined) { if (get(defaultState, path) === undefined) {
const string = `Unknown instance option ${path}, value: ${value}` const string = `Unknown option ${path}, value: ${value}`
if (throwError) { if (throwError) {
throw new Error(string) throw new Error(string)