Better error handling + general cleanup #182
12 changed files with 37 additions and 19 deletions
|
@ -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)
|
||||
|
||||
})
|
||||
}
|
|
@ -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)
|
||||
|
||||
})
|
||||
}
|
|
@ -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))
|
||||
|
||||
})
|
||||
}
|
|
@ -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)
|
||||
})
|
||||
}
|
|
@ -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!")
|
||||
|
||||
|
|
|
@ -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!")
|
||||
|
|
|
@ -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!")
|
||||
|
|
|
@ -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!")
|
||||
|
|
|
@ -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!")
|
||||
|
|
|
@ -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!")
|
||||
|
|
|
@ -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!")
|
||||
|
|
|
@ -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!")
|
||||
|
|
Loading…
Reference in a new issue