Updating to use different collection for channelsettings

This commit is contained in:
Kasper Rynning-Tønnesen
2018-02-27 11:11:29 +01:00
parent 3efefb51d9
commit 370e9ae72b
6 changed files with 30 additions and 30 deletions

View File

@@ -30,7 +30,7 @@ function chat(msg, guid, offline, socket) {
return; return;
} }
var coll = msg.channel; var coll = msg.channel;
db.collection(coll).find({views:{$exists:true}}, function(err, docs){ db.collection(coll + "_settings").find(function(err, docs){
if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == Functions.decrypt_string(socket.zoff_id, msg.pass)))) { if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == Functions.decrypt_string(socket.zoff_id, msg.pass)))) {
var data = msg.data; var data = msg.data;
Functions.check_inlist(coll, guid, socket, offline); Functions.check_inlist(coll, guid, socket, offline);

View File

@@ -383,7 +383,7 @@ module.exports = function() {
return; return;
} }
db.collection(coll).find({views: {$exists: true}}, function(err, docs) { db.collection(coll + "_settings").find(function(err, docs) {
if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (obj.hasOwnProperty('pass') && docs[0].userpass == Functions.decrypt_string(socketid, obj.pass)))) { if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (obj.hasOwnProperty('pass') && docs[0].userpass == Functions.decrypt_string(socketid, obj.pass)))) {
Functions.check_inlist(coll, guid, socket, offline); Functions.check_inlist(coll, guid, socket, offline);
List.send_play(coll, socket); List.send_play(coll, socket);

View File

@@ -34,7 +34,7 @@ function list(msg, guid, coll, offline, socket) {
db.collection('frontpage_lists').find({"_id": coll}, function(err, frontpage_lists){ db.collection('frontpage_lists').find({"_id": coll}, function(err, frontpage_lists){
if(frontpage_lists.length == 1) if(frontpage_lists.length == 1)
{ {
db.collection(coll).find({views: {$exists: true}}, function(err, docs) { db.collection(coll + "_settings").find(function(err, docs) {
if(docs.length == 0 || (docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || docs[0].userpass == pass))) { if(docs.length == 0 || (docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || docs[0].userpass == pass))) {
if(docs.length > 0 && docs[0].hasOwnProperty('userpass') && docs[0].userpass != "" && docs[0].userpass == pass) { if(docs.length > 0 && docs[0].hasOwnProperty('userpass') && docs[0].userpass != "" && docs[0].userpass == pass) {
socket.emit("auth_accepted", {value: true}); socket.emit("auth_accepted", {value: true});
@@ -82,7 +82,7 @@ function skip(list, guid, coll, offline, socket) {
return; return;
} }
db.collection(coll).find({views:{$exists:true}}, function(err, docs){ db.collection(coll + "_settings").find(function(err, docs){
if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (list.hasOwnProperty('userpass') && docs[0].userpass == Functions.decrypt_string(socketid, list.userpass)))) { if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (list.hasOwnProperty('userpass') && docs[0].userpass == Functions.decrypt_string(socketid, list.userpass)))) {
Functions.check_inlist(coll, guid, socket, offline); Functions.check_inlist(coll, guid, socket, offline);
@@ -104,7 +104,7 @@ function skip(list, guid, coll, offline, socket) {
else else
hash = ""; hash = "";
db.collection(coll).find({views: {$exists:true}}, function(err, docs){ db.collection(coll + "_settings").find(function(err, docs){
if(docs !== null && docs.length !== 0) if(docs !== null && docs.length !== 0)
{ {
@@ -129,7 +129,7 @@ function skip(list, guid, coll, offline, socket) {
} }
}); });
}else if(!Functions.contains(docs[0].skips, guid)){ }else if(!Functions.contains(docs[0].skips, guid)){
db.collection(coll).update({views:{$exists:true}}, {$push:{skips:guid}}, function(err, d){ db.collection(coll + "_settings").update({views:{$exists:true}}, {$push:{skips:guid}}, function(err, d){
if(frontpage_viewers[0].viewers == 2) if(frontpage_viewers[0].viewers == 2)
to_skip = 1; to_skip = 1;
else else
@@ -155,7 +155,7 @@ function skip(list, guid, coll, offline, socket) {
} }
function change_song(coll, error, id, callback) { function change_song(coll, error, id, callback) {
db.collection(coll).find({views:{$exists:true}}, function(err, docs){ db.collection(coll + "_settings").find(function(err, docs){
var startTime = docs[0].startTime; var startTime = docs[0].startTime;
if(docs !== null && docs.length !== 0) if(docs !== null && docs.length !== 0)
{ {
@@ -193,7 +193,7 @@ function change_song(coll, error, id, callback) {
}); });
} else { } else {
if((docs[0].skipped_time != undefined && docs[0].skipped_time != Functions.get_time()) || docs[0].skipped_time == undefined) { if((docs[0].skipped_time != undefined && docs[0].skipped_time != Functions.get_time()) || docs[0].skipped_time == undefined) {
db.collection(coll).update({views: {$exists: true}}, {$set: {skipped_time: Functions.get_time()}}, function(err, updated){ db.collection(coll + "_settings").update({views: {$exists: true}}, {$set: {skipped_time: Functions.get_time()}}, function(err, updated){
db.collection(coll).update({now_playing:true, id:id}, { db.collection(coll).update({now_playing:true, id:id}, {
$set:{ $set:{
now_playing:false, now_playing:false,
@@ -278,13 +278,13 @@ function change_song_post(coll, next_song, callback)
added:Functions.get_time() added:Functions.get_time()
} }
}, function(err, returnDocs){ }, function(err, returnDocs){
db.collection(coll).update({views:{$exists:true}},{ db.collection(coll + "_settings").update({views: {$exists: true}}, {
$set:{ $set:{
startTime:Functions.get_time(), startTime:Functions.get_time(),
skips:[] skips:[]
} }
}, function(err, returnDocs){ }, function(err, returnDocs){
db.collection(coll).find({views:{$exists:true}}, function(err, conf){ db.collection(coll + "_settings").find(function(err, conf){
if(!callback) { if(!callback) {
io.to(coll).emit("channel", {type: "song_change", time: Functions.get_time(), remove: conf[0].removeplay}); io.to(coll).emit("channel", {type: "song_change", time: Functions.get_time(), remove: conf[0].removeplay});
List.send_play(coll); List.send_play(coll);
@@ -301,7 +301,7 @@ function change_song_post(coll, next_song, callback)
function send_list(coll, socket, send, list_send, configs, shuffled) function send_list(coll, socket, send, list_send, configs, shuffled)
{ {
db.collection(coll).find({views:{$exists:true}}, function(err, conf){ db.collection(coll + "_settings").find(function(err, conf){
db.collection(coll).find({views:{$exists:false}, type: {$ne: "suggested"}}, function(err, docs) db.collection(coll).find({views:{$exists:false}, type: {$ne: "suggested"}}, function(err, docs)
{ {
if(docs.length > 0) { if(docs.length > 0) {
@@ -335,7 +335,7 @@ function send_list(coll, socket, send, list_send, configs, shuffled)
added:Functions.get_time() added:Functions.get_time()
} }
}, function(err, returnDocs){ }, function(err, returnDocs){
db.collection(coll).update({views:{$exists:true}}, { db.collection(coll + "_settings").update({views:{$exists:true}}, {
$set:{ $set:{
startTime: Functions.get_time(), startTime: Functions.get_time(),
skips:[] skips:[]
@@ -408,14 +408,14 @@ function end(obj, coll, guid, offline, socket) {
return; return;
} }
db.collection(coll).find({views:{$exists:true}}, function(err, docs){ db.collection(coll + "_settings").find(function(err, docs){
if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (obj.hasOwnProperty('pass') && docs[0].userpass == Functions.decrypt_string(socketid, obj.pass)))) { if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (obj.hasOwnProperty('pass') && docs[0].userpass == Functions.decrypt_string(socketid, obj.pass)))) {
Functions.check_inlist(coll, guid, socket, offline); Functions.check_inlist(coll, guid, socket, offline);
db.collection(coll).find({now_playing:true}, function(err, np){ db.collection(coll).find({now_playing:true}, function(err, np){
if(err !== null) console.log(err); if(err !== null) console.log(err);
if(np !== null && np !== undefined && np.length == 1 && np[0].id == id){ if(np !== null && np !== undefined && np.length == 1 && np[0].id == id){
db.collection(coll).find({views:{$exists:true}}, function(err, docs){ db.collection(coll + "_settings").find(function(err, docs){
var startTime = docs[0].startTime; var startTime = docs[0].startTime;
if(docs[0].removeplay === true && startTime+parseInt(np[0].duration)<=Functions.get_time()+5) if(docs[0].removeplay === true && startTime+parseInt(np[0].duration)<=Functions.get_time()+5)
{ {
@@ -444,7 +444,7 @@ function end(obj, coll, guid, offline, socket) {
function send_play(coll, socket) function send_play(coll, socket)
{ {
db.collection(coll).find({now_playing:true}, function(err, np){ db.collection(coll).find({now_playing:true}, function(err, np){
db.collection(coll).find({views:{$exists:true}}, function(err, conf){ db.collection(coll + "_settings").find(function(err, conf){
if(err !== null) console.log(err); if(err !== null) console.log(err);
try{ try{
if(Functions.get_time()-conf[0].startTime > np[0].duration){ if(Functions.get_time()-conf[0].startTime > np[0].duration){

View File

@@ -11,7 +11,7 @@ function add_function(arr, coll, guid, offline, socket) {
var start = arr.start; var start = arr.start;
var end = arr.end; var end = arr.end;
db.collection(coll).find({views:{$exists:true}}, function(err, docs){ db.collection(coll + "_settings").find(function(err, docs){
if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (arr.hasOwnProperty('pass') && docs[0].userpass == Functions.decrypt_string(socketid, arr.pass)))) { if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (arr.hasOwnProperty('pass') && docs[0].userpass == Functions.decrypt_string(socketid, arr.pass)))) {
Functions.check_inlist(coll, guid, socket, offline); Functions.check_inlist(coll, guid, socket, offline);
@@ -24,7 +24,7 @@ function add_function(arr, coll, guid, offline, socket) {
var last = arr.num == arr.total - 1; var last = arr.num == arr.total - 1;
var num = arr.num; var num = arr.num;
var total = arr.total; var total = arr.total;
/*db.collection(coll).find({views:{$exists:true}}, function(err, docs) /*db.collection(coll + "_settings").find(function(err, docs)
{*/ {*/
conf = docs; conf = docs;
if(docs !== null && docs.length !== 0 && ((docs[0].addsongs === true && (hash == docs[0].adminpass || docs[0].adminpass === "")) || if(docs !== null && docs.length !== 0 && ((docs[0].addsongs === true && (hash == docs[0].adminpass || docs[0].adminpass === "")) ||
@@ -86,7 +86,7 @@ function add_function(arr, coll, guid, offline, socket) {
{ {
var new_song = {"added": added,"guids":guids,"id":id,"now_playing":np,"title":title,"votes":votes, "duration":duration, "start": parseInt(start), "end": parseInt(end)}; var new_song = {"added": added,"guids":guids,"id":id,"now_playing":np,"title":title,"votes":votes, "duration":duration, "start": parseInt(start), "end": parseInt(end)};
List.send_list(coll, undefined, false, true, false); List.send_list(coll, undefined, false, true, false);
db.collection(coll).update({views:{$exists:true}}, {$set:{startTime: Functions.get_time()}}); db.collection(coll + "_settings").update({views:{$exists:true}}, {$set:{startTime: Functions.get_time()}});
List.send_play(coll, undefined); List.send_play(coll, undefined);
Frontpage.update_frontpage(coll, id, title); Frontpage.update_frontpage(coll, id, title);
if(!full_list) Search.get_correct_info(new_song, coll, false); if(!full_list) Search.get_correct_info(new_song, coll, false);
@@ -163,7 +163,7 @@ function voteUndecided(msg, coll, guid, offline, socket) {
return; return;
} }
db.collection(coll).find({views:{$exists:true}}, function(err, docs){ db.collection(coll + "_settings").find(function(err, docs){
if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == Functions.decrypt_string(socketid, msg.pass)))) { if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == Functions.decrypt_string(socketid, msg.pass)))) {
Functions.check_inlist(coll, guid, socket, offline); Functions.check_inlist(coll, guid, socket, offline);
@@ -174,7 +174,7 @@ function voteUndecided(msg, coll, guid, offline, socket) {
{ {
var id = msg.id; var id = msg.id;
var hash = Functions.hash_pass(Functions.decrypt_string(socketid, msg.adminpass)); var hash = Functions.hash_pass(Functions.decrypt_string(socketid, msg.adminpass));
db.collection(coll).find({views:{$exists:true}}, function(err, docs){ db.collection(coll + "_settings").find(function(err, docs){
if(docs !== null && docs.length !== 0 && ((docs[0].vote === true && (hash == docs[0].adminpass || docs[0].adminpass === "")) || if(docs !== null && docs.length !== 0 && ((docs[0].vote === true && (hash == docs[0].adminpass || docs[0].adminpass === "")) ||
docs[0].vote === false)) docs[0].vote === false))
{ {
@@ -206,7 +206,7 @@ function shuffle(msg, coll, guid, offline, socket) {
var hash; var hash;
if(msg.adminpass === "") hash = msg.adminpass; if(msg.adminpass === "") hash = msg.adminpass;
else hash = Functions.hash_pass(Functions.decrypt_string(socketid, msg.adminpass)); else hash = Functions.hash_pass(Functions.decrypt_string(socketid, msg.adminpass));
db.collection(coll).find({views:{$exists:true}}, function(err, docs){ db.collection(coll + "_settings").find(function(err, docs){
if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == Functions.decrypt_string(socketid, msg.pass)))) { if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == Functions.decrypt_string(socketid, msg.pass)))) {
if(docs !== null && docs.length !== 0 && ((docs[0].adminpass == hash || docs[0].adminpass === "") || docs[0].shuffle === false)) if(docs !== null && docs.length !== 0 && ((docs[0].adminpass == hash || docs[0].adminpass === "") || docs[0].shuffle === false))
{ {
@@ -246,7 +246,7 @@ function del(params, socket, socketid) {
coll = coll.replace("_", ""); coll = coll.replace("_", "");
coll = encodeURIComponent(coll).replace(/\W/g, ''); coll = encodeURIComponent(coll).replace(/\W/g, '');
coll = filter.clean(coll); coll = filter.clean(coll);
db.collection(coll).find({views:{$exists:true}}, function(err, docs){ db.collection(coll + "_settings").find(function(err, docs){
if(docs !== null && docs.length !== 0 && docs[0].adminpass == Functions.hash_pass(Functions.decrypt_string(socketid, params.adminpass))) if(docs !== null && docs.length !== 0 && docs[0].adminpass == Functions.hash_pass(Functions.decrypt_string(socketid, params.adminpass)))
{ {
db.collection(coll).find({id:params.id}, function(err, docs){ db.collection(coll).find({id:params.id}, function(err, docs){
@@ -274,7 +274,7 @@ function delete_all(msg, coll, guid, offline, socket) {
var hash = Functions.hash_pass(Functions.decrypt_string(socketid, msg.adminpass)); var hash = Functions.hash_pass(Functions.decrypt_string(socketid, msg.adminpass));
var hash_userpass = Functions.decrypt_string(socketid, msg.pass); var hash_userpass = Functions.decrypt_string(socketid, msg.pass);
db.collection(coll).find({views: {$exists: true}}, function(err, conf) { db.collection(coll + "_settings").find(function(err, conf) {
if(conf.length == 1 && conf) { if(conf.length == 1 && conf) {
conf = conf[0]; conf = conf[0];
if(conf.adminpass == hash && conf.adminpass != "" && (conf.userpass == "" || conf.userpass == undefined || (conf.userpass != "" && conf.userpass != undefined && conf.pass == hash_userpass))) { if(conf.adminpass == hash && conf.adminpass != "" && (conf.userpass == "" || conf.userpass == undefined || (conf.userpass != "" && conf.userpass != undefined && conf.pass == hash_userpass))) {

View File

@@ -30,12 +30,12 @@ function password(inp, coll, guid, offline, socket) {
} }
opw = Functions.decrypt_string(socket.zoff_id, opw); opw = Functions.decrypt_string(socket.zoff_id, opw);
db.collection(coll).find({views:{$exists:true}}, function(err, docs){ db.collection(coll + "_settings").find(function(err, docs){
if(docs !== null && docs.length !== 0) if(docs !== null && docs.length !== 0)
{ {
if(docs[0].adminpass === "" || docs[0].adminpass == Functions.hash_pass(opw)) if(docs[0].adminpass === "" || docs[0].adminpass == Functions.hash_pass(opw))
{ {
db.collection(coll).update({views:{$exists:true}}, {$set:{adminpass:Functions.hash_pass(pw)}}, function(err, docs){ db.collection(coll + "_settings").update({views:{$exists:true}}, {$set:{adminpass:Functions.hash_pass(pw)}}, function(err, docs){
if(inp.oldpass) if(inp.oldpass)
socket.emit("toast", "changedpass"); socket.emit("toast", "changedpass");
else else
@@ -109,7 +109,7 @@ function conf_function(params, coll, guid, offline, socket) {
} else { } else {
hash = adminpass; hash = adminpass;
} }
db.collection(coll).find({views:{$exists:true}}, function(err, docs){ db.collection(coll + "_settings").find(function(err, docs){
if(docs !== null && docs.length !== 0 && (docs[0].adminpass === "" || docs[0].adminpass == hash)) { if(docs !== null && docs.length !== 0 && (docs[0].adminpass === "" || docs[0].adminpass == hash)) {
var obj = { var obj = {
addsongs:addsongs, addsongs:addsongs,
@@ -128,10 +128,10 @@ function conf_function(params, coll, guid, offline, socket) {
} else if (frontpage) { } else if (frontpage) {
obj["userpass"] = ""; obj["userpass"] = "";
} }
db.collection(coll).update({views:{$exists:true}}, { db.collection(coll + "_settings").update({views:{$exists:true}}, {
$set:obj $set:obj
}, function(err, docs){ }, function(err, docs){
db.collection(coll).find({views:{$exists:true}}, function(err, docs){ db.collection(coll + "_settings").find(function(err, docs){
if(docs[0].adminpass !== "") docs[0].adminpass = true; if(docs[0].adminpass !== "") docs[0].adminpass = true;
if(docs[0].hasOwnProperty("userpass") && docs[0].userpass != "") docs[0].userpass = true; if(docs[0].hasOwnProperty("userpass") && docs[0].userpass != "") docs[0].userpass = true;
else docs[0].userpass = false; else docs[0].userpass = false;

View File

@@ -4,7 +4,7 @@ function thumbnail(msg, coll, guid, offline, socket) {
if(msg.thumbnail.substring(0,2) != "//") msg.thumbnail = "//" + msg.thumbnail; if(msg.thumbnail.substring(0,2) != "//") msg.thumbnail = "//" + msg.thumbnail;
var channel = msg.channel.toLowerCase(); var channel = msg.channel.toLowerCase();
var hash = Functions.hash_pass(Functions.decrypt_string(socket.zoff_id, msg.adminpass)); var hash = Functions.hash_pass(Functions.decrypt_string(socket.zoff_id, msg.adminpass));
db.collection(channel).find({views:{$exists:true}}, function(err, docs){ db.collection(channel + "_settings").update({views: {$exists: true}}, function(err, docs){
if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == Functions.decrypt_string(socketid, msg.pass)))) { if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == Functions.decrypt_string(socketid, msg.pass)))) {
if(docs !== null && docs.length !== 0 && docs[0].adminpass !== "" && docs[0].adminpass == hash){ if(docs !== null && docs.length !== 0 && docs[0].adminpass !== "" && docs[0].adminpass == hash){
db.collection("suggested_thumbnails").update({channel: channel}, {$set:{thumbnail: msg.thumbnail}}, {upsert:true}, function(err, docs){ db.collection("suggested_thumbnails").update({channel: channel}, {$set:{thumbnail: msg.thumbnail}}, {upsert:true}, function(err, docs){
@@ -25,7 +25,7 @@ function description(msg, coll, guid, offline, socket) {
if(msg.description && msg.channel && msg.adminpass && msg.description.length < 100){ if(msg.description && msg.channel && msg.adminpass && msg.description.length < 100){
var channel = msg.channel.toLowerCase(); var channel = msg.channel.toLowerCase();
var hash = Functions.hash_pass(Functions.decrypt_string(socket.zoff_id, msg.adminpass)); var hash = Functions.hash_pass(Functions.decrypt_string(socket.zoff_id, msg.adminpass));
db.collection(channel).find({views:{$exists:true}}, function(err, docs){ db.collection(channel + "_settings").update({views: {$exists: true}}, function(err, docs){
if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == Functions.decrypt_string(socketid, msg.pass)))) { if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == Functions.decrypt_string(socketid, msg.pass)))) {
if(docs !== null && docs.length !== 0 && docs[0].adminpass !== "" && docs[0].adminpass == hash){ if(docs !== null && docs.length !== 0 && docs[0].adminpass !== "" && docs[0].adminpass == hash){
db.collection("suggested_descriptions").update({channel: channel}, {$set:{description: msg.description}}, {upsert:true}, function(err, docs){ db.collection("suggested_descriptions").update({channel: channel}, {$set:{description: msg.description}}, {upsert:true}, function(err, docs){