From 8725656fd299a9f373febf442e6369ae541ebe9a Mon Sep 17 00:00:00 2001 From: Michel Heusschen <59014050+michelheusschen@users.noreply.github.com> Date: Tue, 23 Jul 2024 13:59:46 +0200 Subject: [PATCH] fix(server): DateTimeOriginal overwrite issue with sidecar file (#11306) * fix(server): DateTimeOriginal overwrite issue with sidecar file * update unit test --- e2e/src/api/specs/asset.e2e-spec.ts | 38 ++++++++++++++++++++ e2e/src/utils.ts | 13 +++++-- server/src/services/metadata.service.spec.ts | 2 +- server/src/services/metadata.service.ts | 2 +- 4 files changed, 50 insertions(+), 5 deletions(-) diff --git a/e2e/src/api/specs/asset.e2e-spec.ts b/e2e/src/api/specs/asset.e2e-spec.ts index a5ba40e148..df6018b299 100644 --- a/e2e/src/api/specs/asset.e2e-spec.ts +++ b/e2e/src/api/specs/asset.e2e-spec.ts @@ -472,6 +472,44 @@ describe('/asset', () => { expect(status).toEqual(200); }); + it('should update date time original when sidecar file contains DateTimeOriginal', async () => { + const sidecarData = ` + + + + 0220 2024-07-11T10:32:52Z + 2.3.0.0 + + + +`; + + const { id } = await utils.createAsset(user1.accessToken, { + sidecarData: { + bytes: Buffer.from(sidecarData), + filename: 'example.xmp', + }, + }); + await utils.waitForQueueFinish(admin.accessToken, 'metadataExtraction'); + + const assetInfo = await utils.getAssetInfo(user1.accessToken, id); + expect(assetInfo.exifInfo?.dateTimeOriginal).toBe('2024-07-11T10:32:52.000Z'); + + const { status, body } = await request(app) + .put(`/assets/${id}`) + .set('Authorization', `Bearer ${user1.accessToken}`) + .send({ dateTimeOriginal: '2023-11-19T18:11:00.000-07:00' }); + + expect(body).toMatchObject({ + id, + exifInfo: expect.objectContaining({ + dateTimeOriginal: '2023-11-20T01:11:00.000Z', + }), + }); + expect(status).toEqual(200); + }); + it('should reject invalid gps coordinates', async () => { for (const test of [ { latitude: 12 }, diff --git a/e2e/src/utils.ts b/e2e/src/utils.ts index 440685c030..3acfc6f67c 100644 --- a/e2e/src/utils.ts +++ b/e2e/src/utils.ts @@ -50,7 +50,7 @@ type CommandResponse = { stdout: string; stderr: string; exitCode: number | null type EventType = 'assetUpload' | 'assetUpdate' | 'assetDelete' | 'userDelete' | 'assetHidden'; type WaitOptions = { event: EventType; id?: string; total?: number; timeout?: number }; type AdminSetupOptions = { onboarding?: boolean }; -type AssetData = { bytes?: Buffer; filename: string }; +type FileData = { bytes?: Buffer; filename: string }; const dbUrl = 'postgres://postgres:postgres@127.0.0.1:5433/immich'; export const baseUrl = 'http://127.0.0.1:2283'; @@ -291,7 +291,10 @@ export const utils = { createAsset: async ( accessToken: string, - dto?: Partial> & { assetData?: AssetData }, + dto?: Partial> & { + assetData?: FileData; + sidecarData?: FileData; + }, ) => { const _dto = { deviceAssetId: 'test-1', @@ -313,6 +316,10 @@ export const utils = { .attach('assetData', assetData, filename) .set('Authorization', `Bearer ${accessToken}`); + if (dto?.sidecarData?.bytes) { + void builder.attach('sidecarData', dto.sidecarData.bytes, dto.sidecarData.filename); + } + for (const [key, value] of Object.entries(_dto)) { void builder.field(key, String(value)); } @@ -325,7 +332,7 @@ export const utils = { replaceAsset: async ( accessToken: string, assetId: string, - dto?: Partial> & { assetData?: AssetData }, + dto?: Partial> & { assetData?: FileData }, ) => { const _dto = { deviceAssetId: 'test-1', diff --git a/server/src/services/metadata.service.spec.ts b/server/src/services/metadata.service.spec.ts index 9b0aed3546..956b45e214 100644 --- a/server/src/services/metadata.service.spec.ts +++ b/server/src/services/metadata.service.spec.ts @@ -911,7 +911,7 @@ describe(MetadataService.name, () => { expect(metadataMock.writeTags).toHaveBeenCalledWith(assetStub.sidecar.sidecarPath, { Description: description, ImageDescription: description, - CreationDate: date, + DateTimeOriginal: date, GPSLatitude: gps, GPSLongitude: gps, }); diff --git a/server/src/services/metadata.service.ts b/server/src/services/metadata.service.ts index bb6018459a..5b64bb4364 100644 --- a/server/src/services/metadata.service.ts +++ b/server/src/services/metadata.service.ts @@ -316,7 +316,7 @@ export class MetadataService implements OnEvents { { Description: description, ImageDescription: description, - CreationDate: dateTimeOriginal, + DateTimeOriginal: dateTimeOriginal, GPSLatitude: latitude, GPSLongitude: longitude, },