From e504d8264b9bb13c8815c4133a54a16dc8292ab2 Mon Sep 17 00:00:00 2001 From: kPherox Date: Wed, 21 Aug 2019 11:37:55 +0000 Subject: [PATCH] Converts maps and structs from config to JS objects, not array of tuples when wrapping config --- CHANGELOG.md | 5 ++- src/store/modules/normalizers.js | 61 +++++++++++++++++++++++++------- 2 files changed, 51 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bfbd9761..90a61343 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,9 +12,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Fixed -- fixes inputs for renders_errors and rewrite_policy settings -- removes unnecessary computed properties -- enables source maps for production build +- converts maps and structs to JS objects, not array of tuples when wrapping config +- changes type of IP value from string to number ## [1.0.1] - 2019-08-15 diff --git a/src/store/modules/normalizers.js b/src/store/modules/normalizers.js index f6a70067..be78a57b 100644 --- a/src/store/modules/normalizers.js +++ b/src/store/modules/normalizers.js @@ -1,4 +1,7 @@ -const nonAtomsTuples = ['replace', 'match_actor', ':replace', ':match_actor'] +const nonAtomsTuples = ['replace', ':replace'] +const nonAtomsObjects = ['match_actor', ':match_actor'] +const objects = ['digest', 'pleroma_fe', 'masto_fe', 'poll_limits'] +const objectParents = ['mascots'] const groups = { 'cors_plug': [ 'credentials', @@ -146,16 +149,23 @@ export const wrapConfig = settings => { } else if (key === ':rate_limit') { return [...acc, { 'tuple': [`:${settingName}`, data] }] } else if (settingName === 'ip') { - const ip = data.split('.') + const ip = data.split('.').map(s => parseInt(s, 10)) return [...acc, { 'tuple': [`:${settingName}`, { 'tuple': ip }] }] - } else if (!Array.isArray(data) && typeof data === 'object') { - return nonAtomsTuples.includes(settingName) - ? [...acc, { 'tuple': [`:${settingName}`, wrapNonAtomsTuples(data)] }] - : [...acc, { 'tuple': [`:${settingName}`, wrapNestedTuples(data)] }] + } else if (Array.isArray(data) || typeof data !== 'object') { + return key === ':mrf_user_allowlist' + ? [...acc, { 'tuple': [`${settingName}`, data] }] + : [...acc, { 'tuple': [`:${settingName}`, data] }] + } else if (nonAtomsObjects.includes(settingName)) { + return [...acc, { 'tuple': [`:${settingName}`, wrapNonAtomsObjects(data)] }] + } else if (objectParents.includes(settingName)) { + return [...acc, { 'tuple': [`:${settingName}`, wrapNestedObjects(data)] }] + } else if (objects.includes(settingName)) { + return [...acc, { 'tuple': [`:${settingName}`, wrapObjects(data)] }] + } else if (nonAtomsTuples.includes(settingName)) { + return [...acc, { 'tuple': [`:${settingName}`, wrapNonAtomsTuples(data)] }] + } else { + return [...acc, { 'tuple': [`:${settingName}`, wrapNestedTuples(data)] }] } - return key === ':mrf_user_allowlist' - ? [...acc, { 'tuple': [`${settingName}`, settings[config][settingName]] }] - : [...acc, { 'tuple': [`:${settingName}`, settings[config][settingName]] }] }, []) return { group, key, value } }) @@ -167,12 +177,21 @@ const wrapNestedTuples = setting => { if (data === null || data === '') { return acc } else if (settingName === 'ip') { - const ip = data.split('.') + const ip = data.split('.').map(s => parseInt(s, 10)) return [...acc, { 'tuple': [`:${settingName}`, { 'tuple': ip }] }] - } else if (!Array.isArray(data) && typeof data === 'object') { + } else if (Array.isArray(data) || typeof data !== 'object') { + return [...acc, { 'tuple': [`:${settingName}`, data] }] + } else if (nonAtomsObjects.includes(settingName)) { + return [...acc, { 'tuple': [`:${settingName}`, wrapNonAtomsObjects(data)] }] + } else if (objectParents.includes(settingName)) { + return [...acc, { 'tuple': [`:${settingName}`, wrapNestedObjects(data)] }] + } else if (objects.includes(settingName)) { + return [...acc, { 'tuple': [`:${settingName}`, wrapObjects(data)] }] + } else if (nonAtomsTuples.includes(settingName)) { + return [...acc, { 'tuple': [`:${settingName}`, wrapNonAtomsTuples(data)] }] + } else { return [...acc, { 'tuple': [`:${settingName}`, wrapNestedTuples(data)] }] } - return [...acc, { 'tuple': [`:${settingName}`, setting[settingName]] }] }, []) } @@ -182,6 +201,24 @@ const wrapNonAtomsTuples = setting => { }, []) } +const wrapNestedObjects = setting => { + return Object.keys(setting).reduce((acc, settingName) => { + return [...acc, { 'tuple': [`:${settingName}`, wrapObjects(setting[settingName])] }] + }, []) +} + +const wrapNonAtomsObjects = setting => { + return Object.keys(setting).reduce((acc, settingName) => { + return { ...acc, [`${settingName}`]: setting[settingName] } + }, {}) +} + +const wrapObjects = setting => { + return Object.keys(setting).reduce((acc, settingName) => { + return { ...acc, [`:${settingName}`]: setting[settingName] } + }, {}) +} + const getGroup = key => { return Object.keys(groups).find(i => groups[i].includes(key)) }