1
0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2024-12-28 22:51:59 +00:00

fix(server): exif description whitespace handling (#11249)

* fix(server): exif description whitespace handling

* remove trim optional chaining
This commit is contained in:
Michel Heusschen 2024-07-22 01:01:14 +02:00 committed by GitHub
parent 1e8806854d
commit 8b773a2b2e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 23 additions and 1 deletions

View file

@ -710,6 +710,26 @@ describe(MetadataService.name, () => {
}), }),
); );
}); });
it('trims whitespace from description', async () => {
assetMock.getByIds.mockResolvedValue([assetStub.image]);
metadataMock.readTags.mockResolvedValue({ Description: '\t \v \f \n \r' });
await sut.handleMetadataExtraction({ id: assetStub.image.id });
expect(assetMock.upsertExif).toHaveBeenCalledWith(
expect.objectContaining({
description: '',
}),
);
metadataMock.readTags.mockResolvedValue({ ImageDescription: ' my\n description' });
await sut.handleMetadataExtraction({ id: assetStub.image.id });
expect(assetMock.upsertExif).toHaveBeenCalledWith(
expect.objectContaining({
description: 'my\n description',
}),
);
});
}); });
describe('handleQueueSidecar', () => { describe('handleQueueSidecar', () => {
@ -889,6 +909,7 @@ describe(MetadataService.name, () => {
}), }),
).resolves.toBe(JobStatus.SUCCESS); ).resolves.toBe(JobStatus.SUCCESS);
expect(metadataMock.writeTags).toHaveBeenCalledWith(assetStub.sidecar.sidecarPath, { expect(metadataMock.writeTags).toHaveBeenCalledWith(assetStub.sidecar.sidecarPath, {
Description: description,
ImageDescription: description, ImageDescription: description,
CreationDate: date, CreationDate: date,
GPSLatitude: gps, GPSLatitude: gps,

View file

@ -314,6 +314,7 @@ export class MetadataService implements OnEvents {
const sidecarPath = asset.sidecarPath || `${asset.originalPath}.xmp`; const sidecarPath = asset.sidecarPath || `${asset.originalPath}.xmp`;
const exif = _.omitBy<Tags>( const exif = _.omitBy<Tags>(
{ {
Description: description,
ImageDescription: description, ImageDescription: description,
CreationDate: dateTimeOriginal, CreationDate: dateTimeOriginal,
GPSLatitude: latitude, GPSLatitude: latitude,
@ -512,7 +513,7 @@ export class MetadataService implements OnEvents {
bitsPerSample: this.getBitsPerSample(tags), bitsPerSample: this.getBitsPerSample(tags),
colorspace: tags.ColorSpace ?? null, colorspace: tags.ColorSpace ?? null,
dateTimeOriginal: this.getDateTimeOriginal(tags) ?? asset.fileCreatedAt, dateTimeOriginal: this.getDateTimeOriginal(tags) ?? asset.fileCreatedAt,
description: (tags.ImageDescription || tags.Description) ?? '', description: (tags.ImageDescription || tags.Description || '').trim(),
exifImageHeight: validate(tags.ImageHeight), exifImageHeight: validate(tags.ImageHeight),
exifImageWidth: validate(tags.ImageWidth), exifImageWidth: validate(tags.ImageWidth),
exposureTime: tags.ExposureTime ?? null, exposureTime: tags.ExposureTime ?? null,