diff --git a/server/src/cores/storage.core.ts b/server/src/cores/storage.core.ts index 4cbf963158..b4eba7ce5e 100644 --- a/server/src/cores/storage.core.ts +++ b/server/src/cores/storage.core.ts @@ -1,5 +1,5 @@ import { randomUUID } from 'node:crypto'; -import { dirname, join, resolve } from 'node:path'; +import path, { dirname, join, resolve } from 'node:path'; import { APP_MEDIA_LOCATION } from 'src/constants'; import { AssetEntity } from 'src/entities/asset.entity'; import { PersonEntity } from 'src/entities/person.entity'; @@ -115,18 +115,21 @@ export class StorageCore { return normalizedPath.startsWith(normalizedAppMediaLocation); } - async moveAssetImage(asset: AssetEntity, pathType: GeneratedImageType, format: ImageFormat) { - const { id: entityId, files } = asset; - const oldFile = getAssetFile(files, pathType); + moveAssetImage(asset: AssetEntity, pathType: GeneratedImageType) { + const oldFile = getAssetFile(asset.files, pathType); + if (!oldFile?.path) { + return; + } + return this.moveFile({ - entityId, + entityId: asset.id, pathType, - oldPath: oldFile?.path || null, - newPath: StorageCore.getImagePath(asset, pathType, format), + oldPath: oldFile.path, + newPath: StorageCore.getImagePath(asset, pathType, path.extname(oldFile.path).slice(1) as ImageFormat), }); } - async moveAssetVideo(asset: AssetEntity) { + moveAssetVideo(asset: AssetEntity) { return this.moveFile({ entityId: asset.id, pathType: AssetPathType.ENCODED_VIDEO, diff --git a/server/src/services/media.service.spec.ts b/server/src/services/media.service.spec.ts index a754fc47d0..4fae472076 100644 --- a/server/src/services/media.service.spec.ts +++ b/server/src/services/media.service.spec.ts @@ -238,19 +238,19 @@ describe(MediaService.name, () => { entityId: assetStub.image.id, pathType: AssetPathType.FULLSIZE, oldPath: '/uploads/user-id/fullsize/path.webp', - newPath: 'upload/thumbs/user-id/as/se/asset-id-fullsize.jpeg', + newPath: 'upload/thumbs/user-id/as/se/asset-id-fullsize.webp', }); expect(mocks.move.create).toHaveBeenCalledWith({ entityId: assetStub.image.id, pathType: AssetPathType.PREVIEW, oldPath: '/uploads/user-id/thumbs/path.jpg', - newPath: 'upload/thumbs/user-id/as/se/asset-id-preview.jpeg', + newPath: 'upload/thumbs/user-id/as/se/asset-id-preview.jpg', }); expect(mocks.move.create).toHaveBeenCalledWith({ entityId: assetStub.image.id, pathType: AssetPathType.THUMBNAIL, oldPath: '/uploads/user-id/webp/path.ext', - newPath: 'upload/thumbs/user-id/as/se/asset-id-thumbnail.webp', + newPath: 'upload/thumbs/user-id/as/se/asset-id-thumbnail.ext', }); expect(mocks.move.create).toHaveBeenCalledTimes(3); }); diff --git a/server/src/services/media.service.ts b/server/src/services/media.service.ts index 5318cdc97f..a4561ce818 100644 --- a/server/src/services/media.service.ts +++ b/server/src/services/media.service.ts @@ -134,15 +134,14 @@ export class MediaService extends BaseService { @OnJob({ name: JobName.MIGRATE_ASSET, queue: QueueName.MIGRATION }) async handleAssetMigration({ id }: JobOf): Promise { - const { image } = await this.getConfig({ withCache: true }); const [asset] = await this.assetRepository.getByIds([id], { files: true }); if (!asset) { return JobStatus.FAILED; } - await this.storageCore.moveAssetImage(asset, AssetPathType.FULLSIZE, image.fullsize.format); - await this.storageCore.moveAssetImage(asset, AssetPathType.PREVIEW, image.preview.format); - await this.storageCore.moveAssetImage(asset, AssetPathType.THUMBNAIL, image.thumbnail.format); + await this.storageCore.moveAssetImage(asset, AssetPathType.FULLSIZE); + await this.storageCore.moveAssetImage(asset, AssetPathType.PREVIEW); + await this.storageCore.moveAssetImage(asset, AssetPathType.THUMBNAIL); await this.storageCore.moveAssetVideo(asset); return JobStatus.SUCCESS;