Created
December 19, 2012 10:50
-
-
Save FugueNation/4335897 to your computer and use it in GitHub Desktop.
checker.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var _ = require('underscore'); | |
var Seq = require('seq'); | |
var request = require('request'); | |
var crypto = require('crypto'); | |
var fs = require('fs'); | |
fs.readFile('manifest.json', function (err, data) { | |
if (err) return console.log(err.message); | |
var manifest = JSON.parse(data); | |
var urls = []; | |
_.each(manifest.packages, function( p ) { | |
_.each(p.digests, function( d ) { | |
urls.push({url:'http://aimg-monpla-smash.gree-apps.net/origin/asset/' + d, d:d}); | |
urls.push({url:'http://monpla-smash.gree-apps.net:8000/origin/asset/' + d, d:d}); | |
}) | |
}) | |
Seq() | |
.sync(function() { return urls; }) | |
.flatten() | |
.seqEach(function( url ) { | |
var that = this; | |
request({url:url.url, encoding:null}, function (error, response, body) { | |
if (!error && response.statusCode == 200) { | |
var shasum = crypto.createHash('sha1'); | |
shasum.update(body); | |
var d = shasum.digest('hex'); | |
if (d != url.d) { | |
console.log('hash mismatch, got:', d, 'expected:', url.d, response); | |
return that.done(); | |
} | |
// console.log(body) // Print the google web page. | |
} else { | |
console.log("fail", url); | |
console.log(error && error.message, response); | |
return that.done(); | |
} | |
that.ok(); | |
}) | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment