diff --git a/src/backend/model/fileaccess/MetadataLoader.ts b/src/backend/model/fileaccess/MetadataLoader.ts index 5a61af21..8ad45f07 100644 --- a/src/backend/model/fileaccess/MetadataLoader.ts +++ b/src/backend/model/fileaccess/MetadataLoader.ts @@ -418,18 +418,13 @@ export class MetadataLoader { private static mapCameraData(metadata: PhotoMetadata, exif: any) { metadata.cameraData = metadata.cameraData || {}; - if (exif.ifd0) { - if (exif.ifd0.Make && exif.ifd0.Make !== '') { - metadata.cameraData.make = '' + exif.ifd0.Make; - } - if (exif.ifd0.Model && exif.ifd0.Model !== '') { - metadata.cameraData.model = '' + exif.ifd0.Model; - } - } + metadata.cameraData.make = exif.ifd0?.Make || exif.tiff?.Make || metadata.cameraData.make; + + metadata.cameraData.model = exif.ifd0?.Model || exif.tiff?.Model || metadata.cameraData.model; + + metadata.cameraData.lens = exif.exif?.LensModel || exif.exifEX?.LensModel || metadata.cameraData.lens; + if (exif.exif) { - if (exif.exif.LensModel && exif.exif.LensModel !== '') { - metadata.cameraData.lens = '' + exif.exif.LensModel; - } if (Utils.isUInt32(exif.exif.ISO)) { metadata.cameraData.ISO = parseInt('' + exif.exif.ISO, 10); } @@ -449,6 +444,7 @@ export class MetadataLoader { ); } } + Utils.removeNullOrEmptyObj(metadata.cameraData); if (Object.keys(metadata.cameraData).length === 0) { delete metadata.cameraData; } @@ -473,13 +469,8 @@ export class MetadataLoader { } catch (err) { Logger.error(LOG_TAG, 'Error during reading of GPS data: ' + err); } finally { - if (metadata.positionData?.GPSData && - (Object.keys(metadata.positionData.GPSData).length === 0 || - metadata.positionData.GPSData.longitude === undefined || - metadata.positionData.GPSData.latitude === undefined)) { - delete metadata.positionData.GPSData; - } if (metadata.positionData) { + Utils.removeNullOrEmptyObj(metadata.positionData); if (Object.keys(metadata.positionData).length === 0) { delete metadata.positionData; } diff --git a/src/common/Utils.ts b/src/common/Utils.ts index 618ad8b9..a1fc4cac 100644 --- a/src/common/Utils.ts +++ b/src/common/Utils.ts @@ -35,7 +35,7 @@ export class Utils { delete obj[key]; } } - } else if (obj[key] === null) { + } else if (obj[key] === null || obj[key] === undefined) { delete obj[key]; } } diff --git a/test/backend/assets/sidecar/flatxmp.json b/test/backend/assets/sidecar/flatxmp.json new file mode 100644 index 00000000..10dfa9d9 --- /dev/null +++ b/test/backend/assets/sidecar/flatxmp.json @@ -0,0 +1,37 @@ +{ + "size": { + "width": 10, + "height": 5 + }, + "caption": "Description of image", + "creationDate": 328817998000, + "faces": [ + { + "box": { + "height": 1, + "left": 6, + "top": 2, + "width": 2 + }, + "name": "Person1" + }, + { + "box": { + "height": 2, + "left": 2, + "top": 1, + "width": 2 + }, + "name": "Person2" + } + ], + "fileSize": 1430, + "keywords": [ + "Thing3" + ], + "title": "The title", + "cameraData": { + "make": "Cam Make", + "model": "Cam Model" + } +} \ No newline at end of file diff --git a/test/backend/assets/sidecar/headline.json b/test/backend/assets/sidecar/headline.json new file mode 100644 index 00000000..0a1c60cf --- /dev/null +++ b/test/backend/assets/sidecar/headline.json @@ -0,0 +1,16 @@ +{ + "size": { + "width": 10, + "height": 5 + }, + "creationDate": 1185683698000, + "creationDateOffset": "+13:45", + "fileSize": 1430, + "keywords": ["Person 1", "Person 2"], + "caption": "XMP description", + "title": "Photoshop Headline", + "cameraData": { + "make": "CamMake", + "model": "CamModel" + } +} \ No newline at end of file