1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2025-01-14 14:43:17 +08:00

keywords decoding error fix

This commit is contained in:
Braun Patrik 2016-07-11 12:52:15 +02:00
parent 941fdf509e
commit 3cd9ef7b1a

View File

@ -81,7 +81,38 @@ export class DiskManager {
return false;
}
/*
UTF8 = {
encode: function(s){
for(var c, i = -1, l = (s = s.split("")).length, o = String.fromCharCode; ++i < l;
s[i] = (c = s[i].charCodeAt(0)) >= 127 ? o(0xc0 | (c >>> 6)) + o(0x80 | (c & 0x3f)) : s[i]
);
return s.join("");
},
decode: function(s){
for(var 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("");
}
};*/
private static loadPhotoMetadata(fullPath):Promise<PhotoMetadata> {
return new Promise<PhotoMetadata>((resolve:(metadata:PhotoMetadata)=>void, reject) => {
fs.readFile(fullPath, function (err, data) {
@ -115,8 +146,22 @@ export class DiskManager {
city: iptcData.city
};
let keywords:[string] = iptcData.keywords;
//Decode characters to UTF8
let decode = (s)=> {
for (var 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("");
};
let keywords:[string] = iptcData.keywords.map(s => decode(s));
let creationDate:Date = iptcData.date_time;
console.log(keywords);
let metadata:PhotoMetadata = new PhotoMetadata(keywords, cameraData, positionData, imageSize, creationDate);