Add a few limits

This commit is contained in:
calzoneman 2013-08-26 10:36:47 -05:00
parent 0491ea11da
commit c8ce8b530a
3 changed files with 37 additions and 28 deletions

View file

@ -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");

View file

@ -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);
},
});
});

View file

@ -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;