Publish events through pipeline

This commit is contained in:
Alex Gleason 2023-08-17 20:45:50 -05:00
parent 85345bc157
commit 0158a6979e
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
2 changed files with 24 additions and 3 deletions

View File

@ -2,11 +2,13 @@ import { type AppController } from '@/app.ts';
import { type Filter, findReplyTag, z } from '@/deps.ts'; import { type Filter, findReplyTag, z } from '@/deps.ts';
import { publish } from '@/client.ts'; import { publish } from '@/client.ts';
import * as mixer from '@/mixer.ts'; import * as mixer from '@/mixer.ts';
import * as pipeline from '@/pipeline.ts';
import { getAuthor, getFollows } from '@/queries.ts'; import { getAuthor, getFollows } from '@/queries.ts';
import { jsonMetaContentSchema } from '@/schemas/nostr.ts'; import { jsonMetaContentSchema } from '@/schemas/nostr.ts';
import { signEvent } from '@/sign.ts'; import { signEvent } from '@/sign.ts';
import { toAccount, toStatus } from '@/transformers/nostr-to-mastoapi.ts'; import { toAccount, toStatus } from '@/transformers/nostr-to-mastoapi.ts';
import { buildLinkHeader, eventDateComparator, lookupAccount, nostrNow, paginationSchema, parseBody } from '@/utils.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) => { const createAccountController: AppController = (c) => {
return c.json({ error: 'Please log in with Nostr.' }, 405); return c.json({ error: 'Please log in with Nostr.' }, 405);
@ -167,7 +169,13 @@ const updateCredentialsController: AppController = async (c) => {
created_at: nostrNow(), created_at: nostrNow(),
}, c); }, 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); const account = await toAccount(event);
return c.json(account); return c.json(account);

View File

@ -1,6 +1,7 @@
import { type AppController } from '@/app.ts'; import { type AppController } from '@/app.ts';
import { publish } from '@/client.ts'; import { publish } from '@/client.ts';
import { ISO6391, Kind, z } from '@/deps.ts'; import { ISO6391, Kind, z } from '@/deps.ts';
import * as pipeline from '@/pipeline.ts';
import { getAncestors, getDescendants, getEvent } from '@/queries.ts'; import { getAncestors, getDescendants, getEvent } from '@/queries.ts';
import { signEvent } from '@/sign.ts'; import { signEvent } from '@/sign.ts';
import { toStatus } from '@/transformers/nostr-to-mastoapi.ts'; import { toStatus } from '@/transformers/nostr-to-mastoapi.ts';
@ -77,7 +78,13 @@ const createStatusController: AppController = async (c) => {
created_at: nostrNow(), created_at: nostrNow(),
}, c); }, 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)); return c.json(await toStatus(event));
} else { } else {
@ -118,7 +125,13 @@ const favouriteController: AppController = async (c) => {
created_at: nostrNow(), created_at: nostrNow(),
}, c); }, 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); const status = await toStatus(target);