From a3ae3e5b8ab7919b6b99d9f023138588400eb0f3 Mon Sep 17 00:00:00 2001 From: tamaina Date: Thu, 24 Jul 2025 23:39:49 +0900 Subject: [PATCH] fix models/UserPublickey.ts --- .../migration/1753322132926-ed25519.js | 20 ------------------- .../activitypub/models/ApPersonService.ts | 10 +++++++--- packages/backend/src/models/UserPublickey.ts | 4 ++-- 3 files changed, 9 insertions(+), 25 deletions(-) delete mode 100644 packages/backend/migration/1753322132926-ed25519.js diff --git a/packages/backend/migration/1753322132926-ed25519.js b/packages/backend/migration/1753322132926-ed25519.js deleted file mode 100644 index aceaf0b205..0000000000 --- a/packages/backend/migration/1753322132926-ed25519.js +++ /dev/null @@ -1,20 +0,0 @@ -/* - * SPDX-FileCopyrightText: syuilo and misskey-project - * SPDX-License-Identifier: AGPL-3.0-only - */ - -export class Ed255191753322132926 { - name = 'Ed255191753322132926' - - async up(queryRunner) { - await queryRunner.query(`ALTER TABLE "user_publickey" DROP CONSTRAINT "FK_10c146e4b39b443ede016f6736d"`); - await queryRunner.query(`ALTER TABLE "user_publickey" ADD CONSTRAINT "UQ_10c146e4b39b443ede016f6736d" UNIQUE ("userId")`); - await queryRunner.query(`ALTER TABLE "user_publickey" ADD CONSTRAINT "FK_10c146e4b39b443ede016f6736d" FOREIGN KEY ("userId") REFERENCES "user"("id") ON DELETE CASCADE ON UPDATE NO ACTION`); - } - - async down(queryRunner) { - await queryRunner.query(`ALTER TABLE "user_publickey" DROP CONSTRAINT "FK_10c146e4b39b443ede016f6736d"`); - await queryRunner.query(`ALTER TABLE "user_publickey" DROP CONSTRAINT "UQ_10c146e4b39b443ede016f6736d"`); - await queryRunner.query(`ALTER TABLE "user_publickey" ADD CONSTRAINT "FK_10c146e4b39b443ede016f6736d" FOREIGN KEY ("userId") REFERENCES "user"("id") ON DELETE CASCADE ON UPDATE NO ACTION`); - } -} diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index dd642e86e0..77d62dc54f 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -390,7 +390,7 @@ export class ApPersonService implements OnModuleInit { .then(isPublic => isPublic ? 'public' : 'private') .catch(err => { if (!(err instanceof StatusError) || err.isRetryable) { - this.logger.error('error occurred while fetching following/followers collection', { stack: err }); + this.logger.error('Create the Person: error occurred while fetching following/followers collection', { stack: err }); } return 'private'; }), @@ -416,7 +416,7 @@ export class ApPersonService implements OnModuleInit { const emojis = await this.apNoteService.extractEmojis(person.tag ?? [], host) .then(_emojis => _emojis.map(emoji => emoji.name)) .catch(err => { - this.logger.error('error occurred while fetching user emojis', { stack: err }); + this.logger.error('Create the Person: error occurred while fetching user emojis', { stack: err }); return []; }); //#endregion @@ -479,6 +479,7 @@ export class ApPersonService implements OnModuleInit { (person.additionalPublicKeys ?? []).forEach(key => publicKeys.set(key.id, key)); (Array.isArray(person.publicKey) ? person.publicKey : [person.publicKey]).forEach(key => publicKeys.set(key.id, key)); + this.logger.debug(`Create the Person: Saving public keys for user ${user.id}`, { keyIds: Array.from(publicKeys.keys()) }); await transactionalEntityManager.save(Array.from(publicKeys.values(), key => new MiUserPublickey({ keyId: key.id, userId: user!.id, @@ -491,7 +492,10 @@ export class ApPersonService implements OnModuleInit { if (isDuplicateKeyValueError(e)) { // /users/@a => /users/:id のように入力がaliasなときにエラーになることがあるのを対応 const u = await this.usersRepository.findOneBy({ uri: person.id }); - if (u == null) throw new Error('already registered'); + if (u == null) { + this.logger.error('Create the Person: duplicate key error', { stack: e }); + throw new Error('already registered'); + } user = u as MiRemoteUser; } else { diff --git a/packages/backend/src/models/UserPublickey.ts b/packages/backend/src/models/UserPublickey.ts index 0ecff2bcbe..7dc8aee5d7 100644 --- a/packages/backend/src/models/UserPublickey.ts +++ b/packages/backend/src/models/UserPublickey.ts @@ -3,7 +3,7 @@ * SPDX-License-Identifier: AGPL-3.0-only */ -import { PrimaryColumn, Entity, Index, JoinColumn, Column, OneToOne } from 'typeorm'; +import { PrimaryColumn, Entity, Index, JoinColumn, Column, ManyToOne } from 'typeorm'; import { id } from './util/id.js'; import { MiUser } from './User.js'; @@ -18,7 +18,7 @@ export class MiUserPublickey { @Column(id()) public userId: MiUser['id']; - @OneToOne(type => MiUser, { + @ManyToOne(type => MiUser, { onDelete: 'CASCADE', }) @JoinColumn()