From a3d4eae99d847466fa041810c0066a284dfd32e5 Mon Sep 17 00:00:00 2001 From: tamaina Date: Tue, 11 Jun 2024 15:50:55 +0900 Subject: [PATCH] fix --- .../activitypub/models/ApPersonService.ts | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index a712ca95ca..7ff1254660 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -184,13 +184,10 @@ export class ApPersonService implements OnModuleInit { throw new Error('invalid Actor: id has different host'); } - if (x.publicKey && typeof x.publicKey.id !== 'string') { - const publicKeyIdHost = this.punyHost(x.publicKey.id); - if (publicKeyIdHost !== expectHost) { - throw new Error('invalid Actor: publicKey.id has different host'); - } - } else if (x.publicKey && Array.isArray(x.publicKey)) { - for (const publicKey of x.publicKey) { + if (x.publicKey) { + const publicKeys = Array.isArray(x.publicKey) ? x.publicKey : [x.publicKey]; + + for (const publicKey of publicKeys) { if (typeof publicKey.id !== 'string') { throw new Error('invalid Actor: publicKey.id is not a string'); } @@ -200,8 +197,6 @@ export class ApPersonService implements OnModuleInit { throw new Error('invalid Actor: publicKey.id has different host'); } } - } else if (x.publicKey) { - throw new Error('invalid Actor: publicKey is not an object or an array'); } if (x.additionalPublicKeys) { @@ -415,10 +410,9 @@ export class ApPersonService implements OnModuleInit { })); if (person.publicKey) { - const publicKeys = new Map([ - ...(person.additionalPublicKeys ? person.additionalPublicKeys.map(key => [key.id, key] as const) : []), - ...(Array.isArray(person.publicKey) ? person.publicKey.map(key => [key.id, key] as const) : [[person.publicKey.id, person.publicKey]] as const), - ]); + const publicKeys = new Map(); + (person.additionalPublicKeys ?? []).forEach(key => publicKeys.set(key.id, key)); + (Array.isArray(person.publicKey) ? person.publicKey : [person.publicKey]).forEach(key => publicKeys.set(key.id, key)); await transactionalEntityManager.save(Array.from(publicKeys.values(), key => new MiUserPublickey({ keyId: key.id, @@ -576,7 +570,7 @@ export class ApPersonService implements OnModuleInit { const publicKeys = new Map(); if (person.publicKey) { (person.additionalPublicKeys ?? []).forEach(key => publicKeys.set(key.id, key)); - publicKeys.set(person.publicKey.id, person.publicKey); + (Array.isArray(person.publicKey) ? person.publicKey : [person.publicKey]).forEach(key => publicKeys.set(key.id, key)); await this.userPublickeysRepository.save(Array.from(publicKeys.values(), key => ({ keyId: key.id,