Skip to content

Commit

Permalink
enhance(server): make identicon same between local and remote
Browse files Browse the repository at this point in the history
Resolve #10200
  • Loading branch information
syuilo committed Mar 5, 2023
1 parent ba2630c commit b9a3b2c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ You should also include the user name that made the change.
### Improvements
- クリップ、チャンネルページに共有ボタンを追加
- ドライブの「URLからアップロード」で、content-dispositionのfilenameがあればそれをファイル名に
- Identiconがローカルとリモートで同じになるように
- サーバーのパフォーマンスを改善

### Bugfixes
Expand Down
14 changes: 7 additions & 7 deletions packages/backend/src/core/entities/UserEntityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,27 +278,27 @@ export class UserEntityService implements OnModuleInit {
@bindThis
public async getAvatarUrl(user: User): Promise<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 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<ExpectsMe extends boolean | null = null, D extends boolean = false>(
Expand Down

0 comments on commit b9a3b2c

Please sign in to comment.