From f70cf00fd17bd2bf5faf4496b8cd4fce7ca20240 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Rynning-T=C3=B8nnesen?= Date: Sun, 18 Mar 2018 18:19:42 +0100 Subject: [PATCH] Fixed issue with channels having spaces --- server/handlers/chat.js | 9 +++-- server/handlers/frontpage.js | 1 + server/handlers/functions.js | 1 + server/handlers/io.js | 37 +++++++++++---------- server/handlers/list.js | 21 +++++++----- server/handlers/list_change.js | 9 +++-- server/handlers/list_settings.js | 4 +-- server/handlers/notifications.js | 1 + server/handlers/search.js | 4 ++- server/handlers/suggestions.js | 3 +- server/public/layouts/admin/main.handlebars | 2 +- 11 files changed, 55 insertions(+), 37 deletions(-) diff --git a/server/handlers/chat.js b/server/handlers/chat.js index ebe4d149..1255eb2b 100644 --- a/server/handlers/chat.js +++ b/server/handlers/chat.js @@ -10,6 +10,7 @@ function get_history(channel, all, socket) { channel: channel, }; } + channel = channel.replace(/ /g,''); var pass = ""; if(!query.all) { Functions.getSessionAdminUser(Functions.getSession(socket), channel, function(userpass) { @@ -28,6 +29,7 @@ function get_history(channel, all, socket) { } function getAndSendLogs(channel, all, socket, pass, query) { + channel = channel.replace(/ /g,''); db.collection("chat_logs").find(query, { from: 1, createdAt: 1, @@ -62,7 +64,7 @@ function chat(msg, guid, offline, socket) { socket.emit('update_required', result); return; } - var coll = msg.channel.toLowerCase(); + var coll = msg.channel.toLowerCase().replace(/ /g,''); Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass) { msg.pass = userpass; db.collection(coll + "_settings").find(function(err, docs){ @@ -110,7 +112,7 @@ function all_chat(msg, guid, offline, socket) { socket.emit('update_required', result); return; } - var coll = msg.channel.toLowerCase(); + var coll = msg.channel.toLowerCase().replace(/ /g,''); var data = msg.data; Functions.check_inlist(coll, guid, socket, offline); @@ -201,7 +203,7 @@ function namechange(data, guid, socket, tried) { //socket.emit('name', {type: "name", accepted: true}); if(old_name != name && !first) { if(data.hasOwnProperty("channel") && typeof(data.channel) == "string") { - io.to(data.channel).emit('chat', {from: old_name, msg: " changed name to " + name}); + io.to(data.channel.replace(/ /g,'')).emit('chat', {from: old_name, msg: " changed name to " + name}); io.sockets.emit('chat.all', {from: old_name , msg: " changed name to " + name, channel: data.channel}); } } @@ -226,6 +228,7 @@ function namechange(data, guid, socket, tried) { } function removename(guid, coll, socket) { + coll = coll.replace(/ /g,''); db.collection("user_names").find({"guid": guid}, function(err, docs) { if(docs.length == 1) { var old_name = docs[0].name; diff --git a/server/handlers/frontpage.js b/server/handlers/frontpage.js index 5cda8083..2514aa26 100644 --- a/server/handlers/frontpage.js +++ b/server/handlers/frontpage.js @@ -18,6 +18,7 @@ function frontpage_lists(msg, socket) { } function update_frontpage(coll, id, title, callback) { + coll = coll.replace(/ /g,''); db.collection("frontpage_lists").update({_id: coll}, {$set: { id: id, title: title, diff --git a/server/handlers/functions.js b/server/handlers/functions.js index 95295047..8d481241 100644 --- a/server/handlers/functions.js +++ b/server/handlers/functions.js @@ -59,6 +59,7 @@ function get_short_id(socket) { function check_inlist(coll, guid, socket, offline) { + coll = coll.replace(/ /g,''); if(!offline && coll != undefined){ db.collection("connected_users").update({"_id": coll}, {$addToSet:{users: guid}}, {upsert: true}, function(err, updated) { if(updated.nModified > 0 || updated.upserted != undefined) { diff --git a/server/handlers/io.js b/server/handlers/io.js index 09e52db0..a93570fb 100644 --- a/server/handlers/io.js +++ b/server/handlers/io.js @@ -35,6 +35,7 @@ module.exports = function() { socket.on('self_ping', function(msg) { var channel = msg.channel; + channel = channel.replace(/ /g,''); if(offline) { db.collection("connected_users").update({"_id": "offline_users"}, {$addToSet: {users: guid}}, {upsert: true}, function(err, docs){}); } else { @@ -68,7 +69,7 @@ module.exports = function() { guid = msg.guid; socketid = msg.socket_id; socket.zoff_id = socketid; - coll = msg.channel.toLowerCase(); + coll = msg.channel.toLowerCase().replace(/ /g,''); in_list = true; chromecast_object = true; socket.join(coll); @@ -86,7 +87,7 @@ module.exports = function() { socket.on("error_video", function(msg) { try { - var _list = msg.channel; + var _list = msg.channel.replace(/ /g,''); if(_list.length == 0) return; coll = emojiStrip(_list).toLowerCase(); coll = coll.replace("_", ""); @@ -113,11 +114,11 @@ module.exports = function() { }); socket.on('suggest_thumbnail', function(msg){ - Suggestions.thumbnail(msg, coll, guid, offline, socket); + Suggestions.thumbnail(msg, coll.replace(/ /g,''), guid, offline, socket); }); socket.on('suggest_description', function(msg){ - Suggestions.description(msg, coll, guid, offline, socket); + Suggestions.description(msg, coll.replace(/ /g,''), guid, offline, socket); }); socket.on("namechange", function(msg) { @@ -155,7 +156,7 @@ module.exports = function() { return; } var status = msg.status; - var channel = msg.channel; + var channel = msg.channel.replace(/ /g,''); if(status){ in_list = false; offline = true; @@ -215,7 +216,7 @@ module.exports = function() { socket.emit('update_required', result); return; } - Chat.get_history(msg.channel, msg.all, socket); + Chat.get_history(msg.channel.replace(/ /g,''), msg.all, socket); }); socket.on('chat', function (msg) { @@ -246,7 +247,7 @@ module.exports = function() { socket.on('list', function(msg) { try { - var _list = msg.channel; + var _list = msg.channel.replace(/ /g,''); if(_list.length == 0) return; coll = emojiStrip(_list).toLowerCase(); coll = coll.replace("_", ""); @@ -267,7 +268,7 @@ module.exports = function() { { if(coll === undefined) { try { - coll = obj.channel.toLowerCase(); + coll = obj.channel.toLowerCase().replace(/ /g,''); if(coll.length == 0) return; coll = emojiStrip(coll).toLowerCase(); coll = coll.replace("_", ""); @@ -284,7 +285,7 @@ module.exports = function() { { if(coll !== undefined) { try { - coll = arr.list; + coll = arr.list.replace(/ /g,''); if(coll.length == 0) return; coll = emojiStrip(coll).toLowerCase(); coll = coll.replace("_", ""); @@ -300,7 +301,7 @@ module.exports = function() { socket.on('delete_all', function(msg) { if(coll !== undefined) { try { - coll = msg.channel.toLowerCase(); + coll = msg.channel.toLowerCase().replace(/ /g,''); if(coll.length == 0) return; coll = emojiStrip(coll).toLowerCase(); coll = coll.replace("_", ""); @@ -318,7 +319,7 @@ module.exports = function() { { if(coll !== undefined) { try { - coll = msg.channel.toLowerCase(); + coll = msg.channel.toLowerCase().replace(/ /g,''); if(coll.length == 0) return; coll = emojiStrip(coll).toLowerCase(); coll = coll.replace("_", ""); @@ -333,24 +334,24 @@ module.exports = function() { socket.on('password', function(inp) { - ListSettings.password(inp, coll, guid, offline, socket); + ListSettings.password(inp, coll.replace(/ /g,''), guid, offline, socket); }); socket.on('skip', function(list) { - List.skip(list, guid, coll, offline, socket); + List.skip(list, guid, coll.replace(/ /g,''), offline, socket); }); socket.on('conf', function(params) { - ListSettings.conf_function(params, coll, guid, offline, socket); + ListSettings.conf_function(params, coll.replace(/ /g,''), guid, offline, socket); }); socket.on('shuffle', function(msg) { if(coll !== undefined) { try { - coll = msg.channel.toLowerCase(); + coll = msg.channel.toLowerCase().replace(/ /g,''); if(coll.length == 0) return; coll = emojiStrip(coll).toLowerCase(); coll = coll.replace("_", ""); @@ -367,7 +368,7 @@ module.exports = function() { { if(coll === undefined && obj !== undefined && obj.channel !== undefined){ try { - coll = obj.channel.toLowerCase(); + coll = obj.channel.toLowerCase().replace(/ /g,''); if(coll.length == 0) return; coll = emojiStrip(coll).toLowerCase(); coll = coll.replace("_", ""); @@ -393,7 +394,7 @@ module.exports = function() { socket.on("left_channel", function(msg) { if(msg.hasOwnProperty("channel") && msg.channel != "" && typeof(msg.channel) == "string") { - coll = msg.channel; + coll = msg.channel.replace(/ /g,''); List.left_channel(coll, guid, short_id, in_list, socket, false); } }) @@ -418,7 +419,7 @@ module.exports = function() { if(!obj.hasOwnProperty("channel") || typeof(obj.channel) != "string") if(coll !== undefined) { try { - coll = obj.channel.toLowerCase(); + coll = obj.channel.toLowerCase().replace(/ /g,''); if(coll.length == 0) return; coll = emojiStrip(coll).toLowerCase(); coll = coll.replace("_", ""); diff --git a/server/handlers/list.js b/server/handlers/list.js index b2d1d2fa..227db2b0 100644 --- a/server/handlers/list.js +++ b/server/handlers/list.js @@ -46,7 +46,7 @@ function list(msg, guid, coll, offline, socket) { socket.emit('update_required', result); return; } - coll = msg.channel.toLowerCase(); + coll = msg.channel.toLowerCase().replace(/ /g,''); var pass = crypto.createHash('sha256').update(Functions.decrypt_string(socketid, msg.pass)).digest("base64"); db.collection('frontpage_lists').find({"_id": coll}, function(err, frontpage_lists){ if(frontpage_lists.length == 1) @@ -108,7 +108,7 @@ function skip(list, guid, coll, offline, socket) { if(coll == undefined && list.hasOwnProperty('channel')) coll = list.channel.toLowerCase(); if(coll !== undefined) { try { - coll = list.channel.toLowerCase(); + coll = list.channel.toLowerCase().replace(/ /g,''); if(coll.length == 0) return; coll = emojiStrip(coll).toLowerCase(); coll = coll.replace("_", ""); @@ -225,6 +225,7 @@ function skip(list, guid, coll, offline, socket) { } function change_song(coll, error, id, callback, socket) { + coll = coll.replace(/ /g,''); db.collection(coll + "_settings").find(function(err, docs){ var startTime = docs[0].startTime; if(docs !== null && docs.length !== 0) @@ -321,8 +322,8 @@ function change_song(coll, error, id, callback, socket) { }); } -function change_song_post(coll, next_song, callback, socket) -{ +function change_song_post(coll, next_song, callback, socket) { + coll = coll.replace(/ /g,''); db.collection(coll).aggregate([{ $match:{ now_playing:false, @@ -381,6 +382,7 @@ function change_song_post(coll, next_song, callback, socket) function send_list(coll, socket, send, list_send, configs, shuffled) { + coll = coll.replace(/ /g,''); db.collection(coll + "_settings").find({id: "config"}, function(err, _conf){ var conf = _conf; if(conf.length == 0) { @@ -535,6 +537,7 @@ function end(obj, coll, guid, offline, socket) { socket.emit("update_required", result); return; } + coll = coll.replace(/ /g,''); Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass) { obj.pass = userpass; @@ -578,8 +581,8 @@ function end(obj, coll, guid, offline, socket) { } } -function send_play(coll, socket, broadcast) -{ +function send_play(coll, socket, broadcast) { + coll = coll.replace(/ /g,''); db.collection(coll).find({now_playing:true}, function(err, np){ db.collection(coll + "_settings").find(function(err, conf){ if(err !== null) console.log(err); @@ -624,6 +627,7 @@ function send_play(coll, socket, broadcast) } function sendColor(coll, socket, id) { + coll = coll.replace(/ /g,''); var url = 'https://img.youtube.com/vi/'+id+'/mqdefault.jpg'; Jimp.read(url).then(function (image) { @@ -637,6 +641,7 @@ function sendColor(coll, socket, id) { } function getNextSong(coll, callback) { + coll = coll.replace(/ /g,''); db.collection(coll).aggregate([{ $match:{ views:{ @@ -663,9 +668,9 @@ function getNextSong(coll, callback) { }); } -function left_channel(coll, guid, short_id, in_list, socket, change) -{ +function left_channel(coll, guid, short_id, in_list, socket, change) { if(!coll) return; + coll = coll.replace(/ /g,''); db.collection("connected_users").update({"_id": coll}, {$pull: {users: guid}}, function(err, updated) { if(updated.nModified > 0) { db.collection("connected_users").find({"_id": coll}, function(err, new_doc){ diff --git a/server/handlers/list_change.js b/server/handlers/list_change.js index d053d9d4..b8f4e7ae 100644 --- a/server/handlers/list_change.js +++ b/server/handlers/list_change.js @@ -89,6 +89,7 @@ function add_function(arr, coll, guid, offline, socket) { socket.emit('update_required', result); return; } + coll = coll.replace(/ /g,''); Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass) { arr.adminpass = adminpass; arr.userpass = userpass; @@ -277,7 +278,7 @@ function voteUndecided(msg, coll, guid, offline, socket) { socket.emit('update_required', result); return; } - coll = msg.channel.toLowerCase();; + coll = msg.channel.toLowerCase().replace(/ /g,''); Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass) { msg.adminpass = adminpass; msg.pass = userpass; @@ -337,7 +338,7 @@ function shuffle(msg, coll, guid, offline, socket) { socket.emit('update_required', result); return; } - coll = msg.channel.toLowerCase(); + coll = msg.channel.toLowerCase().replace(/ /g,''); Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass) { msg.adminpass = adminpass; @@ -405,7 +406,7 @@ function shuffle(msg, coll, guid, offline, socket) { function del(params, socket, socketid) { if(params.id){ var coll = emojiStrip(params.channel).toLowerCase(); - coll = coll.replace("_", ""); + coll = coll.replace("_", "").replace(/ /g,''); coll = encodeURIComponent(coll).replace(/\W/g, ''); coll = filter.clean(coll); db.collection(coll + "_settings").find(function(err, docs){ @@ -451,6 +452,7 @@ function delete_all(msg, coll, guid, offline, socket) { socket.emit('update_required', result); return; } + coll = coll.replace(/ /g,''); Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass, gotten) { msg.adminpass = adminpass; msg.pass = userpass; @@ -484,6 +486,7 @@ function delete_all(msg, coll, guid, offline, socket) { } function vote(coll, id, guid, socket, full_list, last) { + coll = coll.replace(/ /g,''); db.collection(coll).find({id:id, now_playing: false, type:"video"}, function(err, docs){ if(docs !== null && docs.length > 0 && !Functions.contains(docs[0].guids, guid)) { diff --git a/server/handlers/list_settings.js b/server/handlers/list_settings.js index fb112b4e..65eb5e91 100644 --- a/server/handlers/list_settings.js +++ b/server/handlers/list_settings.js @@ -29,7 +29,7 @@ function password(inp, coll, guid, offline, socket) { } catch(e) { return; } - + coll = coll.replace(/ /g,''); uncrypted = pw; pw = Functions.hash_pass(Functions.decrypt_string(socket.zoff_id, pw), true); Functions.check_inlist(coll, guid, socket, offline); @@ -84,7 +84,7 @@ function conf_function(params, coll, guid, offline, socket) { { if(coll !== undefined) { try { - coll = params.channel; + coll = params.channel.replace(/ /g,''); if(coll.length == 0) return; coll = emojiStrip(coll).toLowerCase(); coll = coll.replace("_", ""); diff --git a/server/handlers/notifications.js b/server/handlers/notifications.js index d5de5eec..171cc2ba 100644 --- a/server/handlers/notifications.js +++ b/server/handlers/notifications.js @@ -2,6 +2,7 @@ var path = require('path'); function requested_change(type, string, channel) { try { + channel = channel.replace(/ /g,''); var nodemailer = require('nodemailer'); var mailconfig = require(path.join(__dirname, '../config/mailconfig.js')); diff --git a/server/handlers/search.js b/server/handlers/search.js index f6201af5..6bce1d54 100644 --- a/server/handlers/search.js +++ b/server/handlers/search.js @@ -9,6 +9,7 @@ try { } function get_correct_info(song_generated, channel, broadcast, callback) { + channel = channel.replace(/ /g,''); request({ type: "GET", url: "https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id&key="+key+"&id=" + song_generated.id, @@ -84,7 +85,7 @@ function check_error_video(msg, channel) { } return; } - + channel = channel.replace(/ /g,''); request({ type: "GET", url: "https://www.googleapis.com/youtube/v3/videos?part=id&key="+key+"&id=" + msg.id, @@ -102,6 +103,7 @@ function check_error_video(msg, channel) { } function findSimilar(msg, channel, broadcast, callback) { + channel = channel.replace(/ /g,''); var yt_url = "https://www.googleapis.com/youtube/v3/search?key="+key+"&videoEmbeddable=true&part=id&type=video&order=viewCount&safeSearch=none&maxResults=5&q=" + encodeURIComponent(msg.title); request({ method: "GET", diff --git a/server/handlers/suggestions.js b/server/handlers/suggestions.js index dad39fdd..78c6b29c 100644 --- a/server/handlers/suggestions.js +++ b/server/handlers/suggestions.js @@ -23,6 +23,7 @@ function thumbnail(msg, coll, guid, offline, socket) { socket.emit("update_required", result); return; } + coll = coll.replace(/ /g,''); Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass) { msg.userpass = userpass; msg.adminpass = adminpass; @@ -73,7 +74,7 @@ function description(msg, coll, guid, offline, socket) { socket.emit("update_required", result); return; } - + coll = coll.replace(/ /g,''); Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass, gotten) { msg.userpass = userpass; msg.adminpass = adminpass; diff --git a/server/public/layouts/admin/main.handlebars b/server/public/layouts/admin/main.handlebars index 0c83103e..43b4bd67 100644 --- a/server/public/layouts/admin/main.handlebars +++ b/server/public/layouts/admin/main.handlebars @@ -15,7 +15,6 @@ - +