-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
52 lines (49 loc) · 1.17 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
const f = require("node-fetch");
const { https, port, url, token } = require("./config.js");
exports.set = async function(key, value, time) {
const body = {
"data": {
"key": key,
"value": value
},
"expire": time
}
let res = await f(`http${(https == true) ? "s" : "" }://${url}:${port}/set`, {
method: "post",
headers: {
"token": token,
"Content-Type": "application/json"
},
body: JSON.stringify(body)
})
};
exports.get = async function(key) {
const body = {
"data": {
"key": key
}
}
let res = await f(`http${(https == true) ? "s" : "" }://${url}:${port}/get`, {
method: "post",
headers: {
"token": token,
"Content-Type": "application/json"
},
body: JSON.stringify(body)
})
let output = await res.text();
return output;
};
exports.ping = async function() {
let dateBefore = Date.now()
let res = await f(`http${(https == true) ? "s" : "" }://${url}:${port}/ping`, {
method: "get",
headers: {
"Content-Type": "application/json",
"token": token
}
})
let dateAfter = Date.now()
let latency = (dateAfter - dateBefore)
return latency;
};