pipeline: add a placeholder for custom policy

This commit is contained in:
Alex Gleason 2024-05-13 12:43:01 -05:00
parent 9bff7a5086
commit 6105e00c80
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
1 changed files with 11 additions and 4 deletions

View File

@ -1,5 +1,6 @@
import { NostrEvent, NSchema as n } from '@nostrify/nostrify'; import { NostrEvent, NSchema as n } from '@nostrify/nostrify';
import { LNURL } from '@nostrify/nostrify/ln'; import { LNURL } from '@nostrify/nostrify/ln';
import { PipePolicy } from '@nostrify/nostrify/policies';
import Debug from '@soapbox/stickynotes/debug'; import Debug from '@soapbox/stickynotes/debug';
import { sql } from 'kysely'; import { sql } from 'kysely';
@ -33,9 +34,12 @@ async function handleEvent(event: DittoEvent, signal: AbortSignal): Promise<void
if (!(await verifyEventWorker(event))) return; if (!(await verifyEventWorker(event))) return;
if (await encounterEvent(event, signal)) return; if (await encounterEvent(event, signal)) return;
debug(`NostrEvent<${event.kind}> ${event.id}`); debug(`NostrEvent<${event.kind}> ${event.id}`);
await hydrateEvent(event, signal);
if (event.kind !== 24133) {
await policyFilter(event); await policyFilter(event);
}
await hydrateEvent(event, signal);
await Promise.all([ await Promise.all([
storeEvent(event, signal), storeEvent(event, signal),
@ -51,9 +55,12 @@ async function handleEvent(event: DittoEvent, signal: AbortSignal): Promise<void
} }
async function policyFilter(event: NostrEvent): Promise<void> { async function policyFilter(event: NostrEvent): Promise<void> {
const policy = new MuteListPolicy(Conf.pubkey, Storages.admin); const policy = new PipePolicy([
const result = await policy.call(event); new MuteListPolicy(Conf.pubkey, Storages.admin),
// put custom policy here
]);
const result = await policy.call(event);
debug(JSON.stringify(result)); debug(JSON.stringify(result));
const [_, _eventId, ok, reason] = result; const [_, _eventId, ok, reason] = result;