From e73dc3dc7227bac1e1f7f0e8a2037123d824f149 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 13 Sep 2024 22:30:06 -0500 Subject: [PATCH] fix(server): fix modify date extraction (#12658) * fix(server): fix modify date extraction * add unit test --- server/src/services/metadata.service.spec.ts | 12 ++++++++++++ server/src/services/metadata.service.ts | 7 ++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/server/src/services/metadata.service.spec.ts b/server/src/services/metadata.service.spec.ts index ea7254f53f..19aaa2ea1a 100644 --- a/server/src/services/metadata.service.spec.ts +++ b/server/src/services/metadata.service.spec.ts @@ -1095,6 +1095,18 @@ describe(MetadataService.name, () => { expect(personMock.updateAll).toHaveBeenCalledWith([]); expect(jobMock.queueAll).toHaveBeenCalledWith([]); }); + + it('should handle invalid modify date', async () => { + assetMock.getByIds.mockResolvedValue([assetStub.image]); + metadataMock.readTags.mockResolvedValue({ ModifyDate: '00:00:00.000' }); + + await sut.handleMetadataExtraction({ id: assetStub.image.id }); + expect(assetMock.upsertExif).toHaveBeenCalledWith( + expect.objectContaining({ + modifyDate: expect.any(Date), + }), + ); + }); }); describe('handleQueueSidecar', () => { diff --git a/server/src/services/metadata.service.ts b/server/src/services/metadata.service.ts index 4ffbd7f09b..eaa491c3ee 100644 --- a/server/src/services/metadata.service.ts +++ b/server/src/services/metadata.service.ts @@ -629,11 +629,16 @@ export class MetadataService { this.logger.debug(`Asset ${asset.id} local time is offset by ${offsetMinutes} minutes`); } + let modifyDate = asset.fileModifiedAt; + try { + modifyDate = (exifTags.ModifyDate as ExifDateTime)?.toDate() ?? modifyDate; + } catch {} + return { dateTimeOriginal, timeZone, localDateTime, - modifyDate: (exifTags.ModifyDate as ExifDateTime)?.toDate() ?? asset.fileModifiedAt, + modifyDate, }; }