From a037a6656cd0234808f676a94bcd539115e1a6dd Mon Sep 17 00:00:00 2001 From: pen <121443048+penginn-net@users.noreply.github.com> Date: Fri, 29 Nov 2024 07:13:36 +0900 Subject: [PATCH] =?UTF-8?q?Enhance:=20`/users/${id}`=E3=81=AB`Accept:=20ap?= =?UTF-8?q?plication/ld+json`=E3=81=A7=E3=81=AF=E3=81=AA=E3=81=84=E3=83=AA?= =?UTF-8?q?=E3=82=AF=E3=82=A8=E3=82=B9=E3=83=88=E3=81=8C=E6=9D=A5=E3=81=9F?= =?UTF-8?q?=E3=81=A8=E3=81=8D`/@${username}`=E3=81=AB=E3=83=AA=E3=83=80?= =?UTF-8?q?=E3=82=A4=E3=83=AC=E3=82=AF=E3=83=88=E3=81=99=E3=82=8B=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB=20(#554)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG_YOJO.md | 5 +++++ .../backend/src/server/ActivityPubServerService.ts | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/CHANGELOG_YOJO.md b/CHANGELOG_YOJO.md index e3acb962dd..af943b1e3f 100644 --- a/CHANGELOG_YOJO.md +++ b/CHANGELOG_YOJO.md @@ -1,3 +1,8 @@ +## 1.2.0 + +### Server +- Enhance: `/users/${id}`に`Accept: application/ld+json`ではないリクエストが来たとき`/@${username}`にリダイレクトするように [#554](https://github.com/yojo-art/cherrypick/pull/554) + ## 1.1.0 Cherrypick 4.11.1 diff --git a/packages/backend/src/server/ActivityPubServerService.ts b/packages/backend/src/server/ActivityPubServerService.ts index 365207b34d..cb915faf88 100644 --- a/packages/backend/src/server/ActivityPubServerService.ts +++ b/packages/backend/src/server/ActivityPubServerService.ts @@ -667,6 +667,20 @@ export class ActivityPubServerService { return await this.userInfo(request, reply, user); }); + fastify.get<{ Params: { user: string; } }>('/users/:user', { constraints: { apOrHtml: 'html' } }, async (request, reply) => { + vary(reply.raw, 'Accept'); + + const userId = request.params.user; + + const user = await this.usersRepository.findOneBy({ + id: userId, + host: IsNull(), + isSuspended: false, + }); + if (user) reply.redirect(`/@${user.username}`); + reply.code(404); + }); + fastify.get<{ Params: { user: string; } }>('/@:user', { constraints: { apOrHtml: 'ap' } }, async (request, reply) => { vary(reply.raw, 'Accept');