This commit is contained in:
tamaina 2024-06-11 15:50:55 +09:00
parent 133970a184
commit a3d4eae99d
1 changed files with 8 additions and 14 deletions

View File

@ -184,13 +184,10 @@ export class ApPersonService implements OnModuleInit {
throw new Error('invalid Actor: id has different host'); throw new Error('invalid Actor: id has different host');
} }
if (x.publicKey && typeof x.publicKey.id !== 'string') { if (x.publicKey) {
const publicKeyIdHost = this.punyHost(x.publicKey.id); const publicKeys = Array.isArray(x.publicKey) ? x.publicKey : [x.publicKey];
if (publicKeyIdHost !== expectHost) {
throw new Error('invalid Actor: publicKey.id has different host'); for (const publicKey of publicKeys) {
}
} else if (x.publicKey && Array.isArray(x.publicKey)) {
for (const publicKey of x.publicKey) {
if (typeof publicKey.id !== 'string') { if (typeof publicKey.id !== 'string') {
throw new Error('invalid Actor: publicKey.id is not a 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'); 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) { if (x.additionalPublicKeys) {
@ -415,10 +410,9 @@ export class ApPersonService implements OnModuleInit {
})); }));
if (person.publicKey) { if (person.publicKey) {
const publicKeys = new Map<string, IKey>([ const publicKeys = new Map<string, IKey>();
...(person.additionalPublicKeys ? person.additionalPublicKeys.map(key => [key.id, key] as const) : []), (person.additionalPublicKeys ?? []).forEach(key => publicKeys.set(key.id, key));
...(Array.isArray(person.publicKey) ? person.publicKey.map(key => [key.id, key] as const) : [[person.publicKey.id, person.publicKey]] as const), (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({ await transactionalEntityManager.save(Array.from(publicKeys.values(), key => new MiUserPublickey({
keyId: key.id, keyId: key.id,
@ -576,7 +570,7 @@ export class ApPersonService implements OnModuleInit {
const publicKeys = new Map<string, IKey>(); const publicKeys = new Map<string, IKey>();
if (person.publicKey) { if (person.publicKey) {
(person.additionalPublicKeys ?? []).forEach(key => publicKeys.set(key.id, key)); (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 => ({ await this.userPublickeysRepository.save(Array.from(publicKeys.values(), key => ({
keyId: key.id, keyId: key.id,