forked from virgaux/USBpc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.js
More file actions
76 lines (61 loc) · 2.09 KB
/
api.js
File metadata and controls
76 lines (61 loc) · 2.09 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const fetch = require('node-fetch');
const fs = require('fs');
async function tempLog(log) {
fs.appendFile('log.txt', log + '\n', function (err) {
//console.log('LogError', log);
});
}
async function getPossibleTeams(matchDetails) {
try {
const response = await fetch(process.env.API_URL + 'get_team/', {
method: 'post',
body: JSON.stringify(matchDetails),
headers: {'Content-Type': 'application/json'}
});
var dataRaw = await response.text();
if (process.env.DEBUG === 'true') {
tempLog('--------------------------------------------------------');
tempLog(JSON.stringify(matchDetails));
tempLog('response:');
tempLog(dataRaw);
tempLog('--------------------------------------------------------');
}
const data = JSON.parse(dataRaw);
return data;
} catch(e) {
console.log('API Error', e);
}
return false;
}
async function reportLoss(username) {
fetch(process.env.API_URL + 'report_loss/' + username + "/" + process.env.ACCUSERNAME.split('@')[0]);
}
async function copiem(username) {
fetch( 'http://192.168.1.6:5003/teamcopy');
}
async function getPossibleTeamsLocal(matchDetails) {
try {
quis = matchDetails.quest ? matchDetails.quest.splinter : null;
console.log(quis)
url = `teamselect/${matchDetails.mana}&${process.env.ACCUSERNAME}&${matchDetails.rules}&${matchDetails.splinters}&${quis}`;
const response = await fetch('http://192.168.1.6:5003/'+url);
var dataRaw = await response.text();
if (process.env.DEBUG === 'true') {
tempLog(JSON.stringify(matchDetails.quest.splinter));
tempLog('--------------------------------------------------------');
tempLog(JSON.stringify(matchDetails));
tempLog('response:');
tempLog(dataRaw);
tempLog('--------------------------------------------------------');
}
const data = JSON.parse(dataRaw);
return data;
} catch(e) {
console.log('API Error', e);
}
return false;
}
exports.getPossibleTeams = getPossibleTeams;
exports.reportLoss = reportLoss;
exports.reportLoss = reportLoss;
exports.copiem = copiem;