From 6ae13265fa9f55b5f565e08da090e678b5ec5fb2 Mon Sep 17 00:00:00 2001 From: Jesse Wierzbinski Date: Fri, 26 Jul 2024 00:32:33 +0200 Subject: [PATCH] feat(federation): :sparkles: Make server actor available on /users/actor --- packages/database-interface/user.ts | 2 +- server/api/users/:uuid/index.ts | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/database-interface/user.ts b/packages/database-interface/user.ts index 8fb38f2d..f7d04b8d 100644 --- a/packages/database-interface/user.ts +++ b/packages/database-interface/user.ts @@ -169,7 +169,7 @@ export class User extends BaseInterface { roles: [], sanctions: [], statusCount: 0, - uri: "", + uri: "/users/actor", }); } diff --git a/server/api/users/:uuid/index.ts b/server/api/users/:uuid/index.ts index 0b46a52d..dd2d6d63 100644 --- a/server/api/users/:uuid/index.ts +++ b/server/api/users/:uuid/index.ts @@ -21,7 +21,7 @@ export const meta = applyConfig({ export const schemas = { param: z.object({ - uuid: z.string().uuid(), + uuid: z.string().uuid().or(z.literal("actor")), }), query: z.object({ debug: z @@ -41,7 +41,10 @@ export default (app: Hono) => const { uuid } = context.req.valid("param"); const { debug } = context.req.valid("query"); - const user = await User.fromId(uuid); + const user = + uuid === "actor" + ? User.getServerActor() + : await User.fromId(uuid); if (!user) { return errorResponse("User not found", 404); @@ -61,7 +64,10 @@ export default (app: Hono) => } // Try to detect a web browser and redirect to the user's profile page - if (context.req.header("user-agent")?.includes("Mozilla")) { + if ( + context.req.header("user-agent")?.includes("Mozilla") && + uuid !== "actor" + ) { return redirect(user.toApi().url); }