Implement max total video time per user
This commit is contained in:
parent
f42e3bf2b7
commit
b1a328d2e0
6 changed files with 49 additions and 19 deletions
|
|
@ -31,7 +31,8 @@ function OptionsModule(channel) {
|
|||
allow_ascii_control: false,// Allow ASCII control characters (\x00-\x1f)
|
||||
playlist_max_per_user: 0, // Maximum number of playlist items per user
|
||||
new_user_chat_delay: 0, // Minimum account/IP age to chat
|
||||
new_user_chat_link_delay: 0 // Minimum account/IP age to post links
|
||||
new_user_chat_link_delay: 0, // Minimum account/IP age to post links
|
||||
playlist_max_duration_per_user: 0 // Maximum total playlist time per user
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -171,6 +172,30 @@ OptionsModule.prototype.handleSetOptions = function (user, data) {
|
|||
sendUpdate = true;
|
||||
}
|
||||
|
||||
if ("playlist_max_duration_per_user" in data) {
|
||||
const rawMax = data.playlist_max_duration_per_user;
|
||||
if (typeof rawMax !== "string" || !rawMax.match(/^(\d+:)*\d+$/)) {
|
||||
user.socket.emit("validationError", {
|
||||
target: "#cs-playlist_max_duration_per_user",
|
||||
message: `Input must be a time in the format HH:MM:SS, not "${rawMax}"`
|
||||
});
|
||||
} else {
|
||||
const max = Utilities.parseTime(rawMax);
|
||||
if (isNaN(max) || max < 0) {
|
||||
user.socket.emit("validationError", {
|
||||
target: "#cs-playlist_max_duration_per_user",
|
||||
message: `Input must be a time greater than 0 in the format HH:MM:SS, not "${rawMax}"`
|
||||
});
|
||||
} else {
|
||||
this.opts.playlist_max_duration_per_user = max;
|
||||
sendUpdate = true;
|
||||
user.socket.emit("validationPassed", {
|
||||
target: "#cs-playlist_max_duration_per_user"
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ("externalcss" in data && user.account.effectiveRank >= 3) {
|
||||
var prefix = "Invalid URL for external CSS: ";
|
||||
if (typeof data.externalcss !== "string") {
|
||||
|
|
|
|||
|
|
@ -42,7 +42,8 @@ const DEFAULT_PERMISSIONS = {
|
|||
chat: 0, // Send chat messages
|
||||
chatclear: 2, // Use the /clear command
|
||||
exceedmaxitems: 2, // Exceed maximum items per user limit
|
||||
deletefromchannellib: 2 // Delete channel library items
|
||||
deletefromchannellib: 2, // Delete channel library items
|
||||
exceedmaxdurationperuser: 2 // Exceed maximum total playlist length per user
|
||||
};
|
||||
|
||||
function PermissionsModule(channel) {
|
||||
|
|
@ -224,6 +225,10 @@ PermissionsModule.prototype.canExceedMaxLength = function (account) {
|
|||
return this.hasPermission(account, "exceedmaxlength");
|
||||
};
|
||||
|
||||
PermissionsModule.prototype.canExceedMaxDurationPerUser = function (account) {
|
||||
return this.hasPermission(account, "exceedmaxdurationperuser");
|
||||
};
|
||||
|
||||
PermissionsModule.prototype.canShufflePlaylist = function (account) {
|
||||
return this.hasPermission(account, "playlistshuffle");
|
||||
};
|
||||
|
|
|
|||
|
|
@ -922,6 +922,18 @@ PlaylistModule.prototype._addItem = function (media, data, user, cb) {
|
|||
}
|
||||
}
|
||||
|
||||
if (this.channel.modules.options &&
|
||||
this.channel.modules.options.get("playlist_max_duration_per_user") > 0) {
|
||||
|
||||
const limit = this.channel.modules.options.get("playlist_max_duration_per_user");
|
||||
const totalDuration = usersItems.map(item => item.media.seconds).reduce((a, b) => a + b, 0) + media.seconds;
|
||||
if (isNaN(totalDuration)) {
|
||||
Logger.errlog.log("playlist_max_duration_per_user check calculated NaN: " + require('util').inspect(usersItems));
|
||||
} else if (totalDuration >= limit && !this.channel.modules.permissions.canExceedMaxDurationPerUser(user)) {
|
||||
return qfail("Channel limit exceeded: maximum total playlist time per user");
|
||||
}
|
||||
}
|
||||
|
||||
/* Warn about blocked countries */
|
||||
if (media.meta.restricted) {
|
||||
user.socket.emit("queueWarn", {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue