actorController: refactor notFound

This commit is contained in:
Alex Gleason 2023-07-27 11:03:46 -05:00
parent 819ae61bca
commit b52694679f
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
1 changed files with 7 additions and 5 deletions

View File

@ -3,21 +3,23 @@ import { db } from '@/db.ts';
import { toActor } from '@/transformers/nostr-to-activitypub.ts'; import { toActor } from '@/transformers/nostr-to-activitypub.ts';
import { activityJson } from '@/utils.ts'; import { activityJson } from '@/utils.ts';
import type { AppController } from '@/app.ts'; import type { AppContext, AppController } from '@/app.ts';
const actorController: AppController = async (c) => { const actorController: AppController = async (c) => {
const notFound = c.json({ error: 'Not found' }, 404);
const username = c.req.param('username'); const username = c.req.param('username');
const user = await db.users.findFirst({ where: { username } }); const user = await db.users.findFirst({ where: { username } });
const event = await getAuthor(user.pubkey); const event = await getAuthor(user.pubkey);
if (!event) return notFound; if (!event) return notFound(c);
const actor = await toActor(event); const actor = await toActor(event);
if (!actor) return notFound; if (!actor) return notFound(c);
return activityJson(c, actor); return activityJson(c, actor);
}; };
function notFound(c: AppContext) {
return c.json({ error: 'Not found' }, 404);
}
export { actorController }; export { actorController };