From cc70f5f6a0a5c7128ea0983056b7116bee3edbda Mon Sep 17 00:00:00 2001 From: Daniel Dietzler <36593685+danieldietzler@users.noreply.github.com> Date: Wed, 27 Sep 2023 21:29:07 +0200 Subject: [PATCH] fix(server): Thumbnail migration creating unnecessary directories (#4251) * fix: during migration folders will be created before checking if needed * refactor --- server/src/domain/media/media.service.ts | 30 ++++++++++++++---------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/server/src/domain/media/media.service.ts b/server/src/domain/media/media.service.ts index 9e2ae8eb40..f836026de5 100644 --- a/server/src/domain/media/media.service.ts +++ b/server/src/domain/media/media.service.ts @@ -98,23 +98,29 @@ export class MediaService { if (!asset) { return false; } - const resizePath = this.ensureThumbnailPath(asset, 'jpeg'); - const webpPath = this.ensureThumbnailPath(asset, 'webp'); - const encodedVideoPath = this.ensureEncodedVideoPath(asset, 'mp4'); - if (asset.resizePath && asset.resizePath !== resizePath) { - await this.storageRepository.moveFile(asset.resizePath, resizePath); - await this.assetRepository.save({ id: asset.id, resizePath }); + if (asset.resizePath) { + const resizePath = this.ensureThumbnailPath(asset, 'jpeg'); + if (asset.resizePath !== resizePath) { + await this.storageRepository.moveFile(asset.resizePath, resizePath); + await this.assetRepository.save({ id: asset.id, resizePath }); + } } - if (asset.webpPath && asset.webpPath !== webpPath) { - await this.storageRepository.moveFile(asset.webpPath, webpPath); - await this.assetRepository.save({ id: asset.id, webpPath }); + if (asset.webpPath) { + const webpPath = this.ensureThumbnailPath(asset, 'webp'); + if (asset.webpPath !== webpPath) { + await this.storageRepository.moveFile(asset.webpPath, webpPath); + await this.assetRepository.save({ id: asset.id, webpPath }); + } } - if (asset.encodedVideoPath && asset.encodedVideoPath !== encodedVideoPath) { - await this.storageRepository.moveFile(asset.encodedVideoPath, encodedVideoPath); - await this.assetRepository.save({ id: asset.id, encodedVideoPath }); + if (asset.encodedVideoPath) { + const encodedVideoPath = this.ensureEncodedVideoPath(asset, 'mp4'); + if (asset.encodedVideoPath !== encodedVideoPath) { + await this.storageRepository.moveFile(asset.encodedVideoPath, encodedVideoPath); + await this.assetRepository.save({ id: asset.id, encodedVideoPath }); + } } return true;