-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
65 lines (61 loc) · 1.77 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"use strict";
var fs = require('fs');
var https = require('https');
var imageDiff = require('image-diff')
var set = 'icc';
var langOne = 'zh_CN';
var langTwo = 'en_US'
var cardSet = JSON.parse( fs.readFileSync('data/'+set+'.json', "utf8") );
var download = function(url,nextUrl,name) {
return new Promise(function(resolve,reject) {
var fn = /^https.*\/([a-f0-9]{64}.*)/.exec(url);
if ( !fn ) {
reject(Error("Invalid url.",url));
}
var path = 'download/'+set+'/'+fn[1];
var file = fs.createWriteStream(path);
var request = https.get(fn[0], function(response) {
response.pipe(file);
file.on('finish', function() {
file.close(function(){
resolve({
path: path,
nextUrl: nextUrl,
fn: fn[1],
name: name
});
});
});
}).on('error', function(err) {
fs.unlink(path);
reject(Error("Error downloading file."));
});
});
};
for (var i=0;i<cardSet.allCards.length;i++ ) {
var card = cardSet.allCards[i];
if ( card.localizedImage[langOne] === card.localizedImage[langTwo] ) {
break;
}
download(card.localizedImage[langOne], card.localizedImage[langTwo], card.cardNameSlug || card.id).then(function(res) {
download(res.nextUrl,'',res.name).then(function(resTwo) {
var diffPath = 'result/'+set+'/'+res.name+'.png';
imageDiff({
actualImage: res.path,
expectedImage: resTwo.path,
diffImage: diffPath
}, function (err, imagesAreSame) {
if (err) {
console.log(err);
}
if ( !imagesAreSame ) {
console.log( diffPath, res.path, resTwo.path );
}
});
}, function(error) {
console.error(error);
});
}, function(error) {
console.error(error);
});
}