2022-04-24 02:04:52 +01:00
|
|
|
const fetch = require("node-fetch");
|
2021-02-13 13:01:40 +00:00
|
|
|
|
2021-09-03 21:11:40 +01:00
|
|
|
const functionMap = {
|
2022-04-24 02:04:52 +01:00
|
|
|
"text": async (res) => await res.text(),
|
|
|
|
"json": async (res) => await res.json()
|
2021-09-03 21:11:40 +01:00
|
|
|
};
|
|
|
|
|
2022-04-24 02:04:52 +01:00
|
|
|
module.exports = async function(url, reqType = "text") {
|
|
|
|
return new Promise(async (resolve, reject) => {
|
|
|
|
try {
|
|
|
|
resolve(functionMap[reqType](await fetch(url)));
|
|
|
|
} catch (e) {
|
|
|
|
reject(e);
|
|
|
|
}
|
2022-01-04 03:39:53 +00:00
|
|
|
});
|
2021-02-13 13:01:40 +00:00
|
|
|
}
|