From b9a3b2c165124b52d41412b4378d892ae6079d27 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 5 Mar 2023 11:09:55 +0900 Subject: [PATCH] enhance(server): make identicon same between local and remote Resolve #10200 --- CHANGELOG.md | 1 + .../backend/src/core/entities/UserEntityService.ts | 14 +++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a1b7a2a3..f79acfb90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ You should also include the user name that made the change. ### Improvements - クリップ、チャンネルページに共有ボタンを追加 - ドライブの「URLからアップロード」で、content-dispositionのfilenameがあればそれをファイル名に +- Identiconがローカルとリモートで同じになるように - サーバーのパフォーマンスを改善 ### Bugfixes diff --git a/packages/backend/src/core/entities/UserEntityService.ts b/packages/backend/src/core/entities/UserEntityService.ts index 8c36e47f1..78129d32a 100644 --- a/packages/backend/src/core/entities/UserEntityService.ts +++ b/packages/backend/src/core/entities/UserEntityService.ts @@ -278,27 +278,27 @@ export class UserEntityService implements OnModuleInit { @bindThis public async getAvatarUrl(user: User): Promise { if (user.avatar) { - return this.driveFileEntityService.getPublicUrl(user.avatar, 'avatar') ?? this.getIdenticonUrl(user.id); + return this.driveFileEntityService.getPublicUrl(user.avatar, 'avatar') ?? this.getIdenticonUrl(user); } else if (user.avatarId) { const avatar = await this.driveFilesRepository.findOneByOrFail({ id: user.avatarId }); - return this.driveFileEntityService.getPublicUrl(avatar, 'avatar') ?? this.getIdenticonUrl(user.id); + return this.driveFileEntityService.getPublicUrl(avatar, 'avatar') ?? this.getIdenticonUrl(user); } else { - return this.getIdenticonUrl(user.id); + return this.getIdenticonUrl(user); } } @bindThis public getAvatarUrlSync(user: User): string { if (user.avatar) { - return this.driveFileEntityService.getPublicUrl(user.avatar, 'avatar') ?? this.getIdenticonUrl(user.id); + return this.driveFileEntityService.getPublicUrl(user.avatar, 'avatar') ?? this.getIdenticonUrl(user); } else { - return this.getIdenticonUrl(user.id); + return this.getIdenticonUrl(user); } } @bindThis - public getIdenticonUrl(userId: User['id']): string { - return `${this.config.url}/identicon/${userId}`; + public getIdenticonUrl(user: User): string { + return `${this.config.url}/identicon/${user.usernameLower}@${user.host ?? this.config.host}`; } public async pack(