Added Endpoints and AJAX Helper Functions for emote management, as well as imporvements to link embedding.

This commit is contained in:
rainbow napkin 2024-12-17 21:51:34 -05:00
parent b9283607d6
commit 255e6e0d7f
7 changed files with 63 additions and 27 deletions

View file

@ -48,21 +48,28 @@ module.exports.post = async function(req, res){
//if we have one
if(emoteDB != null){
//Throw a shit fit
return errorHandler(res, `Emote '[${name}]' already exists!`);
return errorHandler(res, `Emote [${name}] already exists!`);
}
const linkObj = linkUtils.markLink(link);
//Initialize the emote object from linkUtils
var emoteObj = await linkUtils.markLink(link);
console.log(linkObj);
//If we didn't get a valid image/video file
if(emoteObj.type != 'image' && emoteObj.type != 'video'){
//AAAAAAAAAAAAAAAAAA
return errorHandler(res, 'URL either does not lead to a valid image/video file, or leads to one that is larger than 4MB');
}
/*
//Add the toke
await tokeCommandModel.create({command});
//Add the name to the emoteObj
emoteObj.name = name;
//Create the emote document
await emoteModel.create(emoteObj);
//Return the updated command list
res.status(200);
return res.send(await tokeCommandModel.getCommandStrings());
*/
return res.send(await emoteModel.getEmotes());
}else{
//otherwise scream
res.status(400);
@ -80,20 +87,22 @@ module.exports.delete = async function(req, res){
//if they're empty
if(validResult.isEmpty()){
/*
const {command} = matchedData(req);
const tokeDB = await tokeCommandModel.findOne({command});
//Pull name from sanatized/validated input
const {name} = matchedData(req);
//query for existing emote
const emoteDB = await emoteModel.findOne({name});
if(tokeDB == null){
return errorHandler(res, `Cannot delete non-existant toke command '!${command}'!`);
//if we don't have one
if(emoteDB == null){
//Throw a shit fit
return errorHandler(res, `Cannot delete non-existant emote: [${name}]!`);
}
await tokeDB.deleteOne();
await emoteDB.deleteOne();
//Return the updated command list
res.status(200);
return res.send(await tokeCommandModel.getCommandStrings());
*/
return res.send(await emoteModel.getEmotes());
}else{
//otherwise scream
res.status(400);

View file

@ -58,5 +58,6 @@ router.delete('/tokeCommands', permissionSchema.reqPermCheck("editTokeCommands")
//emote
router.get('/emote', permissionSchema.reqPermCheck('adminPanel'), emoteController.get);
router.post('/emote', permissionSchema.reqPermCheck('editEmotes'), emoteValidator.name(), emoteValidator.link(), emoteController.post);
router.delete('/emote', permissionSchema.reqPermCheck('editEmotes'), emoteValidator.name(), emoteController.delete);
module.exports = router;

View file

@ -56,13 +56,13 @@ emoteSchema.statics.loadDefaults = async function(){
//if the emote doesn't exist
if(!foundEmote){
const emoteDB = await _this.create(emote);
console.log(`Loading default emote '${emote.name}' into DB from defaultEmote.json`);
console.log(`Loading default emote [${emote.name}] into DB from defaultEmote.json`);
}
}catch(err){
if(emote != null){
console.log(err);
console.log(`Error loading emote '${emote.name}':`);
console.log(`Error loading emote [${emote.name}]:`);
}else{
console.log("Error, null emote:");
}

View file

@ -20,11 +20,14 @@ const validator = require('validator');//No express here, so regular validator i
module.exports.markLink = async function(link){
//Set max file size to 4MB
const maxSize = 4000000;
//Set badLink type
var type = 'deadLink';
//Assume links are guilty until proven innocent
var type = "malformedLink"
//Make sure we have an actual, factual URL
if(validator.isURL(link)){
//The URL is valid, so this is at least a dead link
type = 'deadLink';
//Don't try this at home, we're what you call "Experts"
//TODO: Handle this shit simultaneously and send the chat before its done, then send updated types for each link as they're pulled individually
try{