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",
|
"@db/sqlite": "jsr:@db/sqlite@^0.11.1",
|
||||||
"@isaacs/ttlcache": "npm:@isaacs/ttlcache@^1.4.1",
|
"@isaacs/ttlcache": "npm:@isaacs/ttlcache@^1.4.1",
|
||||||
"@noble/secp256k1": "npm:@noble/secp256k1@^2.0.0",
|
"@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",
|
"@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/kysely-deno-sqlite": "jsr:@soapbox/kysely-deno-sqlite@^2.1.0",
|
||||||
"@soapbox/stickynotes": "jsr:@soapbox/stickynotes@^0.4.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}`);
|
debug(`NostrEvent<${event.kind}> ${event.id}`);
|
||||||
await hydrateEvent(event, signal);
|
await hydrateEvent(event, signal);
|
||||||
|
|
||||||
|
await policyFilter(event);
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
policyFilter(event),
|
|
||||||
storeEvent(event, signal),
|
storeEvent(event, signal),
|
||||||
parseMetadata(event, signal),
|
parseMetadata(event, signal),
|
||||||
processDeletions(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> {
|
async function policyFilter(event: NostrEvent): Promise<void> {
|
||||||
const UserPolicy = new MuteListPolicy(Conf.pubkey, Storages.admin);
|
const policy = new MuteListPolicy(Conf.pubkey, Storages.admin);
|
||||||
const result = await UserPolicy.call(event);
|
const result = await policy.call(event);
|
||||||
|
|
||||||
debug(JSON.stringify(result));
|
debug(JSON.stringify(result));
|
||||||
|
|
||||||
|
@ -59,11 +60,9 @@ async function policyFilter(event: NostrEvent): Promise<void> {
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
const [prefix, ...rest] = reason.split(': ');
|
const [prefix, ...rest] = reason.split(': ');
|
||||||
if (['duplicate', 'pow', 'blocked', 'rate-limited', 'invalid'].includes(prefix)) {
|
if (['duplicate', 'pow', 'blocked', 'rate-limited', 'invalid'].includes(prefix)) {
|
||||||
const error = new RelayError(prefix as any, rest.join(': '));
|
throw new RelayError(prefix as RelayErrorPrefix, rest.join(': '));
|
||||||
return Promise.reject(error);
|
|
||||||
} else {
|
} else {
|
||||||
const error = new RelayError('error', rest.join(': '));
|
throw new RelayError('error', rest.join(': '));
|
||||||
return Promise.reject(error);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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. */
|
/** NIP-20 command line result. */
|
||||||
class RelayError extends Error {
|
class RelayError extends Error {
|
||||||
constructor(prefix: 'duplicate' | 'pow' | 'blocked' | 'rate-limited' | 'invalid' | 'error', message: string) {
|
constructor(prefix: RelayErrorPrefix, message: string) {
|
||||||
super(`${prefix}: ${message}`);
|
super(`${prefix}: ${message}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,10 +103,8 @@ async function updateAdminEvent<E extends EventStub>(
|
||||||
async function publishEvent(event: NostrEvent, c: AppContext): Promise<NostrEvent> {
|
async function publishEvent(event: NostrEvent, c: AppContext): Promise<NostrEvent> {
|
||||||
debug('EVENT', event);
|
debug('EVENT', event);
|
||||||
try {
|
try {
|
||||||
await Promise.all([
|
await pipeline.handleEvent(event, c.req.raw.signal);
|
||||||
pipeline.handleEvent(event, c.req.raw.signal),
|
await Storages.client.event(event);
|
||||||
Storages.client.event(event),
|
|
||||||
]);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof pipeline.RelayError) {
|
if (e instanceof pipeline.RelayError) {
|
||||||
throw new HTTPException(422, {
|
throw new HTTPException(422, {
|
||||||
|
|
Loading…
Reference in New Issue