remove unecesarry changes
This commit is contained in:
@@ -116,20 +116,13 @@ export class UserCore {
|
|||||||
return createReadStream(user.profileImagePath);
|
return createReadStream(user.profileImagePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getUserProfileImageHash(user: UserEntity): Promise<string> {
|
|
||||||
if (!user.profileImageHash) {
|
|
||||||
throw new NotFoundException('User does not have a profile image');
|
|
||||||
}
|
|
||||||
return user.profileImageHash;
|
|
||||||
}
|
|
||||||
|
|
||||||
async getList(filter?: UserListFilter): Promise<UserEntity[]> {
|
async getList(filter?: UserListFilter): Promise<UserEntity[]> {
|
||||||
return this.userRepository.getList(filter);
|
return this.userRepository.getList(filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
async createProfileImage(authUser: AuthUserDto, filePath: string, hash: string): Promise<UserEntity> {
|
async createProfileImage(authUser: AuthUserDto, filePath: string): Promise<UserEntity> {
|
||||||
try {
|
try {
|
||||||
return this.userRepository.update(authUser.id, { profileImagePath: filePath, profileImageHash: hash });
|
return this.userRepository.update(authUser.id, { profileImagePath: filePath });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
Logger.error(e, 'Create User Profile Image');
|
Logger.error(e, 'Create User Profile Image');
|
||||||
throw new InternalServerErrorException('Failed to create new user profile image');
|
throw new InternalServerErrorException('Failed to create new user profile image');
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { UserEntity } from '@app/infra/entities';
|
import { UserEntity } from '@app/infra/entities';
|
||||||
import { BadRequestException, Inject, Injectable, Logger, NotFoundException } from '@nestjs/common';
|
import { BadRequestException, Inject, Injectable, Logger, NotFoundException } from '@nestjs/common';
|
||||||
import { createHash, randomBytes } from 'crypto';
|
import { randomBytes } from 'crypto';
|
||||||
import { ReadStream } from 'fs';
|
import { ReadStream } from 'fs';
|
||||||
import { IAlbumRepository } from '../album/album.repository';
|
import { IAlbumRepository } from '../album/album.repository';
|
||||||
import { IAssetRepository } from '../asset/asset.repository';
|
import { IAssetRepository } from '../asset/asset.repository';
|
||||||
@@ -108,8 +108,7 @@ export class UserService {
|
|||||||
authUser: AuthUserDto,
|
authUser: AuthUserDto,
|
||||||
fileInfo: Express.Multer.File,
|
fileInfo: Express.Multer.File,
|
||||||
): Promise<CreateProfileImageResponseDto> {
|
): Promise<CreateProfileImageResponseDto> {
|
||||||
const hash = createHash('md5').update(fileInfo.buffer).digest('hex');
|
const updatedUser = await this.userCore.createProfileImage(authUser, fileInfo.path);
|
||||||
const updatedUser = await this.userCore.createProfileImage(authUser, fileInfo.path, hash);
|
|
||||||
return mapCreateProfileImageResponse(updatedUser.id, updatedUser.profileImagePath);
|
return mapCreateProfileImageResponse(updatedUser.id, updatedUser.profileImagePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,14 +120,6 @@ export class UserService {
|
|||||||
return this.userCore.getUserProfileImage(user);
|
return this.userCore.getUserProfileImage(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getUserProfileImageHash(userId: string): Promise<string> {
|
|
||||||
const user = await this.userCore.get(userId);
|
|
||||||
if (!user) {
|
|
||||||
throw new NotFoundException('User not found');
|
|
||||||
}
|
|
||||||
return this.userCore.getUserProfileImageHash(user);
|
|
||||||
}
|
|
||||||
|
|
||||||
async resetAdminPassword(ask: (admin: UserResponseDto) => Promise<string | undefined>) {
|
async resetAdminPassword(ask: (admin: UserResponseDto) => Promise<string | undefined>) {
|
||||||
const admin = await this.userCore.getAdmin();
|
const admin = await this.userCore.getAdmin();
|
||||||
if (!admin) {
|
if (!admin) {
|
||||||
|
|||||||
@@ -102,7 +102,6 @@ export class UserController {
|
|||||||
async getProfileImage(@Param() { userId }: UserIdDto, @Response({ passthrough: true }) res: Res): Promise<any> {
|
async getProfileImage(@Param() { userId }: UserIdDto, @Response({ passthrough: true }) res: Res): Promise<any> {
|
||||||
const readableStream = await this.service.getUserProfileImage(userId);
|
const readableStream = await this.service.getUserProfileImage(userId);
|
||||||
res.header('Content-Type', 'image/jpeg');
|
res.header('Content-Type', 'image/jpeg');
|
||||||
res.header('ETag', await this.service.getUserProfileImageHash(userId));
|
|
||||||
return new StreamableFile(readableStream);
|
return new StreamableFile(readableStream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,9 +42,6 @@ export class UserEntity {
|
|||||||
@Column({ default: '' })
|
@Column({ default: '' })
|
||||||
profileImagePath!: string;
|
profileImagePath!: string;
|
||||||
|
|
||||||
@Column({ default: '' })
|
|
||||||
profileImageHash!: string;
|
|
||||||
|
|
||||||
@Column({ default: true })
|
@Column({ default: true })
|
||||||
shouldChangePassword!: boolean;
|
shouldChangePassword!: boolean;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user