From 1356ef425f1d6d3ea1e7775057318d64dd57be58 Mon Sep 17 00:00:00 2001 From: momoirodouhu Date: Wed, 6 Nov 2024 14:45:29 +0000 Subject: [PATCH] =?UTF-8?q?enhance(backend)=20:=20=E3=83=AA=E3=83=A2?= =?UTF-8?q?=E3=83=BC=E3=83=88=E3=83=A6=E3=83=BC=E3=82=B6=E3=83=BC=E3=81=AE?= =?UTF-8?q?=E7=85=A7=E4=BC=9A=E3=82=92=E3=82=AA=E3=83=AA=E3=82=B8=E3=83=8A?= =?UTF-8?q?=E3=83=AB=E3=81=AB=E3=83=AA=E3=83=80=E3=82=A4=E3=83=AC=E3=82=AF?= =?UTF-8?q?=E3=83=88=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=20(#1289?= =?UTF-8?q?2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + .../src/server/ActivityPubServerService.ts | 26 ++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0309f338f1..6c1d07d9a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ (Cherry-picked from https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/706) - Fix: 連合への配信時に、acctの大小文字が区別されてしまい正しくメンションが処理されないことがある問題を修正 (Cherry-picked from https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/711) +- Enhance: リモートユーザーの照会をオリジナルにリダイレクトするように ### Misskey.js - Fix: Stream初期化時、別途WebSocketを指定する場合の型定義を修正 diff --git a/packages/backend/src/server/ActivityPubServerService.ts b/packages/backend/src/server/ActivityPubServerService.ts index 3255d64621..4373676b90 100644 --- a/packages/backend/src/server/ActivityPubServerService.ts +++ b/packages/backend/src/server/ActivityPubServerService.ts @@ -486,6 +486,16 @@ export class ActivityPubServerService { return; } + // リモートだったらリダイレクト + if (user.host != null) { + if (user.uri == null || this.utilityService.isSelfHost(user.host)) { + reply.code(500); + return; + } + reply.redirect(user.uri, 301); + return; + } + reply.header('Cache-Control', 'public, max-age=180'); this.setResponseType(request, reply); return (this.apRendererService.addContext(await this.apRendererService.renderPerson(user as MiLocalUser))); @@ -654,19 +664,27 @@ export class ActivityPubServerService { const user = await this.usersRepository.findOneBy({ id: userId, - host: IsNull(), isSuspended: false, }); return await this.userInfo(request, reply, user); }); - fastify.get<{ Params: { user: string; } }>('/@:user', { constraints: { apOrHtml: 'ap' } }, async (request, reply) => { + fastify.get<{ Params: { acct: string; } }>('/@:acct', { constraints: { apOrHtml: 'ap' } }, async (request, reply) => { vary(reply.raw, 'Accept'); + const spritedAcct = request.params.acct.toLowerCase().split('@'); + + //@foo@bar@baz なんてないはず + if (spritedAcct.length > 2) { + reply.code(400); + } + + console.log(spritedAcct); + const user = await this.usersRepository.findOneBy({ - usernameLower: request.params.user.toLowerCase(), - host: IsNull(), + usernameLower: spritedAcct[0], + host: spritedAcct[1] ?? IsNull(), isSuspended: false, });