From a4b6d2465138855799d3325a2d7aa1b1eaee6dcd Mon Sep 17 00:00:00 2001 From: Mystikfluu Date: Wed, 10 Aug 2022 21:47:59 +0200 Subject: [PATCH] move PersonalMessages to its own file --- routes/api/dms/PersonalMessages.js | 24 ++++++++++++++++++++++++ server.js | 18 ++---------------- 2 files changed, 26 insertions(+), 16 deletions(-) create mode 100644 routes/api/dms/PersonalMessages.js diff --git a/routes/api/dms/PersonalMessages.js b/routes/api/dms/PersonalMessages.js new file mode 100644 index 0000000..99acabe --- /dev/null +++ b/routes/api/dms/PersonalMessages.js @@ -0,0 +1,24 @@ +module.exports = { + "setup": function(router,con,server) { + router.get("/api/getPersonalPosts", async function(req,res) { + res.set("Access-Control-Allow-Origin","") + + let otherperson = req.query.otherperson + + if(typeof otherperson != "string" || otherperson.length > 100) { + res.status(400).json({"error": "invalid otherperson given"}) + return + } + + const columns = [ + "dms_user_name","dms_text","dms_time","dms_special_text","dms_id","dms_from_bot","dms_reply_id" + ] + + let sql = `select ${columns.join(",")} from ipost.dms where (dms_channel = ?) order by dms_id desc;` + con.query(sql, [xor(encodeURIComponent(res.locals.username),otherperson)], function (err, result) { + if (err) throw err; + res.json(result) + }); + }) + } +} \ No newline at end of file diff --git a/server.js b/server.js index 780d6f3..2c30abe 100644 --- a/server.js +++ b/server.js @@ -423,7 +423,8 @@ const toLoad = [ "api/options.js", "api/all.js", "api/settingshandler.js", - "api/post.js" + "api/post.js", + "api/dms/PersonalMessages.js" ] for (let i = 0; i < toLoad.length; i++) { @@ -612,22 +613,7 @@ router.get("/api/getPost", async function(req,res) { }); }) -router.get("/api/getPersonalPosts", async function(req,res) { - res.set("Access-Control-Allow-Origin","") - let otherperson = req.query.otherperson - - if(typeof otherperson != "string" || otherperson.length > 100) { - res.status(400).json({"error": "invalid otherperson given"}) - return - } - - let sql = `select dms_user_name,dms_text,dms_time,dms_special_text,dms_id,dms_from_bot,dms_reply_id from ipost.dms where (dms_channel = ?) order by dms_id desc;` - con.query(sql, [xor(encodeURIComponent(res.locals.username),otherperson)], function (err, result) { - if (err) throw err; - res.json(result) - }); -}) router.get("/api/getChannels", async function(req,res) { res.set("Access-Control-Allow-Origin","*")