mirror of
https://github.com/xuthus83/pigallery2.git
synced 2025-01-14 14:43:17 +08:00
adding metadata validity check
This commit is contained in:
parent
89f327f051
commit
33cbd93fb5
@ -4,7 +4,7 @@ import {MediaEntity, MediaMetadataEntity} from './MediaEntity';
|
|||||||
|
|
||||||
export class CameraMetadataEntity implements CameraMetadata {
|
export class CameraMetadataEntity implements CameraMetadata {
|
||||||
|
|
||||||
@Column('int', {nullable: true})
|
@Column('int', {nullable: true, unsigned: true})
|
||||||
ISO: number;
|
ISO: number;
|
||||||
|
|
||||||
@Column('text', {nullable: true})
|
@Column('text', {nullable: true})
|
||||||
@ -19,7 +19,7 @@ export class CameraMetadataEntity implements CameraMetadata {
|
|||||||
@Column('float', {nullable: true})
|
@Column('float', {nullable: true})
|
||||||
exposure: number;
|
exposure: number;
|
||||||
|
|
||||||
@Column('int', {nullable: true, unsigned: true})
|
@Column('float', {nullable: true})
|
||||||
focalLength: number;
|
focalLength: number;
|
||||||
|
|
||||||
@Column('text', {nullable: true})
|
@Column('text', {nullable: true})
|
||||||
@ -33,7 +33,7 @@ export class GPSMetadataEntity implements GPSMetadata {
|
|||||||
latitude: number;
|
latitude: number;
|
||||||
@Column('float', {nullable: true})
|
@Column('float', {nullable: true})
|
||||||
longitude: number;
|
longitude: number;
|
||||||
@Column('float', {nullable: true})
|
@Column('int', {nullable: true})
|
||||||
altitude: number;
|
altitude: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ import {ExifParserFactory, OrientationTypes} from 'ts-exif-parser';
|
|||||||
import {IptcParser} from 'ts-node-iptc';
|
import {IptcParser} from 'ts-node-iptc';
|
||||||
import {FFmpegFactory} from '../FFmpegFactory';
|
import {FFmpegFactory} from '../FFmpegFactory';
|
||||||
import {FfprobeData} from 'fluent-ffmpeg';
|
import {FfprobeData} from 'fluent-ffmpeg';
|
||||||
|
import {Utils} from '../../../common/Utils';
|
||||||
|
|
||||||
|
|
||||||
const LOG_TAG = '[MetadataLoader]';
|
const LOG_TAG = '[MetadataLoader]';
|
||||||
@ -49,8 +50,13 @@ export class MetadataLoader {
|
|||||||
metadata.size.width = data.streams[i].width;
|
metadata.size.width = data.streams[i].width;
|
||||||
metadata.size.height = data.streams[i].height;
|
metadata.size.height = data.streams[i].height;
|
||||||
|
|
||||||
|
if (Utils.isInt32(Math.floor(data.streams[i].duration * 1000))) {
|
||||||
metadata.duration = Math.floor(data.streams[i].duration * 1000);
|
metadata.duration = Math.floor(data.streams[i].duration * 1000);
|
||||||
metadata.bitRate = parseInt(data.streams[i].bit_rate, 10) || null;
|
}
|
||||||
|
|
||||||
|
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);
|
metadata.creationDate = Date.parse(data.streams[i].tags.creation_time);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -96,22 +102,36 @@ export class MetadataLoader {
|
|||||||
exif.tags.ExposureTime || exif.tags.FocalLength ||
|
exif.tags.ExposureTime || exif.tags.FocalLength ||
|
||||||
exif.tags.LensModel) {
|
exif.tags.LensModel) {
|
||||||
metadata.cameraData = {
|
metadata.cameraData = {
|
||||||
ISO: exif.tags.ISO,
|
|
||||||
model: exif.tags.Model,
|
model: exif.tags.Model,
|
||||||
make: exif.tags.Make,
|
make: exif.tags.Make,
|
||||||
fStop: exif.tags.FNumber,
|
lens: exif.tags.LensModel
|
||||||
exposure: exif.tags.ExposureTime,
|
|
||||||
focalLength: exif.tags.FocalLength,
|
|
||||||
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) {
|
if (!isNaN(exif.tags.GPSLatitude) || exif.tags.GPSLongitude || exif.tags.GPSAltitude) {
|
||||||
metadata.positionData = metadata.positionData || {};
|
metadata.positionData = metadata.positionData || {};
|
||||||
metadata.positionData.GPSData = {
|
metadata.positionData.GPSData = {};
|
||||||
latitude: exif.tags.GPSLatitude,
|
|
||||||
longitude: exif.tags.GPSLongitude,
|
if (Utils.isFloat32(exif.tags.GPSLongitude)) {
|
||||||
altitude: exif.tags.GPSAltitude
|
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) {
|
if (exif.tags.CreateDate || exif.tags.DateTimeOriginal || exif.tags.ModifyDate) {
|
||||||
@ -217,4 +237,5 @@ export class MetadataLoader {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -179,4 +179,19 @@ export class Utils {
|
|||||||
return curr;
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user