Now sending next song when asked to correctly, and to only the askee

This commit is contained in:
Kasper Rynning-Tønnesen
2018-06-23 13:30:00 +02:00
parent ec8dd98ccb
commit 526bb36d99
4 changed files with 15 additions and 11 deletions

View File

@@ -79,15 +79,15 @@ module.exports = function() {
}); });
socket.on('next_song', function(obj) { 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) { db.collection(obj.channel + "_settings").find(function(e, docs) {
if(docs.length == 0) return; if(docs.length == 0) return;
var pass = ""; var pass = "";
if(obj.pass) { if(obj.hasOwnProperty("pass")) {
pass = crypto.createHash('sha256').update(Functions.decrypt_string(obj.pass)).digest("base64"); 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))) { if((docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || docs[0].userpass == pass))) {
List.getNextSong(obj.channel); List.getNextSong(obj.channel, socket);
} }
}); });
}); });

View File

@@ -651,7 +651,7 @@ function send_play(coll, socket, broadcast) {
if(socket === undefined) { if(socket === undefined) {
io.to(coll).emit("np", toSend); io.to(coll).emit("np", toSend);
// //
getNextSong(coll) getNextSong(coll, undefined)
var url = 'https://img.youtube.com/vi/'+np[0].id+'/mqdefault.jpg'; var url = 'https://img.youtube.com/vi/'+np[0].id+'/mqdefault.jpg';
if(np[0].source == "soundcloud") url = np[0].thumbnail; if(np[0].source == "soundcloud") url = np[0].thumbnail;
sendColor(coll, false, url); 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,''); //coll = coll.replace(/ /g,'');
db.collection(coll).aggregate([{ db.collection(coll).aggregate([{
$match:{ $match:{
@@ -741,7 +741,11 @@ function getNextSong(coll, callback) {
source = "soundcloud"; source = "soundcloud";
thumbnail = doc[0].thumbnail; 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(); if(typeof(callback) == "function") callback();
}); });

View File

@@ -432,7 +432,7 @@ function add_function(arr, coll, guid, offline, socket) {
if(source != "soundcloud") Search.get_correct_info(new_song, coll, true); 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){}); 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"); socket.emit("toast", "addedsong");
}); });
@@ -656,7 +656,7 @@ function shuffle(msg, coll, guid, offline, socket) {
if(tot == curr) if(tot == curr)
{ {
List.send_list(coll, undefined, false, true, false); 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"); socket.emit("toast", "voted");
io.to(coll).emit("channel", {type: "vote", value: id, time: Functions.get_time()}); io.to(coll).emit("channel", {type: "vote", value: id, time: Functions.get_time()});
List.getNextSong(coll); List.getNextSong(coll, undefined);
}); });
}else }else
{ {

View File

@@ -511,7 +511,7 @@ router.route('/api/list/:channel_name/:video_id').put(function(req,res) {
incrementToken(token); incrementToken(token);
} }
io.to(channel_name).emit("channel", {type: "vote", value: video_id, time: Functions.get_time()}); 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) { updateTimeout(guid, res, authorized, "PUT", function(err, docs) {
var to_return = error.no_error; var to_return = error.no_error;
to_return.results = song; to_return.results = song;
@@ -1435,7 +1435,7 @@ function postEnd(channel_name, configs, new_song, guid, res, authenticated, auth
if(configs != undefined) { if(configs != undefined) {
io.to(channel_name).emit("conf", configs); 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) { updateTimeout(guid, res, authorized, "POST", function(err, docs) {
var to_return = error.no_error; var to_return = error.no_error;
if(!authenticated) { if(!authenticated) {