forked from MrPrimate/ddb-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcampaign.js
50 lines (44 loc) · 1.39 KB
/
campaign.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
// This data is the light version of data available in the character builder
const fetch = require("node-fetch");
const CONFIG = require("./config.js");
const authentication = require("./auth.js");
const getCampaigns = (cobalt, cobaltId) => {
//return [];
return new Promise((resolve, reject) => {
console.log(`Retrieving campaigns for ${cobaltId}`);
// console.log(authentication.CACHE_AUTH.exists(cobaltId).data);
const url = CONFIG.urls.campaignsAPI;
const options = {
credentials: "include",
headers: {
"User-Agent": "Foundry VTT Character Integrator",
"Accept": "*/*",
"Cookie": `cobalt-token=${authentication.CACHE_AUTH.exists(cobaltId).data}; CobaltSession=${cobalt}`,
},
method: "GET",
mode: "cors",
redirect: "follow",
};
fetch(url, options)
.then(res => {
return res;
})
.then(res => res.text())
.then(text => {
const json = JSON.parse(text);
// console.log(json);
if (json.status == "success") {
resolve(json.data);
} else {
console.log("Received no valid campaign data, instead:" + json.message);
reject(json.message);
}
})
.catch(error => {
console.log("Error retrieving campaigns");
console.log(error);
reject(error);
});
});
};
exports.getCampaigns = getCampaigns;