feat: do not allow deactivated accounts to post
This commit is contained in:
parent
801e68c6c4
commit
fe66937bba
|
@ -21,18 +21,10 @@ import { AdminSigner } from '@/signers/AdminSigner.ts';
|
|||
import { lnurlCache } from '@/utils/lnurl.ts';
|
||||
import { nip05Cache } from '@/utils/nip05.ts';
|
||||
|
||||
import { MuteListPolicy } from '@/policies/MuteListPolicy.ts';
|
||||
|
||||
const debug = Debug('ditto:pipeline');
|
||||
|
||||
let UserPolicy: any;
|
||||
|
||||
try {
|
||||
UserPolicy = (await import('../data/policy.ts')).default;
|
||||
debug('policy loaded from data/policy.ts');
|
||||
} catch (_e) {
|
||||
// do nothing
|
||||
debug('policy not found');
|
||||
}
|
||||
|
||||
/**
|
||||
* Common pipeline function to process (and maybe store) events.
|
||||
* It is idempotent, so it can be called multiple times for the same event.
|
||||
|
@ -43,17 +35,8 @@ async function handleEvent(event: DittoEvent, signal: AbortSignal): Promise<void
|
|||
debug(`NostrEvent<${event.kind}> ${event.id}`);
|
||||
await hydrateEvent(event, signal);
|
||||
|
||||
if (UserPolicy) {
|
||||
const result = await new UserPolicy().call(event, signal);
|
||||
debug(JSON.stringify(result));
|
||||
const [_, _eventId, ok, reason] = result;
|
||||
if (!ok) {
|
||||
const [prefix, ...rest] = reason.split(': ');
|
||||
throw new RelayError(prefix, rest.join(': '));
|
||||
}
|
||||
}
|
||||
|
||||
await Promise.all([
|
||||
policyFilter(event),
|
||||
storeEvent(event, signal),
|
||||
parseMetadata(event, signal),
|
||||
processDeletions(event, signal),
|
||||
|
@ -66,6 +49,25 @@ async function handleEvent(event: DittoEvent, signal: AbortSignal): Promise<void
|
|||
]);
|
||||
}
|
||||
|
||||
async function policyFilter(event: NostrEvent): Promise<void> {
|
||||
const UserPolicy = new MuteListPolicy(Conf.pubkey, Storages.admin);
|
||||
const result = await UserPolicy.call(event);
|
||||
|
||||
debug(JSON.stringify(result));
|
||||
|
||||
const [_, _eventId, ok, reason] = result;
|
||||
if (!ok) {
|
||||
const [prefix, ...rest] = reason.split(': ');
|
||||
if (['duplicate', 'pow', 'blocked', 'rate-limited', 'invalid'].includes(prefix)) {
|
||||
const error = new RelayError(prefix as any, rest.join(': '));
|
||||
return Promise.reject(error);
|
||||
} else {
|
||||
const error = new RelayError('error', rest.join(': '));
|
||||
return Promise.reject(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Encounter the event, and return whether it has already been encountered. */
|
||||
async function encounterEvent(event: NostrEvent, signal: AbortSignal): Promise<boolean> {
|
||||
const [existing] = await Storages.cache.query([{ ids: [event.id], limit: 1 }]);
|
||||
|
|
Loading…
Reference in New Issue