actorController: refactor notFound
This commit is contained in:
parent
819ae61bca
commit
b52694679f
|
@ -3,21 +3,23 @@ import { db } from '@/db.ts';
|
|||
import { toActor } from '@/transformers/nostr-to-activitypub.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 notFound = c.json({ error: 'Not found' }, 404);
|
||||
|
||||
const username = c.req.param('username');
|
||||
const user = await db.users.findFirst({ where: { username } });
|
||||
|
||||
const event = await getAuthor(user.pubkey);
|
||||
if (!event) return notFound;
|
||||
if (!event) return notFound(c);
|
||||
|
||||
const actor = await toActor(event);
|
||||
if (!actor) return notFound;
|
||||
if (!actor) return notFound(c);
|
||||
|
||||
return activityJson(c, actor);
|
||||
};
|
||||
|
||||
function notFound(c: AppContext) {
|
||||
return c.json({ error: 'Not found' }, 404);
|
||||
}
|
||||
|
||||
export { actorController };
|
||||
|
|
Loading…
Reference in New Issue