forked from makazeu/steam-key
-
Notifications
You must be signed in to change notification settings - Fork 0
/
post.js
42 lines (37 loc) · 875 Bytes
/
post.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
const request = require('request');
module.exports = (postAddress, subId, subName, serverId) => {
let options = {
uri: postAddress,
method: 'POST',
timeout: 20000,
json: {
subId: subId,
subName: subName,
server: serverId
}
};
start(options);
};
async function start(options) {
try {
for (let i = 1; i <= 3; i++) {
let res = await doPost(options);
if (res === 'OK') {
break;
}
}
} catch (error) {
//console.log(error);
}
}
function doPost(options) {
return new Promise((resolve, reject) => {
request(options, (error, response, body) => {
if (!error) {
resolve(body);
} else {
reject(error);
}
});
});
}