diff --git a/channel.js b/channel.js index 146a705d..48dc93e7 100644 --- a/channel.js +++ b/channel.js @@ -1123,10 +1123,13 @@ Channel.prototype.tryQueue = function(user, data) { if(!this.hasPermission(user, "playlistadd")) { return; } - if(data.pos == undefined || data.id == undefined) { + if(typeof data.pos !== "string") { return; } - if(data.type == undefined && !(data.id in this.library)) { + if(typeof data.id !== "string" && data.id !== false) { + return; + } + if(typeof data.type !== "string" && !(data.id in this.library)) { return; } @@ -1140,24 +1143,14 @@ Channel.prototype.tryQueue = function(user, data) { return; } - this.enqueue(data, user); + if(data.list) + this.enqueueList(data, user); + else + this.enqueue(data, user); } -Channel.prototype.tryQueuePlaylist = function(user, data) { - if(!this.hasPermission(user, "playlistaddlist")) { - return; - } - - if(typeof data.name != "string" || - typeof data.pos != "string") { - return; - } - - if(data.pos == "next" && !this.hasPermission(user, "playlistnext")) { - return; - } - - var pl = Database.loadUserPlaylist(user.name, data.name); +Channel.prototype.enqueueList = function(data, user) { + var pl = data.list; var chan = this; // Queue in reverse order for qnext if(data.pos == "next") { @@ -1184,6 +1177,25 @@ Channel.prototype.tryQueuePlaylist = function(user, data) { } } +Channel.prototype.tryQueuePlaylist = function(user, data) { + if(!this.hasPermission(user, "playlistaddlist")) { + return; + } + + if(typeof data.name != "string" || + typeof data.pos != "string") { + return; + } + + if(data.pos == "next" && !this.hasPermission(user, "playlistnext")) { + return; + } + + var pl = Database.loadUserPlaylist(user.name, data.name); + data.list = pl; + this.enqueueList(data, user); +} + Channel.prototype.setTemp = function(idx, temp) { var med = this.queue[idx]; med.temp = temp; diff --git a/www/assets/js/ui.js b/www/assets/js/ui.js index 87247b0d..7c4e0c22 100644 --- a/www/assets/js/ui.js +++ b/www/assets/js/ui.js @@ -190,6 +190,7 @@ function queue(pos) { if(pos == "next") { links = links.reverse(); } + var parsed = []; links.forEach(function(link) { var data = parseMediaLink(link); if(data.id === null || data.type === null) { @@ -200,12 +201,24 @@ function queue(pos) { else { $("#mediaurl").val(""); } - socket.emit("queue", { + parsed.push({ id: data.id, - type: data.type, - pos: "end" + type: data.type }); }); + + if(parsed.length > 1) { + socket.emit("queue", { + id: false, + list: parsed, + type: "list", + pos: pos + }); + } + else { + parsed[0].pos = pos; + socket.emit("queue", parsed[0]); + } } $("#queue_next").click(function() {