From eb9481b668645a5838a15de18b57dbf713628538 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 11 Apr 2023 20:28:25 -0500 Subject: [PATCH] fix(server): generate thumbnail job uses stale path (#2236) * fix(server): generate thumbnail job' using stale path * add query for webp generation * revert query for webp because it happens after files are moved * Add log info --- server/libs/domain/src/media/media.service.spec.ts | 6 +++++- server/libs/domain/src/media/media.service.ts | 10 +++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/server/libs/domain/src/media/media.service.spec.ts b/server/libs/domain/src/media/media.service.spec.ts index 81b55638f..069758177 100644 --- a/server/libs/domain/src/media/media.service.spec.ts +++ b/server/libs/domain/src/media/media.service.spec.ts @@ -79,6 +79,7 @@ describe(MediaService.name, () => { describe('handleGenerateJpegThumbnail', () => { it('should generate a thumbnail for an image', async () => { + assetMock.getByIds.mockResolvedValue([assetEntityStub.image]); await sut.handleGenerateJpegThumbnail({ asset: _.cloneDeep(assetEntityStub.image) }); expect(storageMock.mkdirSync).toHaveBeenCalledWith('upload/thumbs/user-id'); @@ -94,6 +95,7 @@ describe(MediaService.name, () => { }); it('should generate a thumbnail for an image from exif', async () => { + assetMock.getByIds.mockResolvedValue([assetEntityStub.image]); mediaMock.resize.mockRejectedValue(new Error('unsupported format')); await sut.handleGenerateJpegThumbnail({ asset: _.cloneDeep(assetEntityStub.image) }); @@ -114,6 +116,7 @@ describe(MediaService.name, () => { }); it('should generate a thumbnail for a video', async () => { + assetMock.getByIds.mockResolvedValue([assetEntityStub.video]); await sut.handleGenerateJpegThumbnail({ asset: _.cloneDeep(assetEntityStub.video) }); expect(storageMock.mkdirSync).toHaveBeenCalledWith('upload/thumbs/user-id'); @@ -130,7 +133,7 @@ describe(MediaService.name, () => { it('should queue some jobs', async () => { const asset = _.cloneDeep(assetEntityStub.image); - + assetMock.getByIds.mockResolvedValue([asset]); await sut.handleGenerateJpegThumbnail({ asset }); expect(jobMock.queue).toHaveBeenCalledWith({ name: JobName.GENERATE_WEBP_THUMBNAIL, data: { asset } }); @@ -140,6 +143,7 @@ describe(MediaService.name, () => { }); it('should log an error', async () => { + assetMock.getByIds.mockResolvedValue([assetEntityStub.image]); mediaMock.resize.mockRejectedValue(new Error('unsupported format')); mediaMock.extractThumbnailFromExif.mockRejectedValue(new Error('unsupported format')); diff --git a/server/libs/domain/src/media/media.service.ts b/server/libs/domain/src/media/media.service.ts index c32e8376f..81cae61fd 100644 --- a/server/libs/domain/src/media/media.service.ts +++ b/server/libs/domain/src/media/media.service.ts @@ -43,7 +43,14 @@ export class MediaService { } async handleGenerateJpegThumbnail(data: IAssetJob): Promise { - const { asset } = data; + const [asset] = await this.assetRepository.getByIds([data.asset.id]); + + if (!asset) { + this.logger.warn( + `Asset not found: ${data.asset.id} - Original Path: ${data.asset.originalPath} - Resize Path: ${data.asset.resizePath}`, + ); + return; + } try { const resizePath = this.storageCore.getFolderLocation(StorageFolder.THUMBNAILS, asset.ownerId); @@ -122,6 +129,7 @@ export class MediaService { const [asset] = await this.assetRepository.getByIds([job.asset.id]); if (!asset) { + this.logger.warn(`Asset not found: ${job.asset.id} - Original Path: ${job.asset.originalPath}`); return; }