-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex-axum.js
74 lines (66 loc) · 2.49 KB
/
index-axum.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
68
69
70
71
72
73
74
const axios = require("axios"),
fs = require('fs');
// Edit with your link and location of json file
var link = 'http://xxx.xxx.xxx.xxx:1212/api/stats?token=MyAccessToken',
json_loc = './tracker-axum.json';
axios
.get(link)
.then((response) => {
let json_text = JSON.stringify(response.data);
let json = JSON.parse( // edit your starting date as epoch ms
'{"date":' + Date.now().toString() + ',' + json_text.slice(1)
);
checkFile(json);
})
.catch((error) => {
console.log(error);
blank = {
date: Date.now(),started: 0,
timestamp_run_save: 0,timestamp_run_timeout: 0,timestamp_run_console: 0,timestamp_run_keys_timeout: 0,
torrents: 0,torrents_updates: 0,torrents_shadow: 0,
seeds: 0,peers: 0,completed: 0,
whitelist_enabled: false,whitelist: 0,blacklist_enabled: false,blacklist: 0,
keys_enabled: false,keys: 0,
tcp4_connections_handled: 0,tcp4_api_handled: 0,tcp4_announces_handled: 0,tcp4_scrapes_handled: 0,
tcp6_connections_handled: 0,tcp6_api_handled: 0,tcp6_announces_handled: 0,tcp6_scrapes_handled: 0,
udp4_connections_handled: 0,udp4_announces_handled: 0,udp4_scrapes_handled: 0,
udp6_connections_handled: 0,udp6_announces_handled: 0,udp6_scrapes_handled: 0
};
checkFile(blank);
});
function checkFile(obj_) {
if (fs.existsSync(json_loc)) {
fs.readFile(json_loc, 'utf8', function(err, data) {
if (err)
console.log(err);
if (data.length == 0) {
fs.writeFile(json_loc, '{"data": []}', 'utf8', function(err, data) {
if (err)
console.log(err);
})
toJson(obj_);
} else {
toJson(obj_);
}
});
} else {
fs.writeFile(json_loc, '{"data": []}', 'utf8', function(err, data) {
if (err)
console.log(err);
})
toJson(obj_);
}
}
function toJson(obj_) {
fs.readFile(json_loc, 'utf8', function(err, data) {
if (err)
console.log(err);
var obj = JSON.parse(data);
obj.data.push(obj_);
json = JSON.stringify(obj);
fs.writeFile(json_loc, json, 'utf8', function(err, data) {
if (err)
console.log(err);
});
})
}