mirror of
https://github.com/immich-app/immich.git
synced 2025-03-11 02:23:09 -05:00
change caching of profile image
This commit is contained in:
parent
fa648b1e00
commit
5874fc73ff
4 changed files with 21 additions and 1 deletions
|
@ -116,6 +116,14 @@ export class UserCore {
|
|||
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[]> {
|
||||
return this.userRepository.getList(filter);
|
||||
}
|
||||
|
|
|
@ -120,6 +120,14 @@ export class UserService {
|
|||
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>) {
|
||||
const admin = await this.userCore.getAdmin();
|
||||
if (!admin) {
|
||||
|
|
|
@ -98,10 +98,11 @@ export class UserController {
|
|||
}
|
||||
|
||||
@Get('/profile-image/:userId')
|
||||
@Header('Cache-Control', 'private, max-age=86400, no-transform')
|
||||
@Header('Cache-Control', 'private, no-cache, no-transform')
|
||||
async getProfileImage(@Param() { userId }: UserIdDto, @Response({ passthrough: true }) res: Res): Promise<any> {
|
||||
const readableStream = await this.service.getUserProfileImage(userId);
|
||||
res.header('Content-Type', 'image/jpeg');
|
||||
res.header('ETag', await this.service.getUserProfileImageHash(userId));
|
||||
return new StreamableFile(readableStream);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,6 +42,9 @@ export class UserEntity {
|
|||
@Column({ default: '' })
|
||||
profileImagePath!: string;
|
||||
|
||||
@Column({ default: '' })
|
||||
profileImageHash!: string;
|
||||
|
||||
@Column({ default: true })
|
||||
shouldChangePassword!: boolean;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue