diff --git a/src/store/modules/normalizers.js b/src/store/modules/normalizers.js index abc865ee..801e95a0 100644 --- a/src/store/modules/normalizers.js +++ b/src/store/modules/normalizers.js @@ -28,8 +28,10 @@ export const parseNonTuples = (key, value) => { // REFACTOR export const parseTuples = (tuples, key) => { return tuples.reduce((accum, item) => { - if (key === 'rate_limit') { - accum[item.tuple[0]] = item.tuple[1] + if (key === ':rate_limit') { + accum[item.tuple[0]] = Array.isArray(item.tuple[1]) + ? item.tuple[1].map(el => el.tuple) + : item.tuple[1].tuple } else if (item.tuple[0] === ':mascots') { accum[item.tuple[0]] = item.tuple[1].reduce((acc, mascot) => { return [...acc, { [mascot.tuple[0]]: { ...mascot.tuple[1], id: `f${(~~(Math.random() * 1e8)).toString(16)}` }}] @@ -150,7 +152,7 @@ const wrapValues = (settings, currentState) => { return { 'tuple': [setting, wrapValues(value, currentState)] } } else if (type === 'atom' && value.length > 0) { return { 'tuple': [setting, `:${value}`] } - } else if (type.includes('tuple') && Array.isArray(value)) { + } else if (type.includes('tuple') && (type.includes('string') || type.includes('list') || type.includes('atom'))) { return { 'tuple': [setting, { 'tuple': value }] } } else if (type === 'map') { const mapValue = Object.keys(value).reduce((acc, key) => { diff --git a/src/views/settings/components/Inputs.vue b/src/views/settings/components/Inputs.vue index 7db9537d..05dc0ad6 100644 --- a/src/views/settings/components/Inputs.vue +++ b/src/views/settings/components/Inputs.vue @@ -55,30 +55,6 @@ @input="update($event, settingGroup.group, settingGroup.key, settingParent, setting.key, setting.type, nested)"> -
-
- : - -
- -

Set different limits for unauthenticated and authenticated users

-
-
-
- - : - - - - : - - -
- -

Set limit for all users

-
-
-
@@ -88,6 +64,7 @@ +

{{ setting.description }}

@@ -97,7 +74,7 @@ import AceEditor from 'vue2-ace-editor' import 'brace/mode/elixir' import 'default-passive-events' -import { AutoLinkerInput, BackendsLoggerInput, EditableKeywordInput, IconsInput, MascotsInput, ProxyUrlInput, PruneInput, SslOptionsInput } from './inputComponents' +import { AutoLinkerInput, BackendsLoggerInput, EditableKeywordInput, IconsInput, MascotsInput, ProxyUrlInput, PruneInput, RateLimitInput, SslOptionsInput } from './inputComponents' export default { name: 'Inputs', @@ -110,6 +87,7 @@ export default { MascotsInput, ProxyUrlInput, PruneInput, + RateLimitInput, SslOptionsInput }, props: { @@ -180,19 +158,6 @@ export default { labelWidth() { return this.isMobile ? '100px' : '240px' }, - rateLimitAllUsers() { - return this.data[this.setting.key] ? Object.entries(this.data[this.setting.key])[0] : [null, null] - }, - rateLimitAuthUsers() { - return Array.isArray(this.data[this.setting.key]) - ? Object.entries(this.data[this.setting.key][1])[0] - : false - }, - rateLimitUnauthUsers() { - return Array.isArray(this.data[this.setting.key]) - ? Object.entries(this.data[this.setting.key][0])[0] - : false - }, rewritePolicyValue() { return typeof this.data[this.setting.key] === 'string' ? [this.data[this.setting.key]] : this.data[this.setting.key] }, @@ -210,22 +175,6 @@ export default { type === 'map' || (Array.isArray(type) && type.includes('keyword') && type.findIndex(el => el.includes('list') && el.includes('string')) !== -1) }, - parseRateLimiter(value, input, typeOfInput, typeOfLimit, currentValue) { - if (typeOfLimit === 'oneLimit') { - const valueToSend = typeOfInput === 'scale' ? { 'tuple': [value, currentValue[1]] } : { 'tuple': [currentValue[0], value] } - this.updateSetting(valueToSend, this.settingGroup.group, 'rate_limit', input) - } else if (typeOfLimit === 'authUserslimit') { - const valueToSend = typeOfInput === 'scale' - ? [{ 'tuple': [currentValue[0][0], currentValue[0][1]] }, { 'tuple': [value, currentValue[1][1]] }] - : [{ 'tuple': [currentValue[0][0], currentValue[0][1]] }, { 'tuple': [currentValue[1][0], value] }] - this.updateSetting(valueToSend, this.settingGroup.group, 'rate_limit', input) - } else if (typeOfLimit === 'unauthUsersLimit') { - const valueToSend = typeOfInput === 'scale' - ? [{ 'tuple': [value, currentValue[0][1]] }, { 'tuple': [currentValue[1][0], currentValue[1][1]] }] - : [{ 'tuple': [currentValue[0][0], value] }, { 'tuple': [currentValue[1][0], currentValue[1][1]] }] - this.updateSetting(valueToSend, this.settingGroup.group, 'rate_limit', input) - } - }, processNestedData(value, group, key, parentInput, parentType, childInput, childType) { const valueExists = value => value[group] && value[group][key] && value[group][key][parentInput] const updatedValueForState = valueExists(this.settings) @@ -246,9 +195,6 @@ export default { this.setting.key === ':args' ) }, - toggleLimits(value, input) { - this.updateSetting(value, this.settingGroup.group, 'rate_limit', input) - }, update(value, group, key, parent, input, type, nested) { nested ? this.processNestedData(value, group, key, parent.key, parent.type, input, type) diff --git a/src/views/settings/components/inputComponents/MascotsInput.vue b/src/views/settings/components/inputComponents/MascotsInput.vue index 6397a8e1..671a6a37 100644 --- a/src/views/settings/components/inputComponents/MascotsInput.vue +++ b/src/views/settings/components/inputComponents/MascotsInput.vue @@ -19,7 +19,6 @@ + + diff --git a/src/views/settings/components/inputComponents/index.js b/src/views/settings/components/inputComponents/index.js index 511864e8..601f47d0 100644 --- a/src/views/settings/components/inputComponents/index.js +++ b/src/views/settings/components/inputComponents/index.js @@ -5,4 +5,5 @@ export { default as EditableKeywordInput } from './EditableKeywordInput' export { default as IconsInput } from './IconsInput' export { default as ProxyUrlInput } from './ProxyUrlInput' export { default as PruneInput } from './PruneInput' +export { default as RateLimitInput } from './RateLimitInput' export { default as SslOptionsInput } from './SslOptionsInput' diff --git a/src/views/settings/index.vue b/src/views/settings/index.vue index 16fd3dd5..90976b3d 100644 --- a/src/views/settings/index.vue +++ b/src/views/settings/index.vue @@ -53,13 +53,13 @@ + + +