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,49 +143,52 @@ const SettingsModal = {
}) })
} }
}, },
onImport(data) { onImport(input) {
if (data) { if (!input) return
Object.entries(data).forEach(([path, value]) => { const { _pleroma_settings_version, ...data } = input
if (LOCAL_ONLY_KEYS.has(path)) {
useLocalConfigStore().set({ 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)) {
useLocalConfigStore().set({ path, value: finalValue })
} else {
if (path.startsWith('muteFilters')) {
Object.keys(
useMergedConfigStore().mergedConfig.muteFilters,
).forEach((key) => {
useSyncConfigStore().unsetPreference({
path: `simple.${path}.${key}`,
})
})
Object.entries(value).forEach(([key, filter]) => {
useSyncConfigStore().setPreference({
path: `simple.${path}.${key}`,
value: filter,
})
})
} else { } else {
if (path.startsWith('muteFilters')) { if (finalValue !== undefined) {
Object.keys( useSyncConfigStore().setPreference({
useMergedConfigStore().mergedConfig.muteFilters,
).forEach((key) => {
useSyncConfigStore().unsetPreference({
path: `simple.${path}.${key}`,
})
})
Object.entries(value).forEach(([key, filter]) => {
useSyncConfigStore().setPreference({
path: `simple.${path}.${key}`,
value: filter,
})
})
} else {
const definition = ROOT_CONFIG_DEFINITIONS[path]
const finalValue = validateSetting({
path: `simple.${path}`, path: `simple.${path}`,
value, value: finalValue,
definition,
throwError: false,
defaultState: ROOT_CONFIG,
}) })
if (finalValue !== undefined) {
useSyncConfigStore().setPreference({
path: `simple.${path}`,
value,
})
}
} }
} }
}) }
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)