pubkeyBanPolicy: support iterables

This commit is contained in:
Alex Gleason 2023-03-26 15:43:48 -05:00
parent a8c55053b4
commit 817519c132
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7

View File

@ -1,8 +1,18 @@
import { Policy } from '../types.ts'; import { Policy } from '../types.ts';
/** Ban individual pubkeys from publishing events to the relay. */ /**
const pubkeyPolicy: Policy<string[]> = ({ event: { id, pubkey } }, pubkeys = []) => { * Ban individual pubkeys from publishing events to the relay.
const isMatch = pubkeys.includes(pubkey); * 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 = []) => {
let isMatch = false;
for (const p of pubkeys) {
if (p === pubkey) {
isMatch = true;
break;
}
}
if (isMatch) { if (isMatch) {
return { return {
@ -19,4 +29,4 @@ const pubkeyPolicy: Policy<string[]> = ({ event: { id, pubkey } }, pubkeys = [])
}; };
}; };
export default pubkeyPolicy; export default pubkeyBanPolicy;