/*Canopy - The next generation of stoner streaming software Copyright (C) 2024-2025 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 { body, checkExact } = require('express-validator'); const { Router } = require('express'); //local imports //Models const permissionModel = require("../../schemas/permissionSchema"); const channelModel = require("../../schemas/channel/channelSchema"); //Valudators const channelValidator = require("../../validators/channelValidator"); const accountValidator = require("../../validators/accountValidator"); const {channelPermissionValidator} = require("../../validators/permissionsValidator"); const tokebotValidator = require("../../validators/tokebotValidator"); const emoteValidator = require("../../validators/emoteValidator"); //Controllers const registerController = require("../../controllers/api/channel/registerController"); const listController = require("../../controllers/api/channel/listController"); const settingsController = require("../../controllers/api/channel/settingsController"); const permissionsController = require("../../controllers/api/channel/permissionsController") const rankController = require("../../controllers/api/channel/rankController"); const deleteController = require("../../controllers/api/channel/deleteController"); const banController = require("../../controllers/api/channel/banController"); const tokeCommandController = require("../../controllers/api/channel/tokeCommandController"); const emoteController = require('../../controllers/api/channel/emoteController'); //globals const router = Router(); //user authentication middleware router.use("/register",permissionModel.reqPermCheck("registerChannel")); router.use("/settings", channelValidator.name('chanName')); router.use("/permissions", channelValidator.name('chanName')); router.use("/rank", channelValidator.name('chanName')); router.use("/delete", channelValidator.name('chanName')); router.use("/ban", channelValidator.name('chanName')); router.use("/tokeCommand", channelValidator.name('chanName')); router.use("/emote", channelValidator.name('chanName')); //routing functions //register router.post('/register', channelValidator.name(), channelValidator.description(), channelValidator.thumbnail(), registerController.post); //list router.get('/list', channelModel.reqPermCheck("manageChannel"), listController.get); //settings router.get('/settings', channelModel.reqPermCheck("manageChannel"), settingsController.get); router.post('/settings', channelModel.reqPermCheck("changeSettings"), channelValidator.settingsMap(), settingsController.post); //permissions router.get('/permissions', channelModel.reqPermCheck("manageChannel"), permissionsController.get); router.post('/permissions', channelModel.reqPermCheck("changePerms"), checkExact(channelPermissionValidator.channelPermissionsMap()), permissionsController.post); //rank router.get('/rank', channelModel.reqPermCheck("manageChannel"), rankController.get); router.post('/rank', channelModel.reqPermCheck("changeRank"), accountValidator.user(), channelValidator.rank(), rankController.post); //delete router.post('/delete', channelModel.reqPermCheck("deleteChannel"), channelValidator.name('confirm'), deleteController.post); //ban router.get('/ban', channelModel.reqPermCheck("manageChannel"), banController.get); router.post('/ban', channelModel.reqPermCheck("banUser"), accountValidator.user(), body("banAlts").isBoolean(), body("expirationDays").isInt(), banController.post); router.delete('/ban', channelModel.reqPermCheck("banUser"), accountValidator.user(), banController.delete); //tokeCommand router.get('/tokeCommand', channelModel.reqPermCheck("manageChannel"), tokeCommandController.get); router.post('/tokeCommand', tokebotValidator.command(), channelModel.reqPermCheck("editTokeCommands"), tokeCommandController.post); router.delete('/tokeCommand', tokebotValidator.command(), channelModel.reqPermCheck("editTokeCommands"), tokeCommandController.delete); //emote router.get('/emote', channelModel.reqPermCheck("manageChannel"), emoteController.get); router.post('/emote', channelModel.reqPermCheck("editEmotes"), emoteValidator.name('emoteName'), emoteValidator.link(), emoteController.post); router.delete('/emote', channelModel.reqPermCheck("editEmotes"), emoteValidator.name('emoteName'), emoteController.delete); module.exports = router;