From b06944cb7717f6ad47a014eede9686fbcde69d60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Fern=C3=A1ndez=20Serrata?= <76864299+Rudxain@users.noreply.github.com> Date: Thu, 16 Jun 2022 20:47:01 -0400 Subject: [PATCH] Add files via upload --- api/messages/countMessages.js | 5 +++-- api/messages/deleteMessage.js | 6 ++++-- api/messages/fetchMessage.js | 16 ++++++++-------- api/messages/getMessages.js | 10 +++++----- api/messages/sendMessage.js | 5 +++-- 5 files changed, 23 insertions(+), 19 deletions(-) diff --git a/api/messages/countMessages.js b/api/messages/countMessages.js index 717457b..d4bb035 100644 --- a/api/messages/countMessages.js +++ b/api/messages/countMessages.js @@ -1,3 +1,4 @@ +"use strict"; module.exports = async (app, req, res) => { if (req.method !== 'POST') return res.status(405).send("Method not allowed.") @@ -14,10 +15,10 @@ module.exports = async (app, req, res) => { req.gdRequest('getGJUserInfo20', params, function (err, resp, body) { if (err) return res.status(400).send(`Error counting messages! Messages get blocked a lot so try again later, or make sure your username and password are entered correctly. Last worked: ${app.timeSince(req.id)} ago.`) - else app.trackSuccess(req.id) + app.trackSuccess(req.id) let count = app.parseResponse(body)[38] if (!count) return res.status(400).send("Error fetching unread messages!") - else res.send(count) + res.send(count) }) } \ No newline at end of file diff --git a/api/messages/deleteMessage.js b/api/messages/deleteMessage.js index 8b6cc26..c08c730 100644 --- a/api/messages/deleteMessage.js +++ b/api/messages/deleteMessage.js @@ -1,3 +1,4 @@ +"use strict"; module.exports = async (app, req, res) => { if (req.method !== 'POST') return res.status(405).send("Method not allowed.") @@ -9,15 +10,16 @@ module.exports = async (app, req, res) => { let params = { accountID: req.body.accountID, gjp: app.xor.encrypt(req.body.password, 37526), + // serialize to CSV if needed messages: Array.isArray(req.body.id) ? req.body.id.map(x => x.trim()).join(",") : req.body.id, } - let deleted = params.messages.split(",").length + let deleted = params.messages.split(",").length // CSV record count req.gdRequest('deleteGJMessages20', params, function (err, resp, body) { if (body != 1) return res.status(400).send(`The Geometry Dash servers refused to delete the message! Try again later, or make sure your username and password are entered correctly. Last worked: ${app.timeSince(req.id)} ago.`) - else res.send(`${deleted == 1 ? "1 message" : `${deleted} messages`} deleted!`) + res.send(`${deleted} message${deleted == 1 ? "" : "s"} deleted!`) app.trackSuccess(req.id) }) diff --git a/api/messages/fetchMessage.js b/api/messages/fetchMessage.js index edb871e..4265478 100644 --- a/api/messages/fetchMessage.js +++ b/api/messages/fetchMessage.js @@ -1,3 +1,4 @@ +"use strict"; module.exports = async (app, req, res) => { if (req.method !== 'POST') return res.status(405).send("Method not allowed.") @@ -14,23 +15,22 @@ module.exports = async (app, req, res) => { req.gdRequest('downloadGJMessage20', params, function (err, resp, body) { if (err) return res.status(400).send(`Error fetching message! Try again later, or make sure your username and password are entered correctly. Last worked: ${app.timeSince(req.id)} ago.`) - else app.trackSuccess(req.id) + app.trackSuccess(req.id) let x = app.parseResponse(body) let msg = {} - msg.id = x[1]; + msg.id = x[1] msg.playerID = x[3] msg.accountID = x[2] msg.author = x[6] msg.subject = Buffer.from(x[4], "base64").toString().replace(/^Re: ☆/, "Re: ") msg.content = app.xor.decrypt(x[5], 14251) msg.date = x[7] + req.timestampSuffix - if (msg.subject.endsWith("☆") || msg.subject.startsWith("☆")) { - if (msg.subject.endsWith("☆")) msg.subject = msg.subject.slice(0, -1) - else msg.subject = msg.subject.slice(1) - msg.browserColor = true - } - + if (/^☆|☆$/.test(msg.subject)) { + msg.subject = msg.subject.slice(...(msg.subject.endsWith("☆") ? [0, -1] : [1])) + msg.browserColor = true + } + return res.send(msg) }) diff --git a/api/messages/getMessages.js b/api/messages/getMessages.js index 40da8a3..154ba01 100644 --- a/api/messages/getMessages.js +++ b/api/messages/getMessages.js @@ -1,3 +1,4 @@ +"use strict"; module.exports = async (app, req, res) => { if (req.method !== 'POST') return res.status(405).send("Method not allowed.") @@ -23,17 +24,16 @@ module.exports = async (app, req, res) => { messages.forEach(x => { let msg = {} - msg.id = x[1]; + msg.id = x[1] msg.playerID = x[3] msg.accountID = x[2] msg.author = x[6] msg.subject = Buffer.from(x[4], "base64").toString().replace(/^Re: ☆/, "Re: ") msg.date = x[7] + req.timestampSuffix msg.unread = x[8] != "1" - if (msg.subject.endsWith("☆") || msg.subject.startsWith("☆")) { - if (msg.subject.endsWith("☆")) msg.subject = msg.subject.slice(0, -1) - else msg.subject = msg.subject.slice(1) - msg.browserColor = true + if (/^☆|☆$/.test(msg.subject)) { + msg.subject = msg.subject.slice(...(msg.subject.endsWith("☆") ? [0, -1] : [1])) + msg.browserColor = true } app.userCache(req.id, msg.accountID, msg.playerID, msg.author) diff --git a/api/messages/sendMessage.js b/api/messages/sendMessage.js index 36bb9c6..5766bfc 100644 --- a/api/messages/sendMessage.js +++ b/api/messages/sendMessage.js @@ -1,3 +1,4 @@ +"use strict"; module.exports = async (app, req, res) => { if (req.method !== 'POST') return res.status(405).send("Method not allowed.") @@ -7,7 +8,7 @@ module.exports = async (app, req, res) => { 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!") - let subject = Buffer.from(req.body.subject ? (req.body.color ? "☆" : "") + (req.body.subject.slice(0, 50)) : (req.body.color ? "☆" : "") + "No subject").toString('base64').replace(/\//g, '_').replace(/\+/g, "-") + let subject = Buffer.from((req.body.color ? "☆" : "") + (req.body.subject ? req.body.subject.slice(0, 50) : "No subject")).toString('base64').replace('/', '_').replace('+', '-') let body = app.xor.encrypt(req.body.message.slice(0, 300), 14251) let params = req.gdParams({ @@ -19,7 +20,7 @@ module.exports = async (app, req, res) => { req.gdRequest('uploadGJMessage20', params, function (err, resp, body) { if (body != 1) return res.status(400).send(`The Geometry Dash servers refused to send the message! Try again later, or make sure your username and password are entered correctly. Last worked: ${app.timeSince(req.id)} ago.`) - else res.send('Message sent!') + res.send('Message sent!') app.trackSuccess(req.id) })