Skip to content
Snippets Groups Projects

Fix config value type

Merged kPherox requested to merge kphrx/admin-fe:fix-config-value-type into master
1 unresolved thread
const nonAtomsTuples = ['replace', 'match_actor', ':replace', ':match_actor']
const nonTuples = [
'digest',
'pleroma_fe',
'pleroma_fox_tan',
'pleroma_fox_tan_shy',
+2
'masto_fe',
'poll_limits',
':digest',
':pleroma_fe',
':pleroma_fox_tan',
':pleroma_fox_tan_shy',
':masto_fe',
':poll_limits'
]
const groups = {
'cors_plug': [
'credentials',
@@ -146,16 +160,18 @@ 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 (nonTuples.includes(settingName)) {
    • Hey! Thanks so much for testing and offering fixes and improvements!

      Sending ip as a tuple of numbers is certainly a good idea. But there is an issue with the changes to the wrapConfig and wrapNestedTuples functions. Those are preparing the data to be send to the backend and when we need to send type object values (nested data), we need to send it as an array of tuples, not as an object.

      E.g.

      {
            "group": "pleroma",
            "key": "Pleroma.Upload",
            "value": [
              {"tuple": [":proxy_opts", [
                {"tuple": [":redirect_on_failure", false]},
                {"tuple": [":max_body_length", 1048576]},
                {"tuple": [":http": [
                  {"tuple": [":follow_redirect", true]},
                  {"tuple": [":pool", ":upload"]},
                ]]}
              ]
              ]}
            ]
          }

      Please provide more information if you think that we should still merged that part of your MR or we can just go ahead and merge the ip-related part.

      • Those are preparing the data to be send to the backend and when we need to send type object values (nested data), we need to send it as an array of tuples, not as an object.

        I understand. But if you leave it as it is, for example, the value of :poll_limits is changed from an object to a tuple, so will return an internal server error in /api/v1/instance or /.well-known/nodeinfo/2.0.json. Because it cannot be converted to json. To fix this bug, I tried not to change object to tuple in what was saved with migrate_to_db.

      • Ah, now I see what you mean, you're right, there is a problem with converting object to an array of tuples. I'm now discussing it with backend developer and will be back to you soon.

      • changed this line in version 5 of the diff

      • Please register or sign in to reply
Please register or sign in to reply
return [...acc, { 'tuple': [`:${settingName}`, wrapObject(data)] }]
} else if (!Array.isArray(data) && typeof data === 'object') {
return nonAtomsTuples.includes(settingName)
? [...acc, { 'tuple': [`:${settingName}`, wrapNonAtomsTuples(data)] }]
: [...acc, { 'tuple': [`:${settingName}`, wrapNestedTuples(data)] }]
}
return key === ':mrf_user_allowlist'
? [...acc, { 'tuple': [`${settingName}`, settings[config][settingName]] }]
: [...acc, { 'tuple': [`:${settingName}`, settings[config][settingName]] }]
? [...acc, { 'tuple': [`${settingName}`, data] }]
: [...acc, { 'tuple': [`:${settingName}`, data] }]
}, [])
return { group, key, value }
})
@@ -167,12 +183,14 @@ 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 (nonTuples.includes(settingName)) {
return [...acc, { 'tuple': [`:${settingName}`, wrapObject(data)] }]
} else if (!Array.isArray(data) && typeof data === 'object') {
return [...acc, { 'tuple': [`:${settingName}`, wrapNestedTuples(data)] }]
}
return [...acc, { 'tuple': [`:${settingName}`, setting[settingName]] }]
return [...acc, { 'tuple': [`:${settingName}`, data] }]
}, [])
}
@@ -182,6 +200,13 @@ const wrapNonAtomsTuples = setting => {
}, [])
}
const wrapObject = setting => {
return Object.keys(setting).reduce((acc, settingName) => {
acc[`:${settingName}`] = setting[settingName]
return acc
}, {})
}
const getGroup = key => {
return Object.keys(groups).find(i => groups[i].includes(key))
}
Loading