1
0
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:
Patrik J. Braun 2021-04-02 15:53:20 +02:00
parent 8422e4c29f
commit 3c70ce4b0b
7 changed files with 59 additions and 4 deletions

View File

@ -159,7 +159,6 @@ export class MetadataLoader {
metadata.positionData.GPSData.altitude = exif.tags.GPSAltitude;
}
}
if (exif.tags.CreateDate || exif.tags.DateTimeOriginal || exif.tags.ModifyDate) {
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);
}
metadata.creationDate = metadata.creationDate || 0;
metadata.creationDate = Math.max(metadata.creationDate || 0, 0);
try {
// TODO: clean up the three different exif readers,

View File

@ -240,7 +240,8 @@ export class GallerySearchFieldComponent implements ControlValueAccessor, Valida
private showSuggestions(suggestions: RenderableAutoCompleteItem[], searchText: string) {
this.emptyAutoComplete();
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);
});
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 71 KiB

View 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
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

View File

@ -0,0 +1,11 @@
{
"skip": [
"creationDate"
],
"fileSize": 71311,
"orientation": 1,
"size": {
"height": 1200,
"width": 1783
}
}

View File

@ -2,6 +2,8 @@ import {expect} from 'chai';
import {MetadataLoader} from '../../../../../src/backend/model/threading/MetadataLoader';
import {Utils} from '../../../../../src/common/Utils';
import * as path from 'path';
import * as fs from 'fs';
import {PhotoProcessing} from '../../../../../src/backend/model/fileprocessing/PhotoProcessing';
describe('MetadataLoader', () => {
@ -38,12 +40,37 @@ describe('MetadataLoader', () => {
expect(Utils.clone(data)).to.be.deep.equal(expected);
});
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'));
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', () => {
for (let i = 0; i <= 8; ++i) {
it('Landscape ' + i, async () => {