From 041a8ad1d1fc55bb34d351470e4b072157168d16 Mon Sep 17 00:00:00 2001 From: Paul Paffe Date: Thu, 6 Jul 2023 14:29:16 -0400 Subject: [PATCH] set hash after profile image change --- server/src/domain/user/user.core.ts | 9 ++++----- server/src/domain/user/user.service.ts | 5 +++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/server/src/domain/user/user.core.ts b/server/src/domain/user/user.core.ts index 915830fd09..2f7b0c61fb 100644 --- a/server/src/domain/user/user.core.ts +++ b/server/src/domain/user/user.core.ts @@ -120,17 +120,16 @@ export class UserCore { if (!user.profileImageHash) { throw new NotFoundException('User does not have a profile image'); } - return user.profileImageHash; - - + return user.profileImageHash; + } async getList(filter?: UserListFilter): Promise { return this.userRepository.getList(filter); } - async createProfileImage(authUser: AuthUserDto, filePath: string): Promise { + async createProfileImage(authUser: AuthUserDto, filePath: string, hash: string): Promise { try { - return this.userRepository.update(authUser.id, { profileImagePath: filePath }); + return this.userRepository.update(authUser.id, { profileImagePath: filePath, profileImageHash: hash }); } catch (e) { Logger.error(e, 'Create User Profile Image'); throw new InternalServerErrorException('Failed to create new user profile image'); diff --git a/server/src/domain/user/user.service.ts b/server/src/domain/user/user.service.ts index a45cde019c..723bfdfdc5 100644 --- a/server/src/domain/user/user.service.ts +++ b/server/src/domain/user/user.service.ts @@ -1,6 +1,6 @@ import { UserEntity } from '@app/infra/entities'; import { BadRequestException, Inject, Injectable, Logger, NotFoundException } from '@nestjs/common'; -import { randomBytes } from 'crypto'; +import { createHash, randomBytes } from 'crypto'; import { ReadStream } from 'fs'; import { IAlbumRepository } from '../album/album.repository'; import { IAssetRepository } from '../asset/asset.repository'; @@ -108,7 +108,8 @@ export class UserService { authUser: AuthUserDto, fileInfo: Express.Multer.File, ): Promise { - const updatedUser = await this.userCore.createProfileImage(authUser, fileInfo.path); + const hash = createHash('md5').update(fileInfo.buffer).digest('hex'); + const updatedUser = await this.userCore.createProfileImage(authUser, fileInfo.path, hash); return mapCreateProfileImageResponse(updatedUser.id, updatedUser.profileImagePath); }