-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
60 lines (52 loc) · 1.29 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
var express = require("express");
var app = express();
var getter = require("./get/get");
app.use(express.static(__dirname + '/public'));
var links = {};
function updateLinks(){
getter(function(linkobj){
links = linkobj;
});
}
setInterval(updateLinks, 1000 * 60 * 30);
updateLinks();
function getLinks(callback){
var linkList = [];
function addItem(item, type){
var alreadyInList = false;
linkList.map(function(itemInList){
if (itemInList.item == item){
alreadyInList = true;
}
});
if (!alreadyInList){
linkList.push({item: item, type :type});
}
return !alreadyInList;
}
for (var j = 0; j < 9; j++){
var rand = Math.random();
if (rand> 0.5){
// use onion
var i =0; //Maximum number of retries
var max = 10;
while(!addItem(links.onion[Math.floor(Math.random() * links.onion.length)], "onion") && i < max){
i++;
}
} else {
// use notonion
var i =0; //Maximum number of retries
var max = 10;
while(!addItem(links.notonion[Math.floor(Math.random() * links.notonion.length)], "notonion") && i < max){
i++;
}
}
}
callback(linkList);
}
app.get("/list", function(req, res){
getLinks(function(linklist){
res.json(linklist);
});
});
app.listen(3000);