feat(federation): Make server actor available on /users/actor

This commit is contained in:
Jesse Wierzbinski 2024-07-26 00:32:33 +02:00
parent 420a0d05dc
commit 6ae13265fa
No known key found for this signature in database
2 changed files with 10 additions and 4 deletions

View file

@ -169,7 +169,7 @@ export class User extends BaseInterface<typeof Users, UserWithRelations> {
roles: [],
sanctions: [],
statusCount: 0,
uri: "",
uri: "/users/actor",
});
}

View file

@ -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);
}