Skip to content

Commit

Permalink
fix(server): fix modify date extraction (#12658)
Browse files Browse the repository at this point in the history
* fix(server): fix modify date extraction

* add unit test
  • Loading branch information
alextran1502 authored Sep 14, 2024
1 parent f22338f commit e73dc3d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
12 changes: 12 additions & 0 deletions server/src/services/metadata.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
7 changes: 6 additions & 1 deletion server/src/services/metadata.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}

Expand Down

0 comments on commit e73dc3d

Please sign in to comment.