pubkeyBanPolicy: support iterables
This commit is contained in:
parent
a8c55053b4
commit
817519c132
@ -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;
|
||||||
|
Loading…
Reference in New Issue
Block a user