diff --git a/src/backend/model/threading/MetadataLoader.ts b/src/backend/model/threading/MetadataLoader.ts index 137c1186..c4208cb4 100644 --- a/src/backend/model/threading/MetadataLoader.ts +++ b/src/backend/model/threading/MetadataLoader.ts @@ -199,15 +199,21 @@ export class MetadataLoader { if (iptcData.caption) { metadata.caption = iptcData.caption.replace(/\0/g, '').trim(); } - metadata.keywords = iptcData.keywords || []; + if (Array.isArray(iptcData.keywords)) { + metadata.keywords = iptcData.keywords; + } - metadata.creationDate = ((iptcData.date_time ? iptcData.date_time.getTime() : metadata.creationDate) as number); + if (iptcData.date_time) { + metadata.creationDate = iptcData.date_time.getTime(); + } } catch (err) { // Logger.debug(LOG_TAG, 'Error parsing iptc data', fullPath, err); } - metadata.creationDate = Math.max(metadata.creationDate || 0, 0); + if (!metadata.creationDate) { // creationDate can be negative, when it was created before epoch (1970) + metadata.creationDate = 0; + } try { // TODO: clean up the three different exif readers, diff --git a/test/backend/assets/edge_case_exif_data/before_epoch.jpg b/test/backend/assets/edge_case_exif_data/before_epoch.jpg new file mode 100644 index 00000000..17f9d301 Binary files /dev/null and b/test/backend/assets/edge_case_exif_data/before_epoch.jpg differ diff --git a/test/backend/assets/edge_case_exif_data/before_epoch.json b/test/backend/assets/edge_case_exif_data/before_epoch.json new file mode 100644 index 00000000..e4722492 --- /dev/null +++ b/test/backend/assets/edge_case_exif_data/before_epoch.json @@ -0,0 +1,46 @@ +{ + "cameraData": { + "ISO": 800, + "exposure": 0.008, + "fStop": 5.6, + "focalLength": 85, + "lens": "EF-S15-85mm f/3.5-5.6 IS USM", + "make": "Canon", + "model": "Canon EOS 600D" + }, + "caption": "Bambi Caption", + "creationDate": -11630935227000, + "faces": [ + { + "box": { + "height": 2, + "left": 4, + "top": 2, + "width": 2 + }, + "name": "Bambi" + } + ], + "fileSize": 19145, + "keywords": [ + "USA", + "USA Road trip", + "Yosemite" + ], + "orientation": 1, + "positionData": { + "GPSData": { + "altitude": 1960, + "latitude": 37.74805833333333, + "longitude": -119.51402333333333 + }, + "city": "Yosemite Nemzeti Park", + "country": "United States", + "state": "California" + }, + "rating": 2, + "size": { + "height": 7, + "width": 10 + } +} diff --git a/test/backend/assets/edge_case_exif_data/date_error.json b/test/backend/assets/edge_case_exif_data/date_error.json index 364c0d0f..a5f34a3e 100644 --- a/test/backend/assets/edge_case_exif_data/date_error.json +++ b/test/backend/assets/edge_case_exif_data/date_error.json @@ -7,7 +7,7 @@ "make": "NIKON", "model": "E880" }, - "creationDate": 0, + "creationDate": -2211753600000, "fileSize": 72850, "orientation": 1, "size": { diff --git a/test/backend/assets/edge_case_exif_data/no_metadata.jpg b/test/backend/assets/edge_case_exif_data/no_metadata.jpg new file mode 100644 index 00000000..13ac4b1b Binary files /dev/null and b/test/backend/assets/edge_case_exif_data/no_metadata.jpg differ diff --git a/test/backend/assets/edge_case_exif_data/no_metadata.json b/test/backend/assets/edge_case_exif_data/no_metadata.json new file mode 100644 index 00000000..9801ee72 --- /dev/null +++ b/test/backend/assets/edge_case_exif_data/no_metadata.json @@ -0,0 +1,9 @@ +{ + "creationDate": 1621859678578, + "fileSize": 5860, + "orientation": 1, + "size": { + "height": 7, + "width": 10 + } +}