fix: (regression beta) block button in monitoring/logs was not working anymore

Massimo Melina committed Sep 3, 2024 at 10:28 UTC 7d64d0ea37d116650d399eb61943169f70149065
2 files changed +5 -4
src/adminApis.ts
+2 -1
@@ -150,7 +150,8 @@ export const adminApis = {
150 string_undefined: { comment, expire },
151 object_undefined: { merge },
152 })
153 - addBlock({ ip, expire, comment }, merge)
153 + const optionals = _.pickBy({ expire, comment }, v => v !== undefined) // passing undefined-s would override values in merge
154 + addBlock({ ip, ...optionals }, merge)
155 return {}
156 }
157
src/block.ts
+3 -3
@@ -37,8 +37,8 @@ setInterval(() => { // twice a minute, check if any block has expired
37
38 export function addBlock(rule: BlockingRule, merge?: Partial<BlockingRule>) {
39 block.set(was => {
40 - const found = merge && _.findIndex(was, merge)
41 - return found ? was.map((x, i) => i === found ? { ...x, ...rule, ip: `${x.ip}|${rule.ip}` } : x)
42 - : [...was, { ...merge, ...rule }]
40 + const foundIdx = merge ? _.findIndex(was, merge) : -1
41 + return foundIdx < 0 ? [...was, { ...merge, ...rule }]
42 + : was.map((x, i) => i === foundIdx ? { ...x, ...rule, ip: `${x.ip}|${rule.ip}` } : x)
43 })
44 }
\ No newline at end of file