From 5b7b8503cd4f1b76b65d18b8f291e10db12143b3 Mon Sep 17 00:00:00 2001 From: tamaina Date: Mon, 26 Feb 2024 21:27:50 +0000 Subject: [PATCH] =?UTF-8?q?getAuthUserFromApId=E3=81=AFmain=E3=82=92?= =?UTF-8?q?=E9=81=B8=E3=81=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/activitypub/ApDbResolverService.ts | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/core/activitypub/ApDbResolverService.ts b/packages/backend/src/core/activitypub/ApDbResolverService.ts index 6cce3951bd..fe211157b9 100644 --- a/packages/backend/src/core/activitypub/ApDbResolverService.ts +++ b/packages/backend/src/core/activitypub/ApDbResolverService.ts @@ -152,17 +152,36 @@ export class ApDbResolverService implements OnApplicationShutdown { @bindThis public async getAuthUserFromApId(uri: string): Promise<{ user: MiRemoteUser; - key: MiUserPublickey[] | null; + key: MiUserPublickey | null; } | null> { const user = await this.apPersonService.resolvePerson(uri) as MiRemoteUser; if (user.isDeleted) return null; - const key = await this.publicKeyByUserIdCache.fetch( + const keys = await this.publicKeyByUserIdCache.fetch( user.id, () => this.userPublickeysRepository.find({ where: { userId: user.id } }), v => v != null, ); + if (keys == null || keys.length === 8) return null; + + // 公開鍵は複数あるが、mainっぽいのを選ぶ + const key = keys.length === 1 ? + keys[0] : + keys.find(x => { + try { + const url = new URL(x.keyId); + if ( + url.hash.toLowerCase().includes('main') || + url.pathname.split('/').pop()?.toLowerCase().includes('main') + ) { + return true; + } + } catch { /* noop */ } + + return false; + }) ?? keys[0]; + return { user, key,