From 575244ac53ab4583f1f3682bb9d239f67c5bf1c8 Mon Sep 17 00:00:00 2001 From: rainbow napkin Date: Sun, 15 Dec 2024 07:25:38 -0500 Subject: [PATCH] Basic housekeeping, as well as very basic work on per-channel !toke commands --- defaultTokes.json | 3 +- .../api/account/deleteController.js | 4 +- .../api/account/loginController.js | 4 +- .../api/account/logoutController.js | 4 +- .../api/account/rankEnumController.js | 4 +- .../api/account/registerController.js | 4 +- .../api/account/updateController.js | 4 +- .../api/admin/listChannelsController.js | 4 +- .../api/admin/listUsersController.js | 2 +- .../api/admin/permissionsController.js | 4 +- .../api/admin/tokeCommandController.js | 4 +- src/controllers/api/channel/banController.js | 6 +- .../api/channel/deleteController.js | 2 +- src/controllers/api/channel/listController.js | 2 +- .../api/channel/permissionsController.js | 6 +- .../api/channel/registerController.js | 4 +- .../api/channel/settingsController.js | 2 +- .../api/channel/tokeCommandController.js | 94 +++++++++++++++++++ src/controllers/indexController.js | 2 +- src/controllers/profileController.js | 2 +- src/schemas/channel/channelSchema.js | 6 +- www/js/utils.js | 7 +- 22 files changed, 139 insertions(+), 35 deletions(-) create mode 100644 src/controllers/api/channel/tokeCommandController.js diff --git a/defaultTokes.json b/defaultTokes.json index 28d51e6..6aa2618 100644 --- a/defaultTokes.json +++ b/defaultTokes.json @@ -334,6 +334,7 @@ "SmoothAsEggs", "nosedive", "rip", - "slorp" + "slorp", + "freeluigi" ] } \ No newline at end of file diff --git a/src/controllers/api/account/deleteController.js b/src/controllers/api/account/deleteController.js index eaf4e39..e71ce3a 100644 --- a/src/controllers/api/account/deleteController.js +++ b/src/controllers/api/account/deleteController.js @@ -19,8 +19,8 @@ const {validationResult, matchedData} = require('express-validator'); //local imports const {userModel} = require('../../../schemas/userSchema'); -const accountUtils = require('../../../utils/sessionUtils.js'); -const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils.js'); +const accountUtils = require('../../../utils/sessionUtils'); +const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils'); //api account functions module.exports.post = async function(req, res){ diff --git a/src/controllers/api/account/loginController.js b/src/controllers/api/account/loginController.js index 5ea734d..bf75084 100644 --- a/src/controllers/api/account/loginController.js +++ b/src/controllers/api/account/loginController.js @@ -18,8 +18,8 @@ along with this program. If not, see .*/ const {validationResult, matchedData} = require('express-validator'); //local imports -const accountUtils = require('../../../utils/sessionUtils.js'); -const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils.js'); +const accountUtils = require('../../../utils/sessionUtils'); +const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils'); //api account functions diff --git a/src/controllers/api/account/logoutController.js b/src/controllers/api/account/logoutController.js index 89a37b2..9511900 100644 --- a/src/controllers/api/account/logoutController.js +++ b/src/controllers/api/account/logoutController.js @@ -15,8 +15,8 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see .*/ //local imports -const accountUtils = require('../../../utils/sessionUtils.js'); -const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils.js'); +const accountUtils = require('../../../utils/sessionUtils'); +const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils'); module.exports.get = async function(req, res){ if(req.session.user){ diff --git a/src/controllers/api/account/rankEnumController.js b/src/controllers/api/account/rankEnumController.js index a176cdc..aafc415 100644 --- a/src/controllers/api/account/rankEnumController.js +++ b/src/controllers/api/account/rankEnumController.js @@ -15,8 +15,8 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see .*/ //local imports -const permissionModel = require('../../../schemas/permissionSchema.js'); -const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils.js'); +const permissionModel = require('../../../schemas/permissionSchema'); +const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils'); //api account functions module.exports.get = async function(req, res){ diff --git a/src/controllers/api/account/registerController.js b/src/controllers/api/account/registerController.js index 160139f..1ea0d2c 100644 --- a/src/controllers/api/account/registerController.js +++ b/src/controllers/api/account/registerController.js @@ -19,8 +19,8 @@ const {validationResult, matchedData} = require('express-validator'); //local imports const {userModel} = require('../../../schemas/userSchema'); -const userBanModel = require('../../../schemas/userBanSchema.js'); -const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils.js'); +const userBanModel = require('../../../schemas/userBanSchema'); +const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils'); module.exports.post = async function(req, res){ try{ diff --git a/src/controllers/api/account/updateController.js b/src/controllers/api/account/updateController.js index 0698002..de7bb3e 100644 --- a/src/controllers/api/account/updateController.js +++ b/src/controllers/api/account/updateController.js @@ -19,8 +19,8 @@ const {validationResult, matchedData} = require('express-validator'); //local imports const {userModel} = require('../../../schemas/userSchema'); -const accountUtils = require('../../../utils/sessionUtils.js'); -const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils.js'); +const accountUtils = require('../../../utils/sessionUtils'); +const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils'); module.exports.post = async function(req, res){ const validResult = validationResult(req); diff --git a/src/controllers/api/admin/listChannelsController.js b/src/controllers/api/admin/listChannelsController.js index 15af92b..77313b6 100644 --- a/src/controllers/api/admin/listChannelsController.js +++ b/src/controllers/api/admin/listChannelsController.js @@ -15,8 +15,8 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see .*/ //local imports -const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils.js'); -const channelModel = require('../../../schemas/channel/channelSchema.js'); +const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils'); +const channelModel = require('../../../schemas/channel/channelSchema'); //api list channel functions module.exports.get = async function(req, res){ diff --git a/src/controllers/api/admin/listUsersController.js b/src/controllers/api/admin/listUsersController.js index 4b6706e..be58b48 100644 --- a/src/controllers/api/admin/listUsersController.js +++ b/src/controllers/api/admin/listUsersController.js @@ -15,7 +15,7 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see .*/ //local imports -const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils.js'); +const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils'); const {userModel} = require('../../../schemas/userSchema'); //api list account functions diff --git a/src/controllers/api/admin/permissionsController.js b/src/controllers/api/admin/permissionsController.js index 498471b..18be9d2 100644 --- a/src/controllers/api/admin/permissionsController.js +++ b/src/controllers/api/admin/permissionsController.js @@ -18,8 +18,8 @@ along with this program. If not, see .*/ const {validationResult, matchedData} = require('express-validator'); //local imports -const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils.js'); -const permissionModel = require('../../../schemas/permissionSchema.js'); +const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils'); +const permissionModel = require('../../../schemas/permissionSchema'); //api permissions functions module.exports.get = async function(req, res){ diff --git a/src/controllers/api/admin/tokeCommandController.js b/src/controllers/api/admin/tokeCommandController.js index dcb7b95..6028125 100644 --- a/src/controllers/api/admin/tokeCommandController.js +++ b/src/controllers/api/admin/tokeCommandController.js @@ -18,8 +18,8 @@ along with this program. If not, see .*/ const {validationResult, matchedData} = require('express-validator'); //local imports -const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils.js'); -const tokeCommandModel = require('../../../schemas/tokebot/tokeCommandSchema.js'); +const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils'); +const tokeCommandModel = require('../../../schemas/tokebot/tokeCommandSchema'); module.exports.get = async function(req, res){ try{ diff --git a/src/controllers/api/channel/banController.js b/src/controllers/api/channel/banController.js index 8748731..1bcda0c 100644 --- a/src/controllers/api/channel/banController.js +++ b/src/controllers/api/channel/banController.js @@ -18,10 +18,10 @@ along with this program. If not, see .*/ const {validationResult, matchedData} = require('express-validator'); //local imports -const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils.js'); -const {userModel} = require('../../../schemas/userSchema.js'); +const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils'); +const {userModel} = require('../../../schemas/userSchema'); const channelModel = require('../../../schemas/channel/channelSchema'); -const permissionModel = require('../../../schemas/permissionSchema.js') +const permissionModel = require('../../../schemas/permissionSchema') //api account functions module.exports.get = async function(req, res){ diff --git a/src/controllers/api/channel/deleteController.js b/src/controllers/api/channel/deleteController.js index 4932a6d..2ca8aee 100644 --- a/src/controllers/api/channel/deleteController.js +++ b/src/controllers/api/channel/deleteController.js @@ -18,7 +18,7 @@ along with this program. If not, see .*/ const {validationResult, matchedData} = require('express-validator'); //local imports -const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils.js'); +const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils'); const channelModel = require('../../../schemas/channel/channelSchema'); //api account functions diff --git a/src/controllers/api/channel/listController.js b/src/controllers/api/channel/listController.js index 19797f8..5d5c1bd 100644 --- a/src/controllers/api/channel/listController.js +++ b/src/controllers/api/channel/listController.js @@ -16,7 +16,7 @@ along with this program. If not, see .*/ //local imports const channelModel = require('../../../schemas/channel/channelSchema'); -const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils.js'); +const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils'); //api account functions module.exports.get = async function(req, res){ diff --git a/src/controllers/api/channel/permissionsController.js b/src/controllers/api/channel/permissionsController.js index d44c27f..ee7a8e8 100644 --- a/src/controllers/api/channel/permissionsController.js +++ b/src/controllers/api/channel/permissionsController.js @@ -18,9 +18,9 @@ along with this program. If not, see .*/ const {validationResult, matchedData} = require('express-validator'); //local imports -const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils.js'); -const channelModel = require('../../../schemas/channel/channelSchema.js'); -const permissionModel = require('../../../schemas/permissionSchema.js'); +const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils'); +const channelModel = require('../../../schemas/channel/channelSchema'); +const permissionModel = require('../../../schemas/permissionSchema'); //api account functions module.exports.get = async function(req, res){ diff --git a/src/controllers/api/channel/registerController.js b/src/controllers/api/channel/registerController.js index cc3b038..977e7ec 100644 --- a/src/controllers/api/channel/registerController.js +++ b/src/controllers/api/channel/registerController.js @@ -18,8 +18,8 @@ along with this program. If not, see .*/ const {validationResult, matchedData} = require('express-validator'); //local imports -const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils.js'); -const {userModel} = require('../../../schemas/userSchema.js'); +const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils'); +const {userModel} = require('../../../schemas/userSchema'); const channelModel = require('../../../schemas/channel/channelSchema'); //api account functions diff --git a/src/controllers/api/channel/settingsController.js b/src/controllers/api/channel/settingsController.js index e55fb85..c6d2bdc 100644 --- a/src/controllers/api/channel/settingsController.js +++ b/src/controllers/api/channel/settingsController.js @@ -18,7 +18,7 @@ along with this program. If not, see .*/ const {validationResult, matchedData} = require('express-validator'); //local imports -const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils.js'); +const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils'); const channelModel = require('../../../schemas/channel/channelSchema'); //api account functions diff --git a/src/controllers/api/channel/tokeCommandController.js b/src/controllers/api/channel/tokeCommandController.js new file mode 100644 index 0000000..4547a98 --- /dev/null +++ b/src/controllers/api/channel/tokeCommandController.js @@ -0,0 +1,94 @@ +/*Canopy - The next generation of stoner streaming software +Copyright (C) 2024 Rainbownapkin and the TTN Community + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see .*/ + +//npm imports +const {validationResult, matchedData} = require('express-validator'); + +//local imports +const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils'); +const channelModel = require('../../../schemas/channel/channelSchema'); + +module.exports.get = async function(req, res){ + try{ + const tokeList = await tokeCommandModel.getCommandStrings(); + + res.status(200); + return res.send(tokeList); + }catch(err){ + return exceptionHandler(res, err); + } +} + +module.exports.post = async function(req, res){ + try{ + //get validation error results + const validResult = validationResult(req); + + //if they're empty + if(validResult.isEmpty()){ + /* + const {command} = matchedData(req); + const tokeDB = await tokeCommandModel.findOne({command}); + + if(tokeDB != null){ + return errorHandler(res, `Toke command '!${command}' already exists!`); + } + + //Add the toke + await tokeCommandModel.create({command}); + + //Return the updated command list + res.status(200); + return res.send(await tokeCommandModel.getCommandStrings());*/ + }else{ + //otherwise scream + res.status(400); + return res.send({errors: validResult.array()}) + } + }catch(err){ + return exceptionHandler(res, err); + } +} + +module.exports.delete = async function(req, res){ + try{ + //get validation error results + const validResult = validationResult(req); + + //if they're empty + if(validResult.isEmpty()){ + /* + const {command} = matchedData(req); + const tokeDB = await tokeCommandModel.findOne({command}); + + if(tokeDB == null){ + return errorHandler(res, `Cannot delete non-existant toke command '!${command}'!`); + } + + await tokeDB.deleteOne(); + + //Return the updated command list + res.status(200); + return res.send(await tokeCommandModel.getCommandStrings());*/ + }else{ + //otherwise scream + res.status(400); + return res.send({errors: validResult.array()}) + } + }catch(err){ + return exceptionHandler(res, err); + } +} \ No newline at end of file diff --git a/src/controllers/indexController.js b/src/controllers/indexController.js index 42dbc60..aa8dadf 100644 --- a/src/controllers/indexController.js +++ b/src/controllers/indexController.js @@ -18,7 +18,7 @@ along with this program. If not, see .*/ const config = require('../../config.json'); //local imports -const {exceptionHandler, errorHandler} = require('../utils/loggerUtils.js'); +const {exceptionHandler, errorHandler} = require('../utils/loggerUtils'); const channelModel = require('../schemas/channel/channelSchema'); //root index functions diff --git a/src/controllers/profileController.js b/src/controllers/profileController.js index 5d75746..c3003c1 100644 --- a/src/controllers/profileController.js +++ b/src/controllers/profileController.js @@ -16,7 +16,7 @@ along with this program. If not, see .*/ //Local Imports const {userModel} = require('../schemas/userSchema'); -const {exceptionHandler, errorHandler} = require('../utils/loggerUtils.js'); +const {exceptionHandler, errorHandler} = require('../utils/loggerUtils'); //Config const config = require('../../config.json'); diff --git a/src/schemas/channel/channelSchema.js b/src/schemas/channel/channelSchema.js index 48c11b4..ca13a8a 100644 --- a/src/schemas/channel/channelSchema.js +++ b/src/schemas/channel/channelSchema.js @@ -72,7 +72,11 @@ const channelSchema = new mongoose.Schema({ enum: permissionModel.rankEnum } }], - //Thankfully we don't have to keep track of alts, ips, or deleted users so this should be a little easier :P + tokeCommands: [{ + type: mongoose.SchemaTypes.String, + required: true + }], + //Thankfully we don't have to keep track of alts, ips, or deleted users so this should be a lot easier than site-wide bans :P banList: [channelBanSchema] }); diff --git a/www/js/utils.js b/www/js/utils.js index 34911aa..b409fc0 100644 --- a/www/js/utils.js +++ b/www/js/utils.js @@ -228,7 +228,12 @@ class canopyUXUtils{ } calcWidth(px){ - return (px / window.innerWidth) * 100; + //I cannot fucking believe they added a clamp function to CSS before JS... + const width = (px / window.innerWidth) * 100; + + //Little hacky but this ensures that if our click dragger tries to do something that it should absolutely never be doing + //it'll be told to sit down, shut up, and fuck off. + return width < 100 ? width : 20; }