-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3.getRequests.js
More file actions
60 lines (54 loc) · 1.5 KB
/
3.getRequests.js
File metadata and controls
60 lines (54 loc) · 1.5 KB
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
let https = require('https');
let url = 'https://raw.githubusercontent.com/metarhia/JSTP/master/README.md';
let links = [];
let repos = {};
https.get(url, res => {
let allData = '',
bracketState = 'lookFor[';
res.on('data', data => allData += data);
res.on('end', () => {
let offset = 0;
while (offset < allData.length) {
let [newLink, newOffset] = getLink(allData, offset);
if (newLink !== null) links.push(newLink);
offset = newOffset;
}
links = links.filter(
str => str[0] !== '#' &&
str.indexOf('https://github.com/metarhia') === -1
);
links.forEach(link => {
console.log(link);
https.get(link, res => {
let allData = '';
res.on('data', data => allData += data);
res.on('end', () => repos[link] = allData);
});
});
});
}).on('error', err => console.log(err));
function getLink(allData, offset) {
let ind1 = allData.indexOf('[', offset),
end = true,
newLink = null;
if (ind1 !== -1) {
offset = ind1 + 1;
let ind2 = allData.indexOf(']', offset),
ind3 = ind2 + 1;
if (ind2 !== -1 && ind3 < allData.length) {
offset = ind3 + 1;
end = false;
if (allData[ind3] === '(') {
let ind4 = allData.indexOf(')', offset);
if (ind4 !== -1) {
offset = ind4 + 1;
newLink = allData.substring(ind3 + 1, ind4);
} else {
end = true;
}
}
}
}
if (end) offset = allData.length;
return [newLink, offset];
}