mirror of
https://github.com/immich-app/immich.git
synced 2026-02-10 03:38:54 +03:00
set hash after profile image change
This commit is contained in:
@@ -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<UserEntity[]> {
|
||||
return this.userRepository.getList(filter);
|
||||
}
|
||||
|
||||
async createProfileImage(authUser: AuthUserDto, filePath: string): Promise<UserEntity> {
|
||||
async createProfileImage(authUser: AuthUserDto, filePath: string, hash: string): Promise<UserEntity> {
|
||||
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');
|
||||
|
||||
@@ -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<CreateProfileImageResponseDto> {
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user