forked from AkkomaGang/admin-fe
Fix parsing mascots and send mascots without ids to UpdateSettings
This commit is contained in:
parent
760cdd3db9
commit
bf915110e5
2 changed files with 13 additions and 14 deletions
|
@ -10,12 +10,14 @@ export const parseTuples = (tuples, key) => {
|
||||||
return tuples.reduce((accum, item) => {
|
return tuples.reduce((accum, item) => {
|
||||||
if (key === 'rate_limit') {
|
if (key === 'rate_limit') {
|
||||||
accum[item.tuple[0]] = item.tuple[1]
|
accum[item.tuple[0]] = item.tuple[1]
|
||||||
|
} else if (key === ':mascots') {
|
||||||
|
accum[item.tuple[0]] = { ...item.tuple[1], id: `f${(~~(Math.random() * 1e8)).toString(16)}` }
|
||||||
} else if ((item.tuple[0] === ':sslopts' && item.tuple[1].length === 0) || // should be removed
|
} else if ((item.tuple[0] === ':sslopts' && item.tuple[1].length === 0) || // should be removed
|
||||||
(item.tuple[0] === ':tlsopts' && item.tuple[1].length === 0)) {
|
(item.tuple[0] === ':tlsopts' && item.tuple[1].length === 0)) {
|
||||||
accum[item.tuple[0]] = {}
|
accum[item.tuple[0]] = {}
|
||||||
} else if (Array.isArray(item.tuple[1]) &&
|
} else if (Array.isArray(item.tuple[1]) &&
|
||||||
(typeof item.tuple[1][0] === 'object' && !Array.isArray(item.tuple[1][0])) && item.tuple[1][0]['tuple']) {
|
(typeof item.tuple[1][0] === 'object' && !Array.isArray(item.tuple[1][0])) && item.tuple[1][0]['tuple']) {
|
||||||
accum[item.tuple[0]] = parseTuples(item.tuple[1])
|
accum[item.tuple[0]] = parseTuples(item.tuple[1], item.tuple[0])
|
||||||
} else if (Array.isArray(item.tuple[1])) {
|
} else if (Array.isArray(item.tuple[1])) {
|
||||||
nonAtomsTuples.includes(item.tuple[0])
|
nonAtomsTuples.includes(item.tuple[0])
|
||||||
? accum[item.tuple[0]] = parseNonAtomTuples(item.tuple[1])
|
? accum[item.tuple[0]] = parseNonAtomTuples(item.tuple[1])
|
||||||
|
@ -27,7 +29,7 @@ export const parseTuples = (tuples, key) => {
|
||||||
} else if (item.tuple[1] && typeof item.tuple[1] === 'object') {
|
} else if (item.tuple[1] && typeof item.tuple[1] === 'object') {
|
||||||
nonAtomsObjects.includes(item.tuple[0])
|
nonAtomsObjects.includes(item.tuple[0])
|
||||||
? accum[item.tuple[0]] = parseNonAtomObject(item.tuple[1])
|
? accum[item.tuple[0]] = parseNonAtomObject(item.tuple[1])
|
||||||
: accum[item.tuple[0]] = parseObject(item.tuple)
|
: accum[item.tuple[0]] = parseObject(item.tuple[1])
|
||||||
} else {
|
} else {
|
||||||
accum[item.tuple[0]] = item.tuple[1]
|
accum[item.tuple[0]] = item.tuple[1]
|
||||||
}
|
}
|
||||||
|
@ -49,14 +51,9 @@ const parseNonAtomObject = (object) => {
|
||||||
}, {})
|
}, {})
|
||||||
}
|
}
|
||||||
|
|
||||||
const parseObject = tuple => {
|
const parseObject = object => {
|
||||||
return tuple[0] === ':mascots'
|
return Object.keys(object).reduce((acc, item) => {
|
||||||
? Object.keys(tuple[1]).reduce((acc, item) => {
|
acc[item] = object[item]
|
||||||
acc[item] = { ...tuple[1][item], id: `f${(~~(Math.random() * 1e8)).toString(16)}` }
|
|
||||||
return acc
|
|
||||||
}, {})
|
|
||||||
: Object.keys(tuple[1]).reduce((acc, item) => {
|
|
||||||
acc[item] = tuple[1][item]
|
|
||||||
return acc
|
return acc
|
||||||
}, {})
|
}, {})
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,11 +71,13 @@ export default {
|
||||||
}
|
}
|
||||||
return { ...acc, ...{ [mascot]: this.data[mascot] }}
|
return { ...acc, ...{ [mascot]: this.data[mascot] }}
|
||||||
}, {})
|
}, {})
|
||||||
|
|
||||||
this.updateSetting(updatedValue, this.settingGroup.group, this.settingGroup.key, this.setting.key, this.setting.type)
|
this.updateSetting(updatedValue, this.settingGroup.group, this.settingGroup.key, this.setting.key, this.setting.type)
|
||||||
},
|
},
|
||||||
updateSetting(value, group, key, input, type) {
|
updateSetting(value, group, key, input, type) {
|
||||||
this.$store.dispatch('UpdateSettings', { group, key, input, value, type })
|
const mascotsWithoutIDs = Object.keys(value).reduce((acc, name) => {
|
||||||
|
return { ...acc, ...{ [name]: { ':url': value[name][':url'], ':mime_type': value[name][':mime_type'] }}}
|
||||||
|
}, {})
|
||||||
|
this.$store.dispatch('UpdateSettings', { group, key, input, value: mascotsWithoutIDs, type })
|
||||||
this.$store.dispatch('UpdateState', { group, key, input, value })
|
this.$store.dispatch('UpdateState', { group, key, input, value })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue