Improve stupid code

This commit is contained in:
Alex Gleason 2023-03-29 23:34:34 -05:00
parent 566df31b4a
commit 48501f3c5f
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
2 changed files with 10 additions and 24 deletions

View File

@ -5,23 +5,16 @@ import { Policy } from '../types.ts';
* Pass an array of pubkeys or an iterable, making it efficient to load pubkeys from a large file. * Pass an array of pubkeys or an iterable, making it efficient to load pubkeys from a large file.
*/ */
const pubkeyBanPolicy: Policy<Iterable<string>> = ({ event: { id, pubkey } }, pubkeys = []) => { const pubkeyBanPolicy: Policy<Iterable<string>> = ({ event: { id, pubkey } }, pubkeys = []) => {
let isMatch = false;
for (const p of pubkeys) { for (const p of pubkeys) {
if (p === pubkey) { if (p === pubkey) {
isMatch = true; return {
break; id,
action: 'reject',
msg: 'blocked: pubkey is banned.',
};
} }
} }
if (isMatch) {
return {
id,
action: 'reject',
msg: 'blocked: pubkey is banned.',
};
}
return { return {
id, id,
action: 'accept', action: 'accept',

View File

@ -5,23 +5,16 @@ import type { Policy } from '../types.ts';
* Pass an array of pubkeys or an iterable, making it efficient to load pubkeys from a large file. * Pass an array of pubkeys or an iterable, making it efficient to load pubkeys from a large file.
*/ */
const whitelistPolicy: Policy<Iterable<string>> = ({ event: { id, pubkey } }, pubkeys = []) => { const whitelistPolicy: Policy<Iterable<string>> = ({ event: { id, pubkey } }, pubkeys = []) => {
let isMatch = false;
for (const p of pubkeys) { for (const p of pubkeys) {
if (p === pubkey) { if (p === pubkey) {
isMatch = true; return {
break; id,
action: 'accept',
msg: '',
};
} }
} }
if (isMatch) {
return {
id,
action: 'accept',
msg: '',
};
}
return { return {
id, id,
action: 'reject', action: 'reject',