mirror of
https://github.com/xuthus83/pigallery2.git
synced 2024-11-03 21:04:03 +08:00
improving MetaDataLoader to better handle edge cases #245
This commit is contained in:
parent
8422e4c29f
commit
3c70ce4b0b
@ -159,7 +159,6 @@ export class MetadataLoader {
|
|||||||
metadata.positionData.GPSData.altitude = 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) {
|
||||||
metadata.creationDate = (exif.tags.DateTimeOriginal || exif.tags.CreateDate || exif.tags.ModifyDate) * 1000;
|
metadata.creationDate = (exif.tags.DateTimeOriginal || exif.tags.CreateDate || exif.tags.ModifyDate) * 1000;
|
||||||
}
|
}
|
||||||
@ -208,7 +207,7 @@ export class MetadataLoader {
|
|||||||
// Logger.debug(LOG_TAG, 'Error parsing iptc data', fullPath, err);
|
// Logger.debug(LOG_TAG, 'Error parsing iptc data', fullPath, err);
|
||||||
}
|
}
|
||||||
|
|
||||||
metadata.creationDate = metadata.creationDate || 0;
|
metadata.creationDate = Math.max(metadata.creationDate || 0, 0);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// TODO: clean up the three different exif readers,
|
// TODO: clean up the three different exif readers,
|
||||||
|
@ -240,7 +240,8 @@ export class GallerySearchFieldComponent implements ControlValueAccessor, Valida
|
|||||||
private showSuggestions(suggestions: RenderableAutoCompleteItem[], searchText: string) {
|
private showSuggestions(suggestions: RenderableAutoCompleteItem[], searchText: string) {
|
||||||
this.emptyAutoComplete();
|
this.emptyAutoComplete();
|
||||||
suggestions.forEach((item: RenderableAutoCompleteItem) => {
|
suggestions.forEach((item: RenderableAutoCompleteItem) => {
|
||||||
const renderItem = new AutoCompleteRenderItem(item.text, this._autoCompleteService.getPrefixLessSearchText(searchText), item.type, item.queryHint, item.notSearchable);
|
const renderItem = new AutoCompleteRenderItem(item.text, this._autoCompleteService.getPrefixLessSearchText(searchText),
|
||||||
|
item.type, item.queryHint, item.notSearchable);
|
||||||
this.autoCompleteRenders.push(renderItem);
|
this.autoCompleteRenders.push(renderItem);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
BIN
test/backend/assets/edge_case_exif_data/date_error.JPG
Normal file
BIN
test/backend/assets/edge_case_exif_data/date_error.JPG
Normal file
Binary file not shown.
After Width: | Height: | Size: 71 KiB |
17
test/backend/assets/edge_case_exif_data/date_error.json
Normal file
17
test/backend/assets/edge_case_exif_data/date_error.json
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"cameraData": {
|
||||||
|
"ISO": 400,
|
||||||
|
"exposure": 2,
|
||||||
|
"fStop": 2.8,
|
||||||
|
"focalLength": 8,
|
||||||
|
"make": "NIKON",
|
||||||
|
"model": "E880"
|
||||||
|
},
|
||||||
|
"creationDate": 0,
|
||||||
|
"fileSize": 72850,
|
||||||
|
"orientation": 1,
|
||||||
|
"size": {
|
||||||
|
"height": 768,
|
||||||
|
"width": 1024
|
||||||
|
}
|
||||||
|
}
|
BIN
test/backend/assets/edge_case_exif_data/iso_error.jpg
Normal file
BIN
test/backend/assets/edge_case_exif_data/iso_error.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 70 KiB |
11
test/backend/assets/edge_case_exif_data/iso_error.json
Normal file
11
test/backend/assets/edge_case_exif_data/iso_error.json
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"skip": [
|
||||||
|
"creationDate"
|
||||||
|
],
|
||||||
|
"fileSize": 71311,
|
||||||
|
"orientation": 1,
|
||||||
|
"size": {
|
||||||
|
"height": 1200,
|
||||||
|
"width": 1783
|
||||||
|
}
|
||||||
|
}
|
@ -2,6 +2,8 @@ import {expect} from 'chai';
|
|||||||
import {MetadataLoader} from '../../../../../src/backend/model/threading/MetadataLoader';
|
import {MetadataLoader} from '../../../../../src/backend/model/threading/MetadataLoader';
|
||||||
import {Utils} from '../../../../../src/common/Utils';
|
import {Utils} from '../../../../../src/common/Utils';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
import * as fs from 'fs';
|
||||||
|
import {PhotoProcessing} from '../../../../../src/backend/model/fileprocessing/PhotoProcessing';
|
||||||
|
|
||||||
describe('MetadataLoader', () => {
|
describe('MetadataLoader', () => {
|
||||||
|
|
||||||
@ -38,12 +40,37 @@ describe('MetadataLoader', () => {
|
|||||||
expect(Utils.clone(data)).to.be.deep.equal(expected);
|
expect(Utils.clone(data)).to.be.deep.equal(expected);
|
||||||
});
|
});
|
||||||
it('jpg 2', async () => {
|
it('jpg 2', async () => {
|
||||||
const data = await MetadataLoader.loadPhotoMetadata(path.join(__dirname, '/../../../assets/orientation/broken_orientation_exif2.jpg'));
|
const data = await MetadataLoader.loadPhotoMetadata(
|
||||||
|
path.join(__dirname, '/../../../assets/orientation/broken_orientation_exif2.jpg'));
|
||||||
const expected = require(path.join(__dirname, '/../../../assets/orientation/broken_orientation_exif2.json'));
|
const expected = require(path.join(__dirname, '/../../../assets/orientation/broken_orientation_exif2.json'));
|
||||||
expect(Utils.clone(data)).to.be.deep.equal(expected);
|
expect(Utils.clone(data)).to.be.deep.equal(expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('should load jpg with edge case exif data', () => {
|
||||||
|
const root = path.join(__dirname, '/../../../assets/edge_case_exif_data');
|
||||||
|
const files = fs.readdirSync(root);
|
||||||
|
for (let i = 0; i < files.length; ++i) {
|
||||||
|
const fullFilePath = path.join(root, files[i]);
|
||||||
|
if (PhotoProcessing.isPhoto(fullFilePath)) {
|
||||||
|
it(files[i], async () => {
|
||||||
|
const data = await MetadataLoader.loadPhotoMetadata(fullFilePath);
|
||||||
|
const expected = require(fullFilePath.split('.').slice(0, -1).join('.') + '.json');
|
||||||
|
if (expected.skip) {
|
||||||
|
expected.skip.forEach((s: string) => {
|
||||||
|
delete (<any>data)[s];
|
||||||
|
delete expected[s];
|
||||||
|
});
|
||||||
|
delete expected.skip;
|
||||||
|
}
|
||||||
|
expect(Utils.clone(data)).to.be.deep.equal(expected);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
describe('should read orientation', () => {
|
describe('should read orientation', () => {
|
||||||
for (let i = 0; i <= 8; ++i) {
|
for (let i = 0; i <= 8; ++i) {
|
||||||
it('Landscape ' + i, async () => {
|
it('Landscape ' + i, async () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user