mirror of https://github.com/calzoneman/sync.git
Improve the way chat filter imports are handled
This commit is contained in:
parent
9c989f7ed7
commit
6471969f55
|
@ -2124,6 +2124,62 @@ Channel.prototype.handleToggleLock = function (user) {
|
||||||
this.handleSetLock(user, { locked: !this.playlistLock });
|
this.handleSetLock(user, { locked: !this.playlistLock });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Imports a list of chat filters, replacing the current list
|
||||||
|
*/
|
||||||
|
Channel.prototype.importFilters = function (filters) {
|
||||||
|
this.filters = filters;
|
||||||
|
this.sendChatFilters(this.users);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles a user message to import a list of chat filters
|
||||||
|
*/
|
||||||
|
Channel.prototype.handleImportFilters = function (user, data) {
|
||||||
|
// TODO change to filterimport
|
||||||
|
if (!this.hasPermission(user, "filteredit")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(data instanceof Array)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.filters = data.map(this.validateChatFilter.bind(this))
|
||||||
|
.filter(function (f) { return f !== false; });
|
||||||
|
|
||||||
|
this.sendChatFilters(this.users);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates data for a chat filter
|
||||||
|
*/
|
||||||
|
Channel.prototype.validateChatFilter = function (f) {
|
||||||
|
if (typeof f.source !== "string" || typeof f.flags !== "string" ||
|
||||||
|
typeof f.replace !== "string") {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof f.name !== "string") {
|
||||||
|
f.name = f.source;
|
||||||
|
}
|
||||||
|
|
||||||
|
f.replace = f.replace.substring(0, 1000);
|
||||||
|
f.flags = f.flags.substring(0, 4);
|
||||||
|
|
||||||
|
// TODO XSS prevention
|
||||||
|
try {
|
||||||
|
new RegExp(f.source, f.flags);
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var filter = new Filter(f.name, f.source, f.flags, f.replace);
|
||||||
|
filter.active = Boolean(f.active);
|
||||||
|
filter.filterlinks = Boolean(f.filterlinks);
|
||||||
|
return filter;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates a chat filter, or adds a new one if the filter does not exist
|
* Updates a chat filter, or adds a new one if the filter does not exist
|
||||||
*/
|
*/
|
||||||
|
@ -2163,29 +2219,11 @@ Channel.prototype.handleUpdateFilter = function (user, f) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof f.source !== "string" || typeof f.flags !== "string" ||
|
filter = this.validateChatFilter(f);
|
||||||
typeof f.replace !== "string") {
|
if (!filter) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof f.name !== "string") {
|
|
||||||
f.name = f.source;
|
|
||||||
}
|
|
||||||
|
|
||||||
f.replace = f.replace.substring(0, 1000);
|
|
||||||
f.flags = f.flags.substring(0, 4);
|
|
||||||
|
|
||||||
// TODO XSS prevention
|
|
||||||
try {
|
|
||||||
new RegExp(f.source, f.flags);
|
|
||||||
} catch (e) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var filter = new Filter(f.name, f.source, f.flags, f.replace);
|
|
||||||
filter.active = Boolean(f.active);
|
|
||||||
filter.filterlinks = Boolean(f.filterlinks);
|
|
||||||
|
|
||||||
this.logger.log("%%% " + user.name + " updated filter: " + f.name);
|
this.logger.log("%%% " + user.name + " updated filter: " + f.name);
|
||||||
this.updateFilter(filter);
|
this.updateFilter(filter);
|
||||||
};
|
};
|
||||||
|
|
|
@ -369,6 +369,10 @@ User.prototype.initChannelCallbacks = function () {
|
||||||
self.channel.handleUpdateFilter(self, data);
|
self.channel.handleUpdateFilter(self, data);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
wrap("importFilters", function (data) {
|
||||||
|
self.channel.handleImportFilters(self, data);
|
||||||
|
});
|
||||||
|
|
||||||
// REMOVE FILTER
|
// REMOVE FILTER
|
||||||
// https://www.youtube.com/watch?v=SxUU3zncVmI
|
// https://www.youtube.com/watch?v=SxUU3zncVmI
|
||||||
wrapTypecheck("removeFilter", function (data) {
|
wrapTypecheck("removeFilter", function (data) {
|
||||||
|
|
|
@ -14,7 +14,7 @@ html(lang="en")
|
||||||
ul.nav.navbar-nav
|
ul.nav.navbar-nav
|
||||||
mixin navdefaultlinks(cname)
|
mixin navdefaultlinks(cname)
|
||||||
li: a(href="#", onclick="javascript:showUserOptions()") Options
|
li: a(href="#", onclick="javascript:showUserOptions()") Options
|
||||||
li: a(href="#", onclick="javascript:$('#channeloptions').modal()") Channel Settings
|
li: a#showchansettings(href="#", onclick="javascript:$('#channeloptions').modal()") Channel Settings
|
||||||
mixin navloginlogout(cname)
|
mixin navloginlogout(cname)
|
||||||
section#mainpage
|
section#mainpage
|
||||||
.container
|
.container
|
||||||
|
|
|
@ -600,12 +600,5 @@ $("#cs-chatfilters-import").click(function () {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var entries = $("#cs-chatfilters table").data("entries") || [];
|
socket.emit("importFilters", data);
|
||||||
entries.forEach(function (f) {
|
|
||||||
socket.emit("removeFilter", f);
|
|
||||||
});
|
|
||||||
|
|
||||||
data.forEach(function (f) {
|
|
||||||
socket.emit("updateFilter", f);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -789,6 +789,7 @@ function handlePermissionChange() {
|
||||||
handleModPermissions();
|
handleModPermissions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setVisible("#showchansettings", CLIENT.rank >= 2);
|
||||||
setVisible("#playlistmanagerwrap", CLIENT.rank >= 1);
|
setVisible("#playlistmanagerwrap", CLIENT.rank >= 1);
|
||||||
setVisible("#modflair", CLIENT.rank >= 2);
|
setVisible("#modflair", CLIENT.rank >= 2);
|
||||||
setVisible("#adminflair", CLIENT.rank >= 255);
|
setVisible("#adminflair", CLIENT.rank >= 255);
|
||||||
|
|
Loading…
Reference in New Issue