mirror of
https://github.com/immich-app/immich.git
synced 2025-05-24 01:12:58 -04:00
preserve file extension
This commit is contained in:
parent
0da1c3b279
commit
b803a35bdc
@ -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,
|
||||
|
@ -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);
|
||||
});
|
||||
|
@ -134,15 +134,14 @@ export class MediaService extends BaseService {
|
||||
|
||||
@OnJob({ name: JobName.MIGRATE_ASSET, queue: QueueName.MIGRATION })
|
||||
async handleAssetMigration({ id }: JobOf<JobName.MIGRATE_ASSET>): Promise<JobStatus> {
|
||||
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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user