Fix some issues in pipeline and utils/api.ts
This commit is contained in:
parent
04968fefaa
commit
9bff7a5086
|
@ -20,7 +20,7 @@
|
|||
"@db/sqlite": "jsr:@db/sqlite@^0.11.1",
|
||||
"@isaacs/ttlcache": "npm:@isaacs/ttlcache@^1.4.1",
|
||||
"@noble/secp256k1": "npm:@noble/secp256k1@^2.0.0",
|
||||
"@nostrify/nostrify": "jsr:@nostrify/nostrify@^0.17.1",
|
||||
"@nostrify/nostrify": "jsr:@nostrify/nostrify@^0.19.0",
|
||||
"@sentry/deno": "https://deno.land/x/sentry@7.112.2/index.mjs",
|
||||
"@soapbox/kysely-deno-sqlite": "jsr:@soapbox/kysely-deno-sqlite@^2.1.0",
|
||||
"@soapbox/stickynotes": "jsr:@soapbox/stickynotes@^0.4.0",
|
||||
|
|
|
@ -35,8 +35,9 @@ async function handleEvent(event: DittoEvent, signal: AbortSignal): Promise<void
|
|||
debug(`NostrEvent<${event.kind}> ${event.id}`);
|
||||
await hydrateEvent(event, signal);
|
||||
|
||||
await policyFilter(event);
|
||||
|
||||
await Promise.all([
|
||||
policyFilter(event),
|
||||
storeEvent(event, signal),
|
||||
parseMetadata(event, signal),
|
||||
processDeletions(event, signal),
|
||||
|
@ -50,8 +51,8 @@ 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);
|
||||
const policy = new MuteListPolicy(Conf.pubkey, Storages.admin);
|
||||
const result = await policy.call(event);
|
||||
|
||||
debug(JSON.stringify(result));
|
||||
|
||||
|
@ -59,11 +60,9 @@ async function policyFilter(event: NostrEvent): Promise<void> {
|
|||
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);
|
||||
throw new RelayError(prefix as RelayErrorPrefix, rest.join(': '));
|
||||
} else {
|
||||
const error = new RelayError('error', rest.join(': '));
|
||||
return Promise.reject(error);
|
||||
throw new RelayError('error', rest.join(': '));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -272,9 +271,11 @@ async function streamOut(event: NostrEvent): Promise<void> {
|
|||
}
|
||||
}
|
||||
|
||||
type RelayErrorPrefix = 'duplicate' | 'pow' | 'blocked' | 'rate-limited' | 'invalid' | 'error';
|
||||
|
||||
/** NIP-20 command line result. */
|
||||
class RelayError extends Error {
|
||||
constructor(prefix: 'duplicate' | 'pow' | 'blocked' | 'rate-limited' | 'invalid' | 'error', message: string) {
|
||||
constructor(prefix: RelayErrorPrefix, message: string) {
|
||||
super(`${prefix}: ${message}`);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -103,10 +103,8 @@ async function updateAdminEvent<E extends EventStub>(
|
|||
async function publishEvent(event: NostrEvent, c: AppContext): Promise<NostrEvent> {
|
||||
debug('EVENT', event);
|
||||
try {
|
||||
await Promise.all([
|
||||
pipeline.handleEvent(event, c.req.raw.signal),
|
||||
Storages.client.event(event),
|
||||
]);
|
||||
await pipeline.handleEvent(event, c.req.raw.signal);
|
||||
await Storages.client.event(event);
|
||||
} catch (e) {
|
||||
if (e instanceof pipeline.RelayError) {
|
||||
throw new HTTPException(422, {
|
||||
|
|
Loading…
Reference in New Issue