From 93b4b2e6008aaa3a4f91b9484cbce641b6341cd7 Mon Sep 17 00:00:00 2001 From: Ianyourgod Date: Tue, 5 Mar 2024 10:28:00 -0600 Subject: [PATCH] profanity list endpoints --- api/v1/routes/users/getProfanityList.js | 18 ++++++++++++ api/v1/routes/users/setProfanityList.js | 38 +++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 api/v1/routes/users/getProfanityList.js create mode 100644 api/v1/routes/users/setProfanityList.js diff --git a/api/v1/routes/users/getProfanityList.js b/api/v1/routes/users/getProfanityList.js new file mode 100644 index 0000000..5645694 --- /dev/null +++ b/api/v1/routes/users/getProfanityList.js @@ -0,0 +1,18 @@ +module.exports = (app, utils) => { + app.get('/api/v1/users/getProfanityList', async function (req, res) { + const packet = req.query; + if (!UserManager.isCorrectCode(packet.user, packet.passcode)) { + utils.error(res, 400, "Reauthenticate") + return; + } + if (!AdminAccountUsernames.get(Cast.toString(packet.user))) { + utils.error(res, 403, "FeatureDisabledForThisAccount") + return; + } + const illegalWords = utils.UserManager.getIllegalWords(); + + res.status(200); + res.header("Content-Type", 'application/json'); + res.json(illegalWords); + }); +} \ No newline at end of file diff --git a/api/v1/routes/users/setProfanityList.js b/api/v1/routes/users/setProfanityList.js new file mode 100644 index 0000000..f005a8e --- /dev/null +++ b/api/v1/routes/users/setProfanityList.js @@ -0,0 +1,38 @@ +module.exports = (app, utils) => { + app.get('/api/v1/users/setProfanityList', async function (req, res) { + const packet = req.query; + if (!await UserManager.isCorrectCode(packet.user, packet.passcode)) { + utils.error(res, 400, "Reauthenticate") + return; + } + if (!await utils.UserManager.isAdmin(Cast.toString(packet.user))) { + utils.error(res, 403, "FeatureDisabledForThisAccount") + return; + } + + const words = packet.json; + if (typeof words !== 'object') { + utils.error(res, 400, "InvalidData"); + return; + } + + const types = ["illegalWords", "illegalWebsites", "spacedOutWordsOnly", "potentiallyUnsafeWords", "potentiallyUnsafeWordsSpacedOut"]; + for (const key in words) { + if (typeof words[key] !== 'string') { + utils.error(res, 400, "InvalidData"); + return; + } + + if (!types.includes(key)) { + utils.error(res, 400, "InvalidData"); + return; + } + + await utils.UserManager.setIllegalWords(words[key], key); + } + + res.status(200); + res.header("Content-Type", 'application/json'); + res.json({ "success": true }); + }); +} \ No newline at end of file