mirror of
https://github.com/immich-app/immich.git
synced 2025-01-04 02:46:47 +01:00
fix(server): await thumbnail generation before returning (#3975)
* await sharp command, minor fixes * removed outdated test
This commit is contained in:
parent
90f9501902
commit
04d4a30471
3 changed files with 3 additions and 8 deletions
|
@ -200,12 +200,6 @@ describe(MediaService.name, () => {
|
||||||
expect(assetMock.save).not.toHaveBeenCalledWith();
|
expect(assetMock.save).not.toHaveBeenCalledWith();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should skip thumbnail generate if resize path is missing', async () => {
|
|
||||||
assetMock.getByIds.mockResolvedValue([assetStub.noResizePath]);
|
|
||||||
await sut.handleGenerateWebpThumbnail({ id: assetStub.noResizePath.id });
|
|
||||||
expect(mediaMock.resize).not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should generate a thumbnail', async () => {
|
it('should generate a thumbnail', async () => {
|
||||||
assetMock.getByIds.mockResolvedValue([assetStub.image]);
|
assetMock.getByIds.mockResolvedValue([assetStub.image]);
|
||||||
await sut.handleGenerateWebpThumbnail({ id: assetStub.image.id });
|
await sut.handleGenerateWebpThumbnail({ id: assetStub.image.id });
|
||||||
|
|
|
@ -109,7 +109,7 @@ export class MediaService {
|
||||||
|
|
||||||
async handleGenerateWebpThumbnail({ id }: IEntityJob) {
|
async handleGenerateWebpThumbnail({ id }: IEntityJob) {
|
||||||
const [asset] = await this.assetRepository.getByIds([id]);
|
const [asset] = await this.assetRepository.getByIds([id]);
|
||||||
if (!asset || !asset.resizePath) {
|
if (!asset) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ export class MediaRepository implements IMediaRepository {
|
||||||
|
|
||||||
crop(input: string | Buffer, options: CropOptions): Promise<Buffer> {
|
crop(input: string | Buffer, options: CropOptions): Promise<Buffer> {
|
||||||
return sharp(input, { failOn: 'none' })
|
return sharp(input, { failOn: 'none' })
|
||||||
|
.pipelineColorspace('rgb16')
|
||||||
.extract({
|
.extract({
|
||||||
left: options.left,
|
left: options.left,
|
||||||
top: options.top,
|
top: options.top,
|
||||||
|
@ -38,7 +39,7 @@ export class MediaRepository implements IMediaRepository {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const chromaSubsampling = options.quality >= 80 ? '4:4:4' : '4:2:0'; // this is default in libvips (except the threshold is 90), but we need to set it manually in sharp
|
const chromaSubsampling = options.quality >= 80 ? '4:4:4' : '4:2:0'; // this is default in libvips (except the threshold is 90), but we need to set it manually in sharp
|
||||||
sharp(input, { failOn: 'none' })
|
await sharp(input, { failOn: 'none' })
|
||||||
.pipelineColorspace('rgb16')
|
.pipelineColorspace('rgb16')
|
||||||
.resize(options.size, options.size, { fit: 'outside', withoutEnlargement: true })
|
.resize(options.size, options.size, { fit: 'outside', withoutEnlargement: true })
|
||||||
.rotate()
|
.rotate()
|
||||||
|
|
Loading…
Reference in a new issue