mirror of https://github.com/calzoneman/sync.git
Implement max total video time per user
This commit is contained in:
parent
f42e3bf2b7
commit
b1a328d2e0
|
@ -2,7 +2,7 @@
|
||||||
"author": "Calvin Montgomery",
|
"author": "Calvin Montgomery",
|
||||||
"name": "CyTube",
|
"name": "CyTube",
|
||||||
"description": "Online media synchronizer and chat",
|
"description": "Online media synchronizer and chat",
|
||||||
"version": "3.34.9",
|
"version": "3.34.10",
|
||||||
"repository": {
|
"repository": {
|
||||||
"url": "http://github.com/calzoneman/sync"
|
"url": "http://github.com/calzoneman/sync"
|
||||||
},
|
},
|
||||||
|
|
|
@ -31,7 +31,8 @@ function OptionsModule(channel) {
|
||||||
allow_ascii_control: false,// Allow ASCII control characters (\x00-\x1f)
|
allow_ascii_control: false,// Allow ASCII control characters (\x00-\x1f)
|
||||||
playlist_max_per_user: 0, // Maximum number of playlist items per user
|
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_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;
|
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) {
|
if ("externalcss" in data && user.account.effectiveRank >= 3) {
|
||||||
var prefix = "Invalid URL for external CSS: ";
|
var prefix = "Invalid URL for external CSS: ";
|
||||||
if (typeof data.externalcss !== "string") {
|
if (typeof data.externalcss !== "string") {
|
||||||
|
|
|
@ -42,7 +42,8 @@ const DEFAULT_PERMISSIONS = {
|
||||||
chat: 0, // Send chat messages
|
chat: 0, // Send chat messages
|
||||||
chatclear: 2, // Use the /clear command
|
chatclear: 2, // Use the /clear command
|
||||||
exceedmaxitems: 2, // Exceed maximum items per user limit
|
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) {
|
function PermissionsModule(channel) {
|
||||||
|
@ -224,6 +225,10 @@ PermissionsModule.prototype.canExceedMaxLength = function (account) {
|
||||||
return this.hasPermission(account, "exceedmaxlength");
|
return this.hasPermission(account, "exceedmaxlength");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
PermissionsModule.prototype.canExceedMaxDurationPerUser = function (account) {
|
||||||
|
return this.hasPermission(account, "exceedmaxdurationperuser");
|
||||||
|
};
|
||||||
|
|
||||||
PermissionsModule.prototype.canShufflePlaylist = function (account) {
|
PermissionsModule.prototype.canShufflePlaylist = function (account) {
|
||||||
return this.hasPermission(account, "playlistshuffle");
|
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 */
|
/* Warn about blocked countries */
|
||||||
if (media.meta.restricted) {
|
if (media.meta.restricted) {
|
||||||
user.socket.emit("queueWarn", {
|
user.socket.emit("queueWarn", {
|
||||||
|
|
|
@ -63,6 +63,7 @@ mixin miscoptions
|
||||||
+rcheckbox-auto("cs-allow_dupes", "Allow duplicate videos on the playlist")
|
+rcheckbox-auto("cs-allow_dupes", "Allow duplicate videos on the playlist")
|
||||||
+textbox-auto("cs-voteskip_ratio", "Voteskip ratio", "0.5")
|
+textbox-auto("cs-voteskip_ratio", "Voteskip ratio", "0.5")
|
||||||
+textbox-auto("cs-maxlength", "Max video length", "HH:MM:SS")
|
+textbox-auto("cs-maxlength", "Max video length", "HH:MM:SS")
|
||||||
|
+textbox-timeinput-auto("cs-playlist_max_duration_per_user", "Max length of all user's videos", "HH:MM:SS")
|
||||||
+textbox-auto("cs-afk_timeout", "Auto-AFK Delay", "0 (disabled)")
|
+textbox-auto("cs-afk_timeout", "Auto-AFK Delay", "0 (disabled)")
|
||||||
.form-group
|
.form-group
|
||||||
.col-sm-offset-4
|
.col-sm-offset-4
|
||||||
|
|
|
@ -944,24 +944,10 @@ function handleModPermissions() {
|
||||||
$("#cs-torbanned").prop("checked", CHANNEL.opts.torbanned);
|
$("#cs-torbanned").prop("checked", CHANNEL.opts.torbanned);
|
||||||
$("#cs-allow_ascii_control").prop("checked", CHANNEL.opts.allow_ascii_control);
|
$("#cs-allow_ascii_control").prop("checked", CHANNEL.opts.allow_ascii_control);
|
||||||
$("#cs-playlist_max_per_user").val(CHANNEL.opts.playlist_max_per_user || 0);
|
$("#cs-playlist_max_per_user").val(CHANNEL.opts.playlist_max_per_user || 0);
|
||||||
|
$("#cs-playlist_max_duration_per_user").val(formatTime(CHANNEL.opts.playlist_max_duration_per_user));
|
||||||
$("#cs-new_user_chat_delay").val(formatTime(CHANNEL.opts.new_user_chat_delay || 0));
|
$("#cs-new_user_chat_delay").val(formatTime(CHANNEL.opts.new_user_chat_delay || 0));
|
||||||
$("#cs-new_user_chat_link_delay").val(formatTime(CHANNEL.opts.new_user_chat_link_delay || 0));
|
$("#cs-new_user_chat_link_delay").val(formatTime(CHANNEL.opts.new_user_chat_link_delay || 0));
|
||||||
(function() {
|
$("#cs-maxlength").val(formatTime(CHANNEL.opts.maxlength));
|
||||||
if(typeof CHANNEL.opts.maxlength != "number") {
|
|
||||||
$("#cs-maxlength").val("");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var h = parseInt(CHANNEL.opts.maxlength / 3600);
|
|
||||||
h = ""+h;
|
|
||||||
if(h.length < 2) h = "0" + h;
|
|
||||||
var m = parseInt((CHANNEL.opts.maxlength % 3600) / 60);
|
|
||||||
m = ""+m;
|
|
||||||
if(m.length < 2) m = "0" + m;
|
|
||||||
var s = parseInt(CHANNEL.opts.maxlength % 60);
|
|
||||||
s = ""+s;
|
|
||||||
if(s.length < 2) s = "0" + s;
|
|
||||||
$("#cs-maxlength").val(h + ":" + m + ":" + s);
|
|
||||||
})();
|
|
||||||
$("#cs-csstext").val(CHANNEL.css);
|
$("#cs-csstext").val(CHANNEL.css);
|
||||||
$("#cs-jstext").val(CHANNEL.js);
|
$("#cs-jstext").val(CHANNEL.js);
|
||||||
$("#cs-motdtext").val(CHANNEL.motd);
|
$("#cs-motdtext").val(CHANNEL.motd);
|
||||||
|
@ -2009,6 +1995,7 @@ function genPermissionsEditor() {
|
||||||
makeOption("Embed custom media", "playlistaddcustom", standard, CHANNEL.perms.playlistaddcustom + "");
|
makeOption("Embed custom media", "playlistaddcustom", standard, CHANNEL.perms.playlistaddcustom + "");
|
||||||
makeOption("Add raw video file", "playlistaddrawfile", standard, CHANNEL.perms.playlistaddrawfile + "");
|
makeOption("Add raw video file", "playlistaddrawfile", standard, CHANNEL.perms.playlistaddrawfile + "");
|
||||||
makeOption("Exceed maximum media length", "exceedmaxlength", standard, CHANNEL.perms.exceedmaxlength+"");
|
makeOption("Exceed maximum media length", "exceedmaxlength", standard, CHANNEL.perms.exceedmaxlength+"");
|
||||||
|
makeOption("Exceed maximum total media length", "exceedmaxdurationperuser", standard, CHANNEL.perms.exceedmaxdurationperuser+"");
|
||||||
makeOption("Exceed maximum number of videos per user", "exceedmaxitems", standard, CHANNEL.perms.exceedmaxitems+"");
|
makeOption("Exceed maximum number of videos per user", "exceedmaxitems", standard, CHANNEL.perms.exceedmaxitems+"");
|
||||||
makeOption("Add nontemporary media", "addnontemp", standard, CHANNEL.perms.addnontemp+"");
|
makeOption("Add nontemporary media", "addnontemp", standard, CHANNEL.perms.addnontemp+"");
|
||||||
makeOption("Temp/untemp playlist item", "settemp", standard, CHANNEL.perms.settemp+"");
|
makeOption("Temp/untemp playlist item", "settemp", standard, CHANNEL.perms.settemp+"");
|
||||||
|
|
Loading…
Reference in New Issue