diff --git a/src/pipeline.ts b/src/pipeline.ts index e62bd03..092dde9 100644 --- a/src/pipeline.ts +++ b/src/pipeline.ts @@ -1,4 +1,4 @@ -import { NKinds, NostrEvent, NPolicy, NSchema as n } from '@nostrify/nostrify'; +import { NKinds, NostrEvent, NSchema as n } from '@nostrify/nostrify'; import { PipePolicy } from '@nostrify/nostrify/policies'; import Debug from '@soapbox/stickynotes/debug'; import { sql } from 'kysely'; @@ -55,24 +55,10 @@ async function handleEvent(event: DittoEvent, signal: AbortSignal): Promise { const debug = Debug('ditto:policy'); - const policies: NPolicy[] = [ + const policy = new PipePolicy([ new MuteListPolicy(Conf.pubkey, await Storages.admin()), - ]; - - try { - await policyWorker.import(Conf.policy); - policies.push(policyWorker); - debug(`Using custom policy: ${Conf.policy}`); - } catch (e) { - if (e.message.includes('Module not found')) { - debug('Custom policy not found '); - } else { - console.error(`DITTO_POLICY (error importing policy): ${Conf.policy}`, e); - throw new RelayError('blocked', 'policy could not be loaded'); - } - } - - const policy = new PipePolicy(policies.reverse()); + policyWorker, + ]); try { const result = await policy.call(event); diff --git a/src/workers/policy.ts b/src/workers/policy.ts index e392667..ef9aa2c 100644 --- a/src/workers/policy.ts +++ b/src/workers/policy.ts @@ -1,8 +1,11 @@ +import { Stickynotes } from '@soapbox/stickynotes'; import * as Comlink from 'comlink'; import { Conf } from '@/config.ts'; import type { CustomPolicy } from '@/workers/policy.worker.ts'; +const console = new Stickynotes('ditto:policy'); + export const policyWorker = Comlink.wrap( new Worker( new URL('./policy.worker.ts', import.meta.url), @@ -19,3 +22,14 @@ export const policyWorker = Comlink.wrap( }, ), ); + +try { + await policyWorker.import(Conf.policy); + console.debug(`Using custom policy: ${Conf.policy}`); +} catch (e) { + if (e.message.includes('Module not found')) { + console.debug('Custom policy not found '); + } else { + throw new Error(`DITTO_POLICY (error importing policy): ${Conf.policy}`, e); + } +}