1
0
mirror of https://github.com/immich-app/immich.git synced 2024-11-28 09:33:27 +02:00

fix(server): handle numeric 'Image Description' and 'Description' values (#11636)

* Made 'Image Description' and 'Description' type safe during exif parsing

* add test + update types

---------

Co-authored-by: Michel Heusschen <59014050+michelheusschen@users.noreply.github.com>
This commit is contained in:
Johannes Groß 2024-08-07 17:23:36 +02:00 committed by GitHub
parent 5b64456f48
commit 28ba22e8c1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 2 deletions

View File

@ -7,7 +7,7 @@ export interface ExifDuration {
Scale?: number;
}
export interface ImmichTags extends Omit<Tags, 'FocalLength' | 'Duration'> {
export interface ImmichTags extends Omit<Tags, 'FocalLength' | 'Duration' | 'Description' | 'ImageDescription'> {
ContentIdentifier?: string;
MotionPhoto?: number;
MotionPhotoVersion?: number;
@ -19,6 +19,10 @@ export interface ImmichTags extends Omit<Tags, 'FocalLength' | 'Duration'> {
EmbeddedVideoType?: string;
EmbeddedVideoFile?: BinaryField;
MotionPhotoVideo?: BinaryField;
// Type is wrong, can also be number.
Description?: string | number;
ImageDescription?: string | number;
}
export interface IMetadataRepository {

View File

@ -753,6 +753,18 @@ describe(MetadataService.name, () => {
}),
);
});
it('handles a numeric description', async () => {
assetMock.getByIds.mockResolvedValue([assetStub.image]);
metadataMock.readTags.mockResolvedValue({ Description: 1000 });
await sut.handleMetadataExtraction({ id: assetStub.image.id });
expect(assetMock.upsertExif).toHaveBeenCalledWith(
expect.objectContaining({
description: '1000',
}),
);
});
});
describe('handleQueueSidecar', () => {

View File

@ -482,7 +482,7 @@ export class MetadataService implements OnEvents {
bitsPerSample: this.getBitsPerSample(tags),
colorspace: tags.ColorSpace ?? null,
dateTimeOriginal: this.getDateTimeOriginal(tags) ?? asset.fileCreatedAt,
description: (tags.ImageDescription || tags.Description || '').trim(),
description: String(tags.ImageDescription || tags.Description || '').trim(),
exifImageHeight: validate(tags.ImageHeight),
exifImageWidth: validate(tags.ImageWidth),
exposureTime: tags.ExposureTime ?? null,