mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
actorController: refactor notFound
This commit is contained in:
parent
819ae61bca
commit
b52694679f
1 changed files with 7 additions and 5 deletions
|
|
@ -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 };
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue