From c8ce8b530a068f5da4e7085bb390d35ee064483d Mon Sep 17 00:00:00 2001 From: calzoneman Date: Mon, 26 Aug 2013 10:36:47 -0500 Subject: [PATCH] Add a few limits --- channel.js | 14 ++------------ playlist.js | 40 ++++++++++++++++++++++++---------------- ullist.js | 11 +++++++++++ 3 files changed, 37 insertions(+), 28 deletions(-) diff --git a/channel.js b/channel.js index a261d16b..39b364f6 100644 --- a/channel.js +++ b/channel.js @@ -1231,23 +1231,13 @@ Channel.prototype.tryQueue = function(user, data) { && this.leader != user && user.noflood("queue", 3)) { return; + } else if (user.rank < Rank.Siteadmin && user.noflood("queue", 0.5)) { + return; } if(typeof data.title !== "string") data.title = false; - var count = this.playlist.count(data.id); - - if(user.rank < Rank.Moderator && count >= 5) { - user.socket.emit("queueFail", "That video is already on the " + - "playlist 5 times."); - return; - } else if(user.rank < Rank.Siteadmin && count >= 20) { - user.socket.emit("queueFail", "That video is already on the " + - "playlist 20 times."); - return; - } - data.queueby = user ? user.name : ""; data.temp = !this.hasPermission(user, "addnontemp"); diff --git a/playlist.js b/playlist.js index 99d4968e..a65d1ccf 100644 --- a/playlist.js +++ b/playlist.js @@ -169,20 +169,29 @@ Playlist.prototype.makeItem = function(media) { } Playlist.prototype.add = function(item, pos) { - var success; - if(pos == "append") - success = this.items.append(item); - else if(pos == "prepend") - success = this.items.prepend(item); - else - success = this.items.insertAfter(item, pos); + if(this.items.length >= 4000) + return "Playlist limit reached (4,000)"; - if(success && this.items.length == 1) { + if(this.items.findVideoId(item.media.id)) + return "This item is already on the playlist"; + + if(pos == "append") { + if(!this.items.append(item)) + return "Playlist failure"; + } else if(pos == "prepend") { + if(!this.items.prepend(item)) + return "Playlist failure"; + } else { + if(!this.items.insertAfter(item, pos)) + return "Playlist failure"; + } + + if(this.items.length == 1) { this.current = item; this.startPlayback(); } - return success; + return false; } Playlist.prototype.addCachedMedia = function(data, callback) { @@ -202,8 +211,8 @@ Playlist.prototype.addCachedMedia = function(data, callback) { var action = { fn: function() { - if(pl.add(it, pos)) - callback(false, it); + var err = pl.add(it, pos); + callback(err, err ? null : it); }, waiting: false }; @@ -229,9 +238,8 @@ Playlist.prototype.addMedia = function(data, callback) { var pl = this; var action = { fn: function() { - if(pl.add(it, pos)) { - callback(false, it); - } + var err = pl.add(it, pos); + callback(err, err ? null : it); }, waiting: true }; @@ -331,8 +339,8 @@ Playlist.prototype.addYouTubePlaylist = function(data, callback) { it.queueby = data.queueby; pl.queueAction({ fn: function() { - if(pl.add(it, pos)) - callback(false, it); + var err = pl.add(it, pos); + callback(err, err ? null : it); }, }); }); diff --git a/ullist.js b/ullist.js index 9314fb9e..f4ad4638 100644 --- a/ullist.js +++ b/ullist.js @@ -170,4 +170,15 @@ ULList.prototype.forEach = function (fn) { } }; +/* find a media with the given video id */ +ULList.prototype.findVideoId = function (id) { + var item = this.first; + while(item !== null) { + if(item.media && item.media.id === id) + return true; + item = item.next; + } + return false; +}; + exports.ULList = ULList;