diff --git a/src/controllers/api/accounts.ts b/src/controllers/api/accounts.ts index f54b339..95fe0c7 100644 --- a/src/controllers/api/accounts.ts +++ b/src/controllers/api/accounts.ts @@ -1,13 +1,11 @@ import { type AppController } from '@/app.ts'; import { type Filter, findReplyTag, z } from '@/deps.ts'; import * as mixer from '@/mixer.ts'; -import * as pipeline from '@/pipeline.ts'; import { getAuthor, getFollows, syncUser } from '@/queries.ts'; import { booleanParamSchema } from '@/schema.ts'; import { jsonMetaContentSchema } from '@/schemas/nostr.ts'; -import { signEvent } from '@/sign.ts'; import { toAccount, toRelationship, toStatus } from '@/transformers/nostr-to-mastoapi.ts'; -import { eventDateComparator, isFollowing, lookupAccount, nostrNow } from '@/utils.ts'; +import { eventDateComparator, isFollowing, lookupAccount } from '@/utils.ts'; import { buildLinkHeader, paginationSchema, parseBody } from '@/utils/web.ts'; import { createEvent } from '@/utils/web.ts'; @@ -147,21 +145,12 @@ const updateCredentialsController: AppController = async (c) => { meta.name = result.data.display_name ?? meta.name; meta.about = result.data.note ?? meta.about; - const event = await signEvent({ + const event = await createEvent({ kind: 0, content: JSON.stringify(meta), tags: [], - created_at: nostrNow(), }, c); - 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 afb049a..bb8e9d5 100644 --- a/src/controllers/api/statuses.ts +++ b/src/controllers/api/statuses.ts @@ -1,11 +1,8 @@ import { type AppController } from '@/app.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'; -import { nostrNow } from '@/utils.ts'; -import { parseBody } from '@/utils/web.ts'; +import { createEvent, parseBody } from '@/utils/web.ts'; const createStatusSchema = z.object({ in_reply_to_id: z.string().regex(/[0-9a-f]{64}/).nullish(), @@ -71,21 +68,12 @@ const createStatusController: AppController = async (c) => { tags.push(['subject', data.spoiler_text]); } - const event = await signEvent({ + const event = await createEvent({ kind: Kind.Text, content: data.status ?? '', tags, - created_at: nostrNow(), }, c); - 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 { return c.json({ error: 'Bad request', schema: result.error }, 400); @@ -115,24 +103,15 @@ const favouriteController: AppController = async (c) => { const target = await getEvent(id, { kind: 1 }); if (target) { - const event = await signEvent({ + await createEvent({ kind: Kind.Reaction, content: '+', tags: [ ['e', target.id], ['p', target.pubkey], ], - created_at: nostrNow(), }, c); - try { - await pipeline.handleEvent(event); - } catch (e) { - if (e instanceof pipeline.RelayError) { - return c.json({ error: e.message }, 422); - } - } - const status = await toStatus(target); if (status) { diff --git a/src/utils/web.ts b/src/utils/web.ts index 5df153e..1504614 100644 --- a/src/utils/web.ts +++ b/src/utils/web.ts @@ -7,7 +7,10 @@ import { nostrNow } from '@/utils.ts'; import type { AppContext } from '@/app.ts'; /** Publish an event through the API, throwing a Hono exception on failure. */ -async function createEvent(t: Omit, 'created_at'>, c: AppContext) { +async function createEvent( + t: Omit, 'created_at'>, + c: AppContext, +): Promise> { const pubkey = c.get('pubkey'); if (!pubkey) {