From 0158a6979ea7337dd356f02dc3a6effd6118022c Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 17 Aug 2023 20:45:50 -0500 Subject: [PATCH] Publish events through pipeline --- src/controllers/api/accounts.ts | 10 +++++++++- src/controllers/api/statuses.ts | 17 +++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/controllers/api/accounts.ts b/src/controllers/api/accounts.ts index 544447b..96b3ac2 100644 --- a/src/controllers/api/accounts.ts +++ b/src/controllers/api/accounts.ts @@ -2,11 +2,13 @@ import { type AppController } from '@/app.ts'; import { type Filter, findReplyTag, z } from '@/deps.ts'; import { publish } from '@/client.ts'; import * as mixer from '@/mixer.ts'; +import * as pipeline from '@/pipeline.ts'; import { getAuthor, getFollows } from '@/queries.ts'; import { jsonMetaContentSchema } from '@/schemas/nostr.ts'; import { signEvent } from '@/sign.ts'; import { toAccount, toStatus } from '@/transformers/nostr-to-mastoapi.ts'; import { buildLinkHeader, eventDateComparator, lookupAccount, nostrNow, paginationSchema, parseBody } from '@/utils.ts'; +import pipe from 'https://deno.land/x/ramda@v0.27.2/source/pipe.js'; const createAccountController: AppController = (c) => { return c.json({ error: 'Please log in with Nostr.' }, 405); @@ -167,7 +169,13 @@ const updateCredentialsController: AppController = async (c) => { created_at: nostrNow(), }, c); - publish(event); + try { + await pipeline.handleEvent(event); + } catch (e) { + if (e instanceof pipeline.RelayError) { + return c.json({ error: e.message }, 422); + } + } const account = await toAccount(event); return c.json(account); diff --git a/src/controllers/api/statuses.ts b/src/controllers/api/statuses.ts index 2f594ac..2a78f22 100644 --- a/src/controllers/api/statuses.ts +++ b/src/controllers/api/statuses.ts @@ -1,6 +1,7 @@ import { type AppController } from '@/app.ts'; import { publish } from '@/client.ts'; import { ISO6391, Kind, z } from '@/deps.ts'; +import * as pipeline from '@/pipeline.ts'; import { getAncestors, getDescendants, getEvent } from '@/queries.ts'; import { signEvent } from '@/sign.ts'; import { toStatus } from '@/transformers/nostr-to-mastoapi.ts'; @@ -77,7 +78,13 @@ const createStatusController: AppController = async (c) => { created_at: nostrNow(), }, c); - publish(event); + try { + await pipeline.handleEvent(event); + } catch (e) { + if (e instanceof pipeline.RelayError) { + return c.json({ error: e.message }, 422); + } + } return c.json(await toStatus(event)); } else { @@ -118,7 +125,13 @@ const favouriteController: AppController = async (c) => { created_at: nostrNow(), }, c); - publish(event); + try { + await pipeline.handleEvent(event); + } catch (e) { + if (e instanceof pipeline.RelayError) { + return c.json({ error: e.message }, 422); + } + } const status = await toStatus(target);