From 5af7fe2d3704effc27afefd9ef0822b053c1cd56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Rynning-T=C3=B8nnesen?= Date: Sat, 23 Jun 2018 13:30:00 +0200 Subject: [PATCH] Now sending next song when asked to correctly, and to only the askee --- server/handlers/io.js | 6 +++--- server/handlers/list.js | 10 +++++++--- server/handlers/list_change.js | 6 +++--- server/routing/client/api.js | 4 ++-- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/server/handlers/io.js b/server/handlers/io.js index 39accbb8..da0843dc 100644 --- a/server/handlers/io.js +++ b/server/handlers/io.js @@ -79,15 +79,15 @@ module.exports = function() { }); socket.on('next_song', function(obj) { - if(obj == undefined || !obj.hasOwnProperty("channel") || !obj.hasOwnProperty("pass")) return; + if(obj == undefined || !obj.hasOwnProperty("channel")) return; db.collection(obj.channel + "_settings").find(function(e, docs) { if(docs.length == 0) return; var pass = ""; - if(obj.pass) { + if(obj.hasOwnProperty("pass")) { pass = crypto.createHash('sha256').update(Functions.decrypt_string(obj.pass)).digest("base64"); } if((docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || docs[0].userpass == pass))) { - List.getNextSong(obj.channel); + List.getNextSong(obj.channel, socket); } }); }); diff --git a/server/handlers/list.js b/server/handlers/list.js index b7747c79..c976b5a4 100644 --- a/server/handlers/list.js +++ b/server/handlers/list.js @@ -651,7 +651,7 @@ function send_play(coll, socket, broadcast) { if(socket === undefined) { io.to(coll).emit("np", toSend); // - getNextSong(coll) + getNextSong(coll, undefined) var url = 'https://img.youtube.com/vi/'+np[0].id+'/mqdefault.jpg'; if(np[0].source == "soundcloud") url = np[0].thumbnail; sendColor(coll, false, url); @@ -713,7 +713,7 @@ function sendColor(coll, socket, url, ajax, res) { }); } -function getNextSong(coll, callback) { +function getNextSong(coll, socket, callback) { //coll = coll.replace(/ /g,''); db.collection(coll).aggregate([{ $match:{ @@ -741,7 +741,11 @@ function getNextSong(coll, callback) { source = "soundcloud"; thumbnail = doc[0].thumbnail; } - io.to(coll).emit("next_song", {videoId: doc[0].id, title: doc[0].title, source: source, thumbnail: thumbnail}); + if(socket != undefined) { + socket.emit("next_song", {videoId: doc[0].id, title: doc[0].title, source: source, thumbnail: thumbnail}); + } else { + io.to(coll).emit("next_song", {videoId: doc[0].id, title: doc[0].title, source: source, thumbnail: thumbnail}); + } } if(typeof(callback) == "function") callback(); }); diff --git a/server/handlers/list_change.js b/server/handlers/list_change.js index 207e98dc..087ac3a2 100644 --- a/server/handlers/list_change.js +++ b/server/handlers/list_change.js @@ -432,7 +432,7 @@ function add_function(arr, coll, guid, offline, socket) { if(source != "soundcloud") Search.get_correct_info(new_song, coll, true); } db.collection("frontpage_lists").update({_id:coll}, {$inc:{count:1}, $set:{accessed: Functions.get_time()}}, {upsert:true}, function(err, docs){}); - List.getNextSong(coll); + List.getNextSong(coll, undefined); }); socket.emit("toast", "addedsong"); }); @@ -656,7 +656,7 @@ function shuffle(msg, coll, guid, offline, socket) { if(tot == curr) { List.send_list(coll, undefined, false, true, false); - List.getNextSong(coll); + List.getNextSong(coll, undefined); } }; }); @@ -765,7 +765,7 @@ function vote(coll, id, guid, socket) { socket.emit("toast", "voted"); io.to(coll).emit("channel", {type: "vote", value: id, time: Functions.get_time()}); - List.getNextSong(coll); + List.getNextSong(coll, undefined); }); }else { diff --git a/server/routing/client/api.js b/server/routing/client/api.js index 841031b4..0c0f316a 100644 --- a/server/routing/client/api.js +++ b/server/routing/client/api.js @@ -511,7 +511,7 @@ router.route('/api/list/:channel_name/:video_id').put(function(req,res) { incrementToken(token); } io.to(channel_name).emit("channel", {type: "vote", value: video_id, time: Functions.get_time()}); - List.getNextSong(channel_name, function() { + List.getNextSong(channel_name, undefined, function() { updateTimeout(guid, res, authorized, "PUT", function(err, docs) { var to_return = error.no_error; to_return.results = song; @@ -1435,7 +1435,7 @@ function postEnd(channel_name, configs, new_song, guid, res, authenticated, auth if(configs != undefined) { io.to(channel_name).emit("conf", configs); } - List.getNextSong(channel_name, function() { + List.getNextSong(channel_name, undefined, function() { updateTimeout(guid, res, authorized, "POST", function(err, docs) { var to_return = error.no_error; if(!authenticated) {