-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
67 lines (52 loc) · 1.6 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
66
67
#! /usr/bin/env node
var node = node || {};
node.Webloc = function() {
var fs = require('fs');
var xml2js = require('xml2js');
var util = require('util');
var http = require('http');
var request = require('request');
var parser = new xml2js.Parser();
var badUrlTotal = 0;
var filesTotal = 0;
var checkedTotal = 0;
fs.readdir(process.cwd(), function (err, files) {
filesTotal = files.length;
console.log('Starting check...');
for (var i=0; i < filesTotal; i++) {
readFile(files[i]);
}
});
function readFile(path) {
fs.readFile(path, function(error, data) {
if (error) {
return console.log(error);
}
var parser = new xml2js.Parser();
parser.parseString(data, function(error, result) {
var url = result['plist']['dict'][0]['string'][0];
checkURL(url);
});
});
};
function checkURL(url) {
request(url, function (error, response, body) {
++checkedTotal;
if (!error && response.statusCode == 200) {
console.log(url + ' – GOOD');
}
else {
++badUrlTotal;
console.log(url + ' – BAD');
}
if (checkedTotal >= filesTotal) {
completeCheck();
}
});
}
function completeCheck() {
console.log('Finished!');
console.log('Checked ' + filesTotal + ' Webloc files, ' + badUrlTotal + ' Bad and ' + (filesTotal - badUrlTotal) + ' Good');
}
};
var webloc = new node.Webloc();