mirror of
https://github.com/xuthus83/pigallery2.git
synced 2025-01-14 14:43:17 +08:00
improving utf8 image metadata support
This commit is contained in:
parent
a5e5f90ba6
commit
49b749d90b
@ -116,7 +116,6 @@ export class AuthenticationMWs {
|
||||
(typeof req.body.loginCredential.password === 'undefined')) {
|
||||
return next(new ErrorDTO(ErrorCodes.INPUT_ERROR));
|
||||
}
|
||||
//TODO: implement remember me
|
||||
try {
|
||||
//lets find the user
|
||||
const user = Utils.clone(await ObjectManagerRepository.getInstance().UserManager.findOne({
|
||||
|
@ -4,7 +4,7 @@ import {CameraMetadata, GPSMetadata, ImageSize, PhotoDTO, PhotoMetadata} from ".
|
||||
import {Logger} from "../../Logger";
|
||||
import * as fs from "fs";
|
||||
import * as path from "path";
|
||||
import * as iptc from "node-iptc";
|
||||
import {IptcParser} from "ts-node-iptc";
|
||||
import * as exif_parser from "exif-parser";
|
||||
import {ProjectPath} from "../../ProjectPath";
|
||||
|
||||
@ -53,7 +53,7 @@ export class DiskMangerWorker {
|
||||
const exif = exif_parser.create(data).parse();
|
||||
metadata.cameraData = <CameraMetadata> {
|
||||
ISO: exif.tags.ISO,
|
||||
model: exif.tags.Model.toString("utf8"),
|
||||
model: exif.tags.Model,
|
||||
make: exif.tags.Make,
|
||||
fStop: exif.tags.FNumber,
|
||||
exposure: exif.tags.ExposureTime,
|
||||
@ -76,18 +76,7 @@ export class DiskMangerWorker {
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
const iptcData = iptc(data);
|
||||
//Decode characters to UTF8
|
||||
const decode = (s: any) => {
|
||||
for (let a, b, i = -1, l = (s = s.split("")).length, o = String.fromCharCode, c = "charCodeAt"; ++i < l;
|
||||
((a = s[i][c](0)) & 0x80) &&
|
||||
(s[i] = (a & 0xfc) == 0xc0 && ((b = s[i + 1][c](0)) & 0xc0) == 0x80 ?
|
||||
o(((a & 0x03) << 6) + (b & 0x3f)) : o(128), s[++i] = "")
|
||||
);
|
||||
return s.join("");
|
||||
};
|
||||
|
||||
const iptcData = IptcParser.parse(data);
|
||||
if (iptcData.country_or_primary_location_name || iptcData.province_or_state || iptcData.city) {
|
||||
metadata.positionData = metadata.positionData || {};
|
||||
metadata.positionData.country = iptcData.country_or_primary_location_name;
|
||||
@ -95,11 +84,10 @@ export class DiskMangerWorker {
|
||||
metadata.positionData.city = iptcData.city;
|
||||
}
|
||||
|
||||
|
||||
metadata.keywords = <string[]> (iptcData.keywords || []).map((s: string) => decode(s));
|
||||
metadata.creationDate = <number> iptcData.date_time ? iptcData.date_time.getTime() : 0;
|
||||
metadata.keywords = <string[]> (iptcData.keywords || []);
|
||||
metadata.creationDate = <number> (iptcData.date_time ? iptcData.date_time.getTime() : 0);
|
||||
} catch (err) {
|
||||
Logger.info(LOG_TAG, "Error parsing iptc data", fullPath);
|
||||
Logger.info(LOG_TAG, "Error parsing iptc data", fullPath, err);
|
||||
}
|
||||
|
||||
return resolve(metadata);
|
||||
|
@ -1,5 +1,4 @@
|
||||
import * as _express from "express";
|
||||
import * as _session from "cookie-session";
|
||||
import * as _bodyParser from "body-parser";
|
||||
import * as _http from "http";
|
||||
import {PublicRouter} from "./routes/PublicRouter";
|
||||
@ -17,6 +16,7 @@ import {ThumbnailGeneratorMWs} from "./middlewares/thumbnail/ThumbnailGeneratorM
|
||||
import {DiskManager} from "./model/DiskManger";
|
||||
import {NotificationRouter} from "./routes/NotificationRouter";
|
||||
import {ConfigDiagnostics} from "./model/ConfigDiagnostics";
|
||||
import _session = require('cookie-session');
|
||||
|
||||
const LOG_TAG = "[server]";
|
||||
export class Server {
|
||||
|
@ -29,13 +29,13 @@
|
||||
"body-parser": "1.17.2",
|
||||
"cookie-session": "^2.0.0-beta.2",
|
||||
"ejs": "2.5.6",
|
||||
"exif-parser": "0.1.9",
|
||||
"exif-parser": "^0.1.11",
|
||||
"express": "4.15.3",
|
||||
"flat-file-db": "1.0.0",
|
||||
"jimp": "0.2.28",
|
||||
"mysql": "2.13.0",
|
||||
"node-iptc": "1.0.4",
|
||||
"reflect-metadata": "0.1.10",
|
||||
"ts-node-iptc": "^1.0.7",
|
||||
"typeconfig": "1.0.4",
|
||||
"typeorm": "0.0.11",
|
||||
"winston": "2.3.1"
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 56 KiB After Width: | Height: | Size: 61 KiB |
@ -6,15 +6,14 @@ import {ProjectPath} from "../../../../../backend/ProjectPath";
|
||||
|
||||
describe('DiskMangerWorker', () => {
|
||||
|
||||
it('should call next on authenticated', async () => {
|
||||
it('should parse metadata', async () => {
|
||||
Config.Server.imagesFolder = path.join(__dirname, "/../../assets");
|
||||
ProjectPath.ImageFolder = path.join(__dirname, "/../../assets");
|
||||
const dir = await DiskMangerWorker.scanDirectory("/");
|
||||
console.log(dir.photos[0].metadata);
|
||||
expect(dir.photos.length).to.be.equals(1);
|
||||
expect(dir.photos[0].name).to.be.equals("test image öüóőúéáű-.,.jpg");
|
||||
expect(dir.photos[0].metadata.keywords).to.deep.equals(['Berkley,USA']);
|
||||
expect(dir.photos[0].metadata.fileSize).to.deep.equals(57172);
|
||||
expect(dir.photos[0].metadata.keywords).to.deep.equals(['Berkley', 'USA', 'űáéúőóüö ŰÁÉÚŐÓÜÖ']);
|
||||
expect(dir.photos[0].metadata.fileSize).to.deep.equals(62392);
|
||||
expect(dir.photos[0].metadata.size).to.deep.equals({width: 140, height: 93});
|
||||
expect(dir.photos[0].metadata.cameraData).to.deep.equals({
|
||||
ISO: 3200,
|
||||
@ -32,9 +31,9 @@ describe('DiskMangerWorker', () => {
|
||||
longitude: -122.25678,
|
||||
altitude: 102.4498997995992
|
||||
},
|
||||
country: 'óüöúőűáé ÓÜÖÚŐŰÁÉ',
|
||||
state: 'óüöúőűáé ÓÜÖÚŐŰÁÉ',
|
||||
city: 'óüöúőűáé ÓÜÖÚŐŰÁÉ'
|
||||
country: 'mmóüöúőűáé ÓÜÖÚŐŰÁÉmm-.,|\\mm\u0000',
|
||||
state: 'óüöúőűáé ÓÜÖÚŐŰÁ',
|
||||
city: 'óüöúőűáé ÓÜÖÚŐŰÁ'
|
||||
});
|
||||
|
||||
expect(dir.photos[0].metadata.creationDate).to.be.equals(1436610566000);
|
||||
|
Loading…
x
Reference in New Issue
Block a user