* enhance(backend) : リモートユーザーの照会をオリジナルにリダイレクトするように (#12892) * オリジンリダイレクトのテストをtodoとして追加。 e2eテストにリモートユーザー考慮のテストがなさそうなので。 次のコマンドで動くことは確認済みです。 curl "http://localhost:3000/@foo@bar" -H "accept: application/activity+json" -L * Acctのパースを既存のパーサーでするように修正 * lint
This commit is contained in:
		| @@ -29,6 +29,7 @@ import { UserEntityService } from '@/core/entities/UserEntityService.js'; | ||||
| import { bindThis } from '@/decorators.js'; | ||||
| import { IActivity } from '@/core/activitypub/type.js'; | ||||
| import { isQuote, isRenote } from '@/misc/is-renote.js'; | ||||
| import * as Acct from '@/misc/acct.js'; | ||||
| import type { FastifyInstance, FastifyRequest, FastifyReply, FastifyPluginOptions, FastifyBodyParser } from 'fastify'; | ||||
| import type { FindOptionsWhere } from 'typeorm'; | ||||
|  | ||||
| @@ -486,6 +487,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 +665,20 @@ 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 acct = Acct.parse(request.params.acct); | ||||
|  | ||||
| 			const user = await this.usersRepository.findOneBy({ | ||||
| 				usernameLower: request.params.user.toLowerCase(), | ||||
| 				host: IsNull(), | ||||
| 				usernameLower: acct.username, | ||||
| 				host: acct.host ?? IsNull(), | ||||
| 				isSuspended: false, | ||||
| 			}); | ||||
|  | ||||
|   | ||||
| @@ -230,6 +230,7 @@ describe('Webリソース', () => { | ||||
| 				path: path('xxxxxxxxxx'), | ||||
| 				type: HTML, | ||||
| 			})); | ||||
| 			test.todo('HTMLとしてGETできる。(リモートユーザーでもリダイレクトせず)'); | ||||
| 		}); | ||||
|  | ||||
| 		describe.each([ | ||||
| @@ -249,6 +250,7 @@ describe('Webリソース', () => { | ||||
| 				path: path('xxxxxxxxxx'), | ||||
| 				accept, | ||||
| 			})); | ||||
| 			test.todo('はオリジナルにリダイレクトされる。(リモートユーザー)'); | ||||
| 		}); | ||||
| 	}); | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 momoirodouhu
					momoirodouhu