diff --git a/backend/model/sql/enitites/PhotoEntity.ts b/backend/model/sql/enitites/PhotoEntity.ts index 6ebaa568..a6b58429 100644 --- a/backend/model/sql/enitites/PhotoEntity.ts +++ b/backend/model/sql/enitites/PhotoEntity.ts @@ -4,7 +4,7 @@ import {MediaEntity, MediaMetadataEntity} from './MediaEntity'; export class CameraMetadataEntity implements CameraMetadata { - @Column('int', {nullable: true}) + @Column('int', {nullable: true, unsigned: true}) ISO: number; @Column('text', {nullable: true}) @@ -19,7 +19,7 @@ export class CameraMetadataEntity implements CameraMetadata { @Column('float', {nullable: true}) exposure: number; - @Column('int', {nullable: true, unsigned: true}) + @Column('float', {nullable: true}) focalLength: number; @Column('text', {nullable: true}) @@ -33,7 +33,7 @@ export class GPSMetadataEntity implements GPSMetadata { latitude: number; @Column('float', {nullable: true}) longitude: number; - @Column('float', {nullable: true}) + @Column('int', {nullable: true}) altitude: number; } diff --git a/backend/model/threading/MetadataLoader.ts b/backend/model/threading/MetadataLoader.ts index 46041f44..43f26021 100644 --- a/backend/model/threading/MetadataLoader.ts +++ b/backend/model/threading/MetadataLoader.ts @@ -10,6 +10,7 @@ import {ExifParserFactory, OrientationTypes} from 'ts-exif-parser'; import {IptcParser} from 'ts-node-iptc'; import {FFmpegFactory} from '../FFmpegFactory'; import {FfprobeData} from 'fluent-ffmpeg'; +import {Utils} from '../../../common/Utils'; const LOG_TAG = '[MetadataLoader]'; @@ -49,8 +50,13 @@ export class MetadataLoader { metadata.size.width = data.streams[i].width; metadata.size.height = data.streams[i].height; - metadata.duration = Math.floor(data.streams[i].duration * 1000); - metadata.bitRate = parseInt(data.streams[i].bit_rate, 10) || null; + if (Utils.isInt32(Math.floor(data.streams[i].duration * 1000))) { + metadata.duration = Math.floor(data.streams[i].duration * 1000); + } + + if (Utils.isInt32(parseInt(data.streams[i].bit_rate, 10))) { + metadata.duration = parseInt(data.streams[i].bit_rate, 10) || null; + } metadata.creationDate = Date.parse(data.streams[i].tags.creation_time); break; } @@ -96,22 +102,36 @@ export class MetadataLoader { exif.tags.ExposureTime || exif.tags.FocalLength || exif.tags.LensModel) { metadata.cameraData = { - ISO: exif.tags.ISO, model: exif.tags.Model, make: exif.tags.Make, - fStop: exif.tags.FNumber, - exposure: exif.tags.ExposureTime, - focalLength: exif.tags.FocalLength, - lens: exif.tags.LensModel, + lens: exif.tags.LensModel }; + if (Utils.isUInt32(exif.tags.ISO)) { + metadata.cameraData.ISO = exif.tags.ISO; + } + if (Utils.isFloat32(exif.tags.ISO)) { + metadata.cameraData.focalLength = exif.tags.FocalLength; + } + if (Utils.isFloat32(exif.tags.ExposureTime)) { + metadata.cameraData.exposure = exif.tags.ExposureTime; + } + if (Utils.isFloat32(exif.tags.FNumber)) { + metadata.cameraData.fStop = exif.tags.FNumber; + } } if (!isNaN(exif.tags.GPSLatitude) || exif.tags.GPSLongitude || exif.tags.GPSAltitude) { metadata.positionData = metadata.positionData || {}; - metadata.positionData.GPSData = { - latitude: exif.tags.GPSLatitude, - longitude: exif.tags.GPSLongitude, - altitude: exif.tags.GPSAltitude - }; + metadata.positionData.GPSData = {}; + + if (Utils.isFloat32(exif.tags.GPSLongitude)) { + metadata.positionData.GPSData.longitude = exif.tags.GPSLongitude; + } + if (Utils.isFloat32(exif.tags.GPSLatitude)) { + metadata.positionData.GPSData.latitude = exif.tags.GPSLatitude; + } + if (Utils.isInt32(exif.tags.GPSAltitude)) { + metadata.positionData.GPSData.altitude = exif.tags.GPSAltitude; + } } if (exif.tags.CreateDate || exif.tags.DateTimeOriginal || exif.tags.ModifyDate) { @@ -217,4 +237,5 @@ export class MetadataLoader { } ); } + } diff --git a/common/Utils.ts b/common/Utils.ts index f33c68d5..dbb1559f 100644 --- a/common/Utils.ts +++ b/common/Utils.ts @@ -179,4 +179,19 @@ export class Utils { return curr; } + public static isUInt32(value: number, max: number = 4294967295) { + return !isNaN(value) && value >= 0 && value <= max; + } + + public static isInt32(value: number) { + return !isNaN(value) && value >= -2147483648 && value <= 2147483647; + } + + public static isFloat32(value: number) { + const E = Math.pow(10, 38); + const nE = Math.pow(10, -38); + return !isNaN(value) && ((value >= -3.402823466 * E && value <= -1.175494351 * nE) || + (value <= 3.402823466 * E && value >= 1.175494351 * nE)); + } + }