Fixed issue with channels having spaces

This commit is contained in:
Kasper Rynning-Tønnesen
2018-03-18 18:19:42 +01:00
parent 2e29f8e20f
commit f70cf00fd1
11 changed files with 55 additions and 37 deletions

View File

@@ -10,6 +10,7 @@ function get_history(channel, all, socket) {
channel: channel,
};
}
channel = channel.replace(/ /g,'');
var pass = "";
if(!query.all) {
Functions.getSessionAdminUser(Functions.getSession(socket), channel, function(userpass) {
@@ -28,6 +29,7 @@ function get_history(channel, all, socket) {
}
function getAndSendLogs(channel, all, socket, pass, query) {
channel = channel.replace(/ /g,'');
db.collection("chat_logs").find(query, {
from: 1,
createdAt: 1,
@@ -62,7 +64,7 @@ function chat(msg, guid, offline, socket) {
socket.emit('update_required', result);
return;
}
var coll = msg.channel.toLowerCase();
var coll = msg.channel.toLowerCase().replace(/ /g,'');
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass) {
msg.pass = userpass;
db.collection(coll + "_settings").find(function(err, docs){
@@ -110,7 +112,7 @@ function all_chat(msg, guid, offline, socket) {
socket.emit('update_required', result);
return;
}
var coll = msg.channel.toLowerCase();
var coll = msg.channel.toLowerCase().replace(/ /g,'');
var data = msg.data;
Functions.check_inlist(coll, guid, socket, offline);
@@ -201,7 +203,7 @@ function namechange(data, guid, socket, tried) {
//socket.emit('name', {type: "name", accepted: true});
if(old_name != name && !first) {
if(data.hasOwnProperty("channel") && typeof(data.channel) == "string") {
io.to(data.channel).emit('chat', {from: old_name, msg: " changed name to " + name});
io.to(data.channel.replace(/ /g,'')).emit('chat', {from: old_name, msg: " changed name to " + name});
io.sockets.emit('chat.all', {from: old_name , msg: " changed name to " + name, channel: data.channel});
}
}
@@ -226,6 +228,7 @@ function namechange(data, guid, socket, tried) {
}
function removename(guid, coll, socket) {
coll = coll.replace(/ /g,'');
db.collection("user_names").find({"guid": guid}, function(err, docs) {
if(docs.length == 1) {
var old_name = docs[0].name;

View File

@@ -18,6 +18,7 @@ function frontpage_lists(msg, socket) {
}
function update_frontpage(coll, id, title, callback) {
coll = coll.replace(/ /g,'');
db.collection("frontpage_lists").update({_id: coll}, {$set: {
id: id,
title: title,

View File

@@ -59,6 +59,7 @@ function get_short_id(socket) {
function check_inlist(coll, guid, socket, offline)
{
coll = coll.replace(/ /g,'');
if(!offline && coll != undefined){
db.collection("connected_users").update({"_id": coll}, {$addToSet:{users: guid}}, {upsert: true}, function(err, updated) {
if(updated.nModified > 0 || updated.upserted != undefined) {

View File

@@ -35,6 +35,7 @@ module.exports = function() {
socket.on('self_ping', function(msg) {
var channel = msg.channel;
channel = channel.replace(/ /g,'');
if(offline) {
db.collection("connected_users").update({"_id": "offline_users"}, {$addToSet: {users: guid}}, {upsert: true}, function(err, docs){});
} else {
@@ -68,7 +69,7 @@ module.exports = function() {
guid = msg.guid;
socketid = msg.socket_id;
socket.zoff_id = socketid;
coll = msg.channel.toLowerCase();
coll = msg.channel.toLowerCase().replace(/ /g,'');
in_list = true;
chromecast_object = true;
socket.join(coll);
@@ -86,7 +87,7 @@ module.exports = function() {
socket.on("error_video", function(msg) {
try {
var _list = msg.channel;
var _list = msg.channel.replace(/ /g,'');
if(_list.length == 0) return;
coll = emojiStrip(_list).toLowerCase();
coll = coll.replace("_", "");
@@ -113,11 +114,11 @@ module.exports = function() {
});
socket.on('suggest_thumbnail', function(msg){
Suggestions.thumbnail(msg, coll, guid, offline, socket);
Suggestions.thumbnail(msg, coll.replace(/ /g,''), guid, offline, socket);
});
socket.on('suggest_description', function(msg){
Suggestions.description(msg, coll, guid, offline, socket);
Suggestions.description(msg, coll.replace(/ /g,''), guid, offline, socket);
});
socket.on("namechange", function(msg) {
@@ -155,7 +156,7 @@ module.exports = function() {
return;
}
var status = msg.status;
var channel = msg.channel;
var channel = msg.channel.replace(/ /g,'');
if(status){
in_list = false;
offline = true;
@@ -215,7 +216,7 @@ module.exports = function() {
socket.emit('update_required', result);
return;
}
Chat.get_history(msg.channel, msg.all, socket);
Chat.get_history(msg.channel.replace(/ /g,''), msg.all, socket);
});
socket.on('chat', function (msg) {
@@ -246,7 +247,7 @@ module.exports = function() {
socket.on('list', function(msg)
{
try {
var _list = msg.channel;
var _list = msg.channel.replace(/ /g,'');
if(_list.length == 0) return;
coll = emojiStrip(_list).toLowerCase();
coll = coll.replace("_", "");
@@ -267,7 +268,7 @@ module.exports = function() {
{
if(coll === undefined) {
try {
coll = obj.channel.toLowerCase();
coll = obj.channel.toLowerCase().replace(/ /g,'');
if(coll.length == 0) return;
coll = emojiStrip(coll).toLowerCase();
coll = coll.replace("_", "");
@@ -284,7 +285,7 @@ module.exports = function() {
{
if(coll !== undefined) {
try {
coll = arr.list;
coll = arr.list.replace(/ /g,'');
if(coll.length == 0) return;
coll = emojiStrip(coll).toLowerCase();
coll = coll.replace("_", "");
@@ -300,7 +301,7 @@ module.exports = function() {
socket.on('delete_all', function(msg) {
if(coll !== undefined) {
try {
coll = msg.channel.toLowerCase();
coll = msg.channel.toLowerCase().replace(/ /g,'');
if(coll.length == 0) return;
coll = emojiStrip(coll).toLowerCase();
coll = coll.replace("_", "");
@@ -318,7 +319,7 @@ module.exports = function() {
{
if(coll !== undefined) {
try {
coll = msg.channel.toLowerCase();
coll = msg.channel.toLowerCase().replace(/ /g,'');
if(coll.length == 0) return;
coll = emojiStrip(coll).toLowerCase();
coll = coll.replace("_", "");
@@ -333,24 +334,24 @@ module.exports = function() {
socket.on('password', function(inp)
{
ListSettings.password(inp, coll, guid, offline, socket);
ListSettings.password(inp, coll.replace(/ /g,''), guid, offline, socket);
});
socket.on('skip', function(list)
{
List.skip(list, guid, coll, offline, socket);
List.skip(list, guid, coll.replace(/ /g,''), offline, socket);
});
socket.on('conf', function(params)
{
ListSettings.conf_function(params, coll, guid, offline, socket);
ListSettings.conf_function(params, coll.replace(/ /g,''), guid, offline, socket);
});
socket.on('shuffle', function(msg)
{
if(coll !== undefined) {
try {
coll = msg.channel.toLowerCase();
coll = msg.channel.toLowerCase().replace(/ /g,'');
if(coll.length == 0) return;
coll = emojiStrip(coll).toLowerCase();
coll = coll.replace("_", "");
@@ -367,7 +368,7 @@ module.exports = function() {
{
if(coll === undefined && obj !== undefined && obj.channel !== undefined){
try {
coll = obj.channel.toLowerCase();
coll = obj.channel.toLowerCase().replace(/ /g,'');
if(coll.length == 0) return;
coll = emojiStrip(coll).toLowerCase();
coll = coll.replace("_", "");
@@ -393,7 +394,7 @@ module.exports = function() {
socket.on("left_channel", function(msg) {
if(msg.hasOwnProperty("channel") && msg.channel != "" && typeof(msg.channel) == "string") {
coll = msg.channel;
coll = msg.channel.replace(/ /g,'');
List.left_channel(coll, guid, short_id, in_list, socket, false);
}
})
@@ -418,7 +419,7 @@ module.exports = function() {
if(!obj.hasOwnProperty("channel") || typeof(obj.channel) != "string")
if(coll !== undefined) {
try {
coll = obj.channel.toLowerCase();
coll = obj.channel.toLowerCase().replace(/ /g,'');
if(coll.length == 0) return;
coll = emojiStrip(coll).toLowerCase();
coll = coll.replace("_", "");

View File

@@ -46,7 +46,7 @@ function list(msg, guid, coll, offline, socket) {
socket.emit('update_required', result);
return;
}
coll = msg.channel.toLowerCase();
coll = msg.channel.toLowerCase().replace(/ /g,'');
var pass = crypto.createHash('sha256').update(Functions.decrypt_string(socketid, msg.pass)).digest("base64");
db.collection('frontpage_lists').find({"_id": coll}, function(err, frontpage_lists){
if(frontpage_lists.length == 1)
@@ -108,7 +108,7 @@ function skip(list, guid, coll, offline, socket) {
if(coll == undefined && list.hasOwnProperty('channel')) coll = list.channel.toLowerCase();
if(coll !== undefined) {
try {
coll = list.channel.toLowerCase();
coll = list.channel.toLowerCase().replace(/ /g,'');
if(coll.length == 0) return;
coll = emojiStrip(coll).toLowerCase();
coll = coll.replace("_", "");
@@ -225,6 +225,7 @@ function skip(list, guid, coll, offline, socket) {
}
function change_song(coll, error, id, callback, socket) {
coll = coll.replace(/ /g,'');
db.collection(coll + "_settings").find(function(err, docs){
var startTime = docs[0].startTime;
if(docs !== null && docs.length !== 0)
@@ -321,8 +322,8 @@ function change_song(coll, error, id, callback, socket) {
});
}
function change_song_post(coll, next_song, callback, socket)
{
function change_song_post(coll, next_song, callback, socket) {
coll = coll.replace(/ /g,'');
db.collection(coll).aggregate([{
$match:{
now_playing:false,
@@ -381,6 +382,7 @@ function change_song_post(coll, next_song, callback, socket)
function send_list(coll, socket, send, list_send, configs, shuffled)
{
coll = coll.replace(/ /g,'');
db.collection(coll + "_settings").find({id: "config"}, function(err, _conf){
var conf = _conf;
if(conf.length == 0) {
@@ -535,6 +537,7 @@ function end(obj, coll, guid, offline, socket) {
socket.emit("update_required", result);
return;
}
coll = coll.replace(/ /g,'');
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass) {
obj.pass = userpass;
@@ -578,8 +581,8 @@ function end(obj, coll, guid, offline, socket) {
}
}
function send_play(coll, socket, broadcast)
{
function send_play(coll, socket, broadcast) {
coll = coll.replace(/ /g,'');
db.collection(coll).find({now_playing:true}, function(err, np){
db.collection(coll + "_settings").find(function(err, conf){
if(err !== null) console.log(err);
@@ -624,6 +627,7 @@ function send_play(coll, socket, broadcast)
}
function sendColor(coll, socket, id) {
coll = coll.replace(/ /g,'');
var url = 'https://img.youtube.com/vi/'+id+'/mqdefault.jpg';
Jimp.read(url).then(function (image) {
@@ -637,6 +641,7 @@ function sendColor(coll, socket, id) {
}
function getNextSong(coll, callback) {
coll = coll.replace(/ /g,'');
db.collection(coll).aggregate([{
$match:{
views:{
@@ -663,9 +668,9 @@ function getNextSong(coll, callback) {
});
}
function left_channel(coll, guid, short_id, in_list, socket, change)
{
function left_channel(coll, guid, short_id, in_list, socket, change) {
if(!coll) return;
coll = coll.replace(/ /g,'');
db.collection("connected_users").update({"_id": coll}, {$pull: {users: guid}}, function(err, updated) {
if(updated.nModified > 0) {
db.collection("connected_users").find({"_id": coll}, function(err, new_doc){

View File

@@ -89,6 +89,7 @@ function add_function(arr, coll, guid, offline, socket) {
socket.emit('update_required', result);
return;
}
coll = coll.replace(/ /g,'');
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass) {
arr.adminpass = adminpass;
arr.userpass = userpass;
@@ -277,7 +278,7 @@ function voteUndecided(msg, coll, guid, offline, socket) {
socket.emit('update_required', result);
return;
}
coll = msg.channel.toLowerCase();;
coll = msg.channel.toLowerCase().replace(/ /g,'');
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass) {
msg.adminpass = adminpass;
msg.pass = userpass;
@@ -337,7 +338,7 @@ function shuffle(msg, coll, guid, offline, socket) {
socket.emit('update_required', result);
return;
}
coll = msg.channel.toLowerCase();
coll = msg.channel.toLowerCase().replace(/ /g,'');
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass) {
msg.adminpass = adminpass;
@@ -405,7 +406,7 @@ function shuffle(msg, coll, guid, offline, socket) {
function del(params, socket, socketid) {
if(params.id){
var coll = emojiStrip(params.channel).toLowerCase();
coll = coll.replace("_", "");
coll = coll.replace("_", "").replace(/ /g,'');
coll = encodeURIComponent(coll).replace(/\W/g, '');
coll = filter.clean(coll);
db.collection(coll + "_settings").find(function(err, docs){
@@ -451,6 +452,7 @@ function delete_all(msg, coll, guid, offline, socket) {
socket.emit('update_required', result);
return;
}
coll = coll.replace(/ /g,'');
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass, gotten) {
msg.adminpass = adminpass;
msg.pass = userpass;
@@ -484,6 +486,7 @@ function delete_all(msg, coll, guid, offline, socket) {
}
function vote(coll, id, guid, socket, full_list, last) {
coll = coll.replace(/ /g,'');
db.collection(coll).find({id:id, now_playing: false, type:"video"}, function(err, docs){
if(docs !== null && docs.length > 0 && !Functions.contains(docs[0].guids, guid))
{

View File

@@ -29,7 +29,7 @@ function password(inp, coll, guid, offline, socket) {
} catch(e) {
return;
}
coll = coll.replace(/ /g,'');
uncrypted = pw;
pw = Functions.hash_pass(Functions.decrypt_string(socket.zoff_id, pw), true);
Functions.check_inlist(coll, guid, socket, offline);
@@ -84,7 +84,7 @@ function conf_function(params, coll, guid, offline, socket) {
{
if(coll !== undefined) {
try {
coll = params.channel;
coll = params.channel.replace(/ /g,'');
if(coll.length == 0) return;
coll = emojiStrip(coll).toLowerCase();
coll = coll.replace("_", "");

View File

@@ -2,6 +2,7 @@ var path = require('path');
function requested_change(type, string, channel) {
try {
channel = channel.replace(/ /g,'');
var nodemailer = require('nodemailer');
var mailconfig = require(path.join(__dirname, '../config/mailconfig.js'));

View File

@@ -9,6 +9,7 @@ try {
}
function get_correct_info(song_generated, channel, broadcast, callback) {
channel = channel.replace(/ /g,'');
request({
type: "GET",
url: "https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id&key="+key+"&id=" + song_generated.id,
@@ -84,7 +85,7 @@ function check_error_video(msg, channel) {
}
return;
}
channel = channel.replace(/ /g,'');
request({
type: "GET",
url: "https://www.googleapis.com/youtube/v3/videos?part=id&key="+key+"&id=" + msg.id,
@@ -102,6 +103,7 @@ function check_error_video(msg, channel) {
}
function findSimilar(msg, channel, broadcast, callback) {
channel = channel.replace(/ /g,'');
var yt_url = "https://www.googleapis.com/youtube/v3/search?key="+key+"&videoEmbeddable=true&part=id&type=video&order=viewCount&safeSearch=none&maxResults=5&q=" + encodeURIComponent(msg.title);
request({
method: "GET",

View File

@@ -23,6 +23,7 @@ function thumbnail(msg, coll, guid, offline, socket) {
socket.emit("update_required", result);
return;
}
coll = coll.replace(/ /g,'');
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass) {
msg.userpass = userpass;
msg.adminpass = adminpass;
@@ -73,7 +74,7 @@ function description(msg, coll, guid, offline, socket) {
socket.emit("update_required", result);
return;
}
coll = coll.replace(/ /g,'');
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass, gotten) {
msg.userpass = userpass;
msg.adminpass = adminpass;

View File

@@ -15,7 +15,6 @@
<meta property="og:description" content="Zoff admin panel">
<meta property="og:type" content="website">
<link rel="icon" id="favicon" type="image/png" href="https://zoff.me/assets/images/favicon.png">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<script
src="https://code.jquery.com/jquery-2.2.4.min.js"
integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="
@@ -26,6 +25,7 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/js/materialize.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://zoff.me/assets/css/style.css" title="Default" />
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.4/socket.io.slim.js"></script>
<script type="text/javascript" src="/assets/admin/{{{where_get}}}/js/main.js"></script>
<style>