diff --git a/deno.json b/deno.json index d3e5acd5..6d282377 100644 --- a/deno.json +++ b/deno.json @@ -16,7 +16,7 @@ "exclude": ["./public"], "imports": { "@/": "./src/", - "@nostrify/nostrify": "jsr:@nostrify/nostrify@^0.12.1", + "@nostrify/nostrify": "jsr:@nostrify/nostrify@^0.14.2", "@std/cli": "jsr:@std/cli@^0.223.0", "@std/json": "jsr:@std/json@^0.223.0", "@std/streams": "jsr:@std/streams@^0.223.0", diff --git a/src/controllers/api/streaming.ts b/src/controllers/api/streaming.ts index 8fa1e24c..668218dc 100644 --- a/src/controllers/api/streaming.ts +++ b/src/controllers/api/streaming.ts @@ -68,28 +68,32 @@ const streamingController: AppController = (c) => { const filter = await topicToFilter(stream, c.req.query(), pubkey); if (!filter) return; - for await (const msg of Storages.pubsub.req([filter], { signal: controller.signal })) { - if (msg[0] === 'EVENT') { - const [event] = await hydrateEvents({ - events: [msg[2]], - storage: eventsDB, - signal: AbortSignal.timeout(1000), - }); + try { + for await (const msg of Storages.pubsub.req([filter], { signal: controller.signal })) { + if (msg[0] === 'EVENT') { + const [event] = await hydrateEvents({ + events: [msg[2]], + storage: eventsDB, + signal: AbortSignal.timeout(1000), + }); - if (event.kind === 1) { - const status = await renderStatus(event, { viewerPubkey: pubkey }); - if (status) { - send('update', status); + if (event.kind === 1) { + const status = await renderStatus(event, { viewerPubkey: pubkey }); + if (status) { + send('update', status); + } } - } - if (event.kind === 6) { - const status = await renderReblog(event, { viewerPubkey: pubkey }); - if (status) { - send('update', status); + if (event.kind === 6) { + const status = await renderReblog(event, { viewerPubkey: pubkey }); + if (status) { + send('update', status); + } } } } + } catch (e) { + debug('streaming error:', e); } }; diff --git a/src/controllers/nostr/relay.ts b/src/controllers/nostr/relay.ts index 6705a89f..1fa53c1f 100644 --- a/src/controllers/nostr/relay.ts +++ b/src/controllers/nostr/relay.ts @@ -77,10 +77,14 @@ function connectStream(socket: WebSocket) { send(['EOSE', subId]); - for await (const msg of Storages.pubsub.req(filters, { signal: controller.signal })) { - if (msg[0] === 'EVENT') { - send(['EVENT', subId, msg[2]]); + try { + for await (const msg of Storages.pubsub.req(filters, { signal: controller.signal })) { + if (msg[0] === 'EVENT') { + send(['EVENT', subId, msg[2]]); + } } + } catch (_e) { + controllers.delete(subId); } } diff --git a/src/utils/api.ts b/src/utils/api.ts index 79b383de..cd4e6e21 100644 --- a/src/utils/api.ts +++ b/src/utils/api.ts @@ -18,12 +18,6 @@ type EventStub = TypeFest.SetOptional { - const pubkey = c.get('pubkey'); - - if (!pubkey) { - throw new HTTPException(401); - } - const signer = new APISigner(c); const event = await signer.signEvent({