Add a few limits
This commit is contained in:
parent
0491ea11da
commit
c8ce8b530a
14
channel.js
14
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");
|
||||
|
||||
|
|
40
playlist.js
40
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);
|
||||
},
|
||||
});
|
||||
});
|
||||
|
|
11
ullist.js
11
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;
|
||||
|
|
Loading…
Reference in a new issue