Better error handling + general cleanup #182

Merged
punctuations merged 11 commits from master into master 2021-12-07 16:06:33 -03:00
12 changed files with 37 additions and 19 deletions
Showing only changes of commit 86f6bee6f6 - Show all commits

View file

@ -9,8 +9,9 @@ let caches = [{"stars": null, "coins": null, "demons": null, "diamonds": null},
module.exports = async (app, req, res, post) => {
if (req.isGDPS) return res.send("-2")
if (!app.sheetsKey) return res.send([])
// What does this mean, good or bad?
if (req.isGDPS) return res.status(418).send("-2")
if (!app.sheetsKey) return res.status(500).send([])
let gdMode = post || req.query.hasOwnProperty("gd")
let modMode = !gdMode && req.query.hasOwnProperty("mod")
let cache = caches[gdMode ? 2 : modMode ? 1 : 0]
@ -18,7 +19,7 @@ module.exports = async (app, req, res, post) => {
let type = req.query.type ? req.query.type.toLowerCase() : 'stars'
if (type == "usercoins") type = "coins"
if (!indexes.includes(type)) type = "stars"
if (lastIndex[modMode ? 1 : 0][type] + 600000 > Date.now() && cache[type]) return res.send(gdMode ? cache[type] : JSON.parse(cache[type])) // 10 min cache
if (lastIndex[modMode ? 1 : 0][type] + 600000 > Date.now() && cache[type]) return res.status(200).send(gdMode ? cache[type] : JSON.parse(cache[type])) // 10 min cache
sheet.useApiKey(app.sheetsKey)
sheet.loadInfo().then(async () => {
@ -40,7 +41,7 @@ module.exports = async (app, req, res, post) => {
caches[modMode ? 1 : 0][type] = JSON.stringify(leaderboard)
caches[2][type] = gdFormatting
lastIndex[modMode ? 1 : 0][type] = Date.now()
return res.send(gdMode ? gdFormatting : leaderboard)
return res.status(200).send(gdMode ? gdFormatting : leaderboard)
})
}

View file

@ -2,12 +2,13 @@ const request = require('request')
module.exports = async (app, req, res) => {
if (req.isGDPS) return res.send("0")
// What is this supposed to notify, good or bad?
if (req.isGDPS) return res.status(418).send("0")
request.post('http://robtopgames.com/Boomlings/get_scores.php', {
form : { secret: app.config.params.secret || "Wmfd2893gb7", name: "Player" } }, function(err, resp, body) {
if (err || !body || body == 0) return res.send("0")
if (err || !body || body == 0) return res.status(500).send("0")
let info = body.split(" ").filter(x => x.includes(";"))
let users = []
@ -36,7 +37,7 @@ module.exports = async (app, req, res) => {
users.push(user)
})
return res.send(users)
return res.status(200).send(users)
})
}

View file

@ -1,6 +1,6 @@
module.exports = async (app, req, res) => {
if (req.offline) return res.send("-1")
if (req.offline) return res.status(500).send("-1")
let amount = 100;
let count = req.query.count ? parseInt(req.query.count) : null
@ -18,9 +18,9 @@ module.exports = async (app, req, res) => {
req.gdRequest('getGJLevelScores211', params, function(err, resp, body) {
if (err) return res.send({error: true, lastWorked: app.timeSince(req.id)})
if (err) return res.status(500).send({error: true, lastWorked: app.timeSince(req.id)})
scores = body.split('|').map(x => app.parseResponse(x)).filter(x => x[1])
if (!scores.length) return res.send([])
if (!scores.length) return res.status(500).send([])
else app.trackSuccess(req.id)
scores.forEach(x => {
@ -43,7 +43,7 @@ module.exports = async (app, req, res) => {
app.userCache(req.id, x.accountID, x.playerID, x.username)
})
return res.send(scores.slice(0, amount))
return res.status(200).send(scores.slice(0, amount))
})
}

View file

@ -1,6 +1,6 @@
module.exports = async (app, req, res) => {
if (req.offline) return res.send("-1")
if (req.offline) return res.status(500).send("-1")
let amount = 100;
let count = req.query.count ? parseInt(req.query.count) : null
@ -16,9 +16,9 @@ module.exports = async (app, req, res) => {
req.gdRequest('getGJScores20', params, function(err, resp, body) {
if (err) return res.send("-1")
if (err) return res.status(500).send("-1")
scores = body.split('|').map(x => app.parseResponse(x)).filter(x => x[1])
if (!scores.length) return res.send("-1")
if (!scores.length) return res.status(500).send("-1")
scores.forEach(x => {
let keys = Object.keys(x)
@ -42,6 +42,6 @@ module.exports = async (app, req, res) => {
keys.forEach(k => delete x[k])
app.userCache(req.id, x.accountID, x.playerID, x.username)
})
return res.send(scores)
return res.status(200).send(scores)
})
}

View file

@ -1,5 +1,7 @@
module.exports = async (app, req, res) => {
if (req.method !== 'POST') return res.status(405).send("Method not allowed.")
if (!req.body.accountID) return res.status(400).send("No account ID provided!")
if (!req.body.password) return res.status(400).send("No password provided!")

View file

@ -1,4 +1,6 @@
module.exports = async (app, req, res, api) => {
module.exports = async (app, req, res) => {
if (req.method !== 'POST') return res.status(405).send("Method not allowed.")
if (!req.body.accountID) return res.status(400).send("No account ID provided!")
if (!req.body.password) return res.status(400).send("No password provided!")

View file

@ -1,4 +1,6 @@
module.exports = async (app, req, res, api) => {
module.exports = async (app, req, res) => {
if (req.method !== 'POST') return res.status(405).send("Method not allowed.")
if (!req.body.accountID) return res.status(400).send("No account ID provided!")
if (!req.body.password) return res.status(400).send("No password provided!")

View file

@ -1,4 +1,6 @@
module.exports = async (app, req, res, api) => {
module.exports = async (app, req, res) => {
if (req.method !== 'POST') return res.status(405).send("Method not allowed.")
if (req.body.count) return app.run.countMessages(app, req, res)
if (!req.body.accountID) return res.status(400).send("No account ID provided!")

View file

@ -1,4 +1,6 @@
module.exports = async (app, req, res, api) => {
module.exports = async (app, req, res) => {
if (req.method !== 'POST') return res.status(405).send("Method not allowed.")
if (!req.body.targetID) return res.status(400).send("No target ID provided!")
if (!req.body.message) return res.status(400).send("No message provided!")

View file

@ -3,6 +3,8 @@ function sha1(data) { return crypto.createHash("sha1").update(data, "binary").di
module.exports = async (app, req, res) => {
if (req.method !== 'POST') return res.status(405).send("Method not allowed.")
if (!req.body.ID) return res.status(400).send("No ID provided!")
if (!req.body.accountID) return res.status(400).send("No account ID provided!")
if (!req.body.password) return res.status(400).send("No password provided!")

View file

@ -11,6 +11,8 @@ function getTime(time) {
module.exports = async (app, req, res) => {
if (req.method !== 'POST') return res.status(405).send("Method not allowed.")
if (!req.body.comment) return res.status(400).send("No comment provided!")
if (!req.body.username) return res.status(400).send("No username provided!")
if (!req.body.levelID) return res.status(400).send("No level ID provided!")

View file

@ -3,6 +3,8 @@ function sha1(data) { return crypto.createHash("sha1").update(data, "binary").di
module.exports = async (app, req, res) => {
if (req.method !== 'POST') return res.status(405).send("Method not allowed.")
if (!req.body.comment) return res.status(400).send("No comment provided!")
if (!req.body.username) return res.status(400).send("No username provided!")
if (!req.body.accountID) return res.status(400).send("No account ID provided!")