From f87e791e04871b8c42dae22fcc79f3e9c635186c Mon Sep 17 00:00:00 2001 From: Brutus5000 Date: Sun, 12 Nov 2023 21:47:50 +0100 Subject: [PATCH] Remove lobby_api querying This is unused since new website (was bugged anyway) and currently stops moving the website to Kubernetes. --- express.js | 1 - routes/lobby_api.js | 65 --------------------------------------------- 2 files changed, 66 deletions(-) delete mode 100644 routes/lobby_api.js diff --git a/express.js b/express.js index b2fd2269..10ec9505 100644 --- a/express.js +++ b/express.js @@ -202,7 +202,6 @@ app.get('/account/connect', loggedIn, require(routes + 'account/get/connectSteam //app.get('/account/connectSteam', loggedIn, require(routes + 'account/get/connectSteam')); app.get('/account/resync', loggedIn, require(routes + 'account/get/resync')); // Not Protected -app.get('/lobby_api', cors(), require('./routes/lobby_api')); app.get('/account/create', require(routes + 'account/get/createAccount')); app.get('/account_activated', require(routes + 'account/get/register')); app.get('/account/register', require(routes + 'account/get/register')); diff --git a/routes/lobby_api.js b/routes/lobby_api.js deleted file mode 100644 index 38d80e3d..00000000 --- a/routes/lobby_api.js +++ /dev/null @@ -1,65 +0,0 @@ -const request = require("request"); -const cache = {}; -let isFetching = false; - -const PLAYER_COUNT_INTERVAL = process.env.PLAYER_COUNT_INTERVAL * 1000; - -exports = module.exports = function (req, res) { - let resource = req.query.resource; - if (cache[resource]) { - if (isFetching || Date.now() - cache[resource].pollTime < PLAYER_COUNT_INTERVAL) { - return res.send(cache[resource].data); - } - } - isFetching = true; - let queryResource = resource; - if (resource === "countries") { - queryResource = "players"; - } else if (resource === "lobby") { - queryResource = "games"; - } - request(process.env.LOBBY_API_URL + "/" + queryResource, function (error, response, body) { - let data = []; - - if (body) { - data = JSON.parse(body); - } else { - console.error( - "Error occured during parsing: ", - process.env.LOBBY_API_URL + "/" + resource, - "body: ", body, - "error: ", error, - "response", response - ); - } - - - if (resource === "lobby") { - cache[resource] = { - pollTime: Date.now(), - data: body - }; - } else if (resource === "countries") { - data = data.map(player => player.country); - const mapData = {}; - data.forEach(value => { - if (mapData[value] !== undefined) { - mapData[value] = mapData[value] + 1; - } else { - mapData[value] = 1; - } - }); - cache["countries"] = { - pollTime: Date.now(), - data: mapData - }; - } else { - cache[queryResource] = { - pollTime: Date.now(), - data: data.length.toString() - }; - } - isFetching = false; - return res.send(cache[resource].data); - }); -};