2021-09-03 21:11:40 +01:00
|
|
|
const request = require("request"), RequestType = require("./RequestType.json");
|
2021-02-13 13:01:40 +00:00
|
|
|
|
2021-09-03 21:11:40 +01:00
|
|
|
const functionMap = {
|
|
|
|
0: (resolve, body) => resolve(body),
|
|
|
|
1: (resolve, body) => resolve(JSON.parse(body)),
|
|
|
|
2: null
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = async function(url, reqType = RequestType.Text) {
|
2021-02-13 13:01:40 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
request(url, (err, res, body) => {
|
|
|
|
if (err) reject(err);
|
2021-09-03 21:11:40 +01:00
|
|
|
else functionMap[reqType](resolve, body);
|
2021-02-13 13:01:40 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|