mirror of
https://github.com/immich-app/immich.git
synced 2026-05-18 03:10:24 +03:00
fix: run profile picture through thumbnail pipeline (#27890)
* fix: run profile picture through thumbnail pipeline * fix: format
This commit is contained in:
@@ -16,7 +16,9 @@ import { UserTable } from 'src/schema/tables/user.table';
|
||||
import { BaseService } from 'src/services/base.service';
|
||||
import { JobOf, UserMetadataItem } from 'src/types';
|
||||
import { ImmichFileResponse } from 'src/utils/file';
|
||||
import { mimeTypes } from 'src/utils/mime-types';
|
||||
import { getPreferences, getPreferencesPartial, mergePreferences } from 'src/utils/preferences';
|
||||
import { generateProfileImage } from 'src/utils/profile-image';
|
||||
|
||||
@Injectable()
|
||||
export class UserService extends BaseService {
|
||||
@@ -91,16 +93,29 @@ export class UserService extends BaseService {
|
||||
}
|
||||
|
||||
async createProfileImage(auth: AuthDto, file: Express.Multer.File): Promise<CreateProfileImageResponseDto> {
|
||||
const { profileImagePath: oldpath } = await this.findOrFail(auth.user.id, { withDeleted: false });
|
||||
const { profileImagePath: oldPath } = await this.findOrFail(auth.user.id, { withDeleted: false });
|
||||
|
||||
let profileImagePath: string;
|
||||
try {
|
||||
const config = await this.getConfig({ withCache: true });
|
||||
profileImagePath = await generateProfileImage(
|
||||
{ media: this.mediaRepository, crypto: this.cryptoRepository, storageCore: this.storageCore },
|
||||
config,
|
||||
auth.user.id,
|
||||
file.path,
|
||||
);
|
||||
} catch (error) {
|
||||
await this.jobRepository.queue({ name: JobName.FileDelete, data: { files: [file.path] } });
|
||||
throw new BadRequestException('Unable to process profile image', { cause: error });
|
||||
}
|
||||
|
||||
const user = await this.userRepository.update(auth.user.id, {
|
||||
profileImagePath: file.path,
|
||||
profileImagePath,
|
||||
profileChangedAt: new Date(),
|
||||
});
|
||||
|
||||
if (oldpath !== '') {
|
||||
await this.jobRepository.queue({ name: JobName.FileDelete, data: { files: [oldpath] } });
|
||||
}
|
||||
const toDelete = [file.path, ...(oldPath ? [oldPath] : [])];
|
||||
await this.jobRepository.queue({ name: JobName.FileDelete, data: { files: toDelete } });
|
||||
|
||||
return {
|
||||
userId: user.id,
|
||||
@@ -126,7 +141,7 @@ export class UserService extends BaseService {
|
||||
|
||||
return new ImmichFileResponse({
|
||||
path: user.profileImagePath,
|
||||
contentType: 'image/jpeg',
|
||||
contentType: mimeTypes.lookup(user.profileImagePath),
|
||||
cacheControl: CacheControl.None,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user