allow AsyncHttpRequest to parse j...

son on it's own
This commit is contained in:
Holly Stubbs 2021-09-03 21:11:40 +01:00
parent 8dc931eede
commit 07dcc8f825
3 changed files with 16 additions and 4 deletions

View file

@ -2,6 +2,7 @@ const osu = require("osu-packet"),
User = require("./User.js"),
{ v4: uuid } = require('uuid'),
ahttp = require("./util/AsyncHttpRequest.js"),
RequestType = require("./util/RequestType.json"),
getUserByUsername = require("./util/getUserByUsername.js"),
getUserByToken = require("./util/getUserByToken.js"),
@ -41,7 +42,7 @@ module.exports = async function(req, res, loginInfo) {
userLocation = [0, 0];
} else {
// Get user's location using zxq
userLocationData = JSON.parse(await ahttp(`http://ip.zxq.co/${requestIP}`));
userLocationData = await ahttp(`http://ip.zxq.co/${requestIP}`, RequestType.JSON);
userLocation = userLocationData.loc.split(",");
}

View file

@ -1,10 +1,16 @@
const request = require("request");
const request = require("request"), RequestType = require("./RequestType.json");
module.exports = async function(url) {
const functionMap = {
0: (resolve, body) => resolve(body),
1: (resolve, body) => resolve(JSON.parse(body)),
2: null
};
module.exports = async function(url, reqType = RequestType.Text) {
return new Promise((resolve, reject) => {
request(url, (err, res, body) => {
if (err) reject(err);
else resolve(body);
else functionMap[reqType](resolve, body);
});
});
}

View file

@ -0,0 +1,5 @@
{
"Text": 0,
"JSON": 1,
"XML": 2
}