Merge branch 'master' into feature/chromecast

This commit is contained in:
Kasper Rynning-Tønnesen
2018-02-27 12:39:12 +01:00
12 changed files with 70 additions and 40 deletions

View File

@@ -26,6 +26,8 @@ in ```/server/config```. There are ```*.example.js``` files for all the ones men
If you want to use Google Analytics, have a look at ```analytics.example.js``` in ```server/config/```. If you want to use Google Analytics, have a look at ```analytics.example.js``` in ```server/config/```.
If you have run the server before the table-structures where added, please run ```node server/apps/rewrite.js```. This will fix any crashes that occurs because of faulty document-collectionnames due to moving channel-settings to a separate collection.
Use ```$ npm start``` to start the server. (Alternative you can use the ```pm2.json``` in the project-root, if you prefer pm2 for running the apps.) Use ```$ npm start``` to start the server. (Alternative you can use the ```pm2.json``` in the project-root, if you prefer pm2 for running the apps.)
### About ### About

23
server/apps/rewrite.js Normal file
View File

@@ -0,0 +1,23 @@
path = require('path'),
pathThumbnails = __dirname;
db = require(pathThumbnails + '/../handlers/db.js');
db.getCollectionNames(function(err, docs) {
for(var i = 0; i < docs.length; i++) {
makeNewAndDelete(docs[i]);
}
})
function makeNewAndDelete(name) {
db.collection(name).find({views: {$exists: true}}, function(err, doc) {
if(doc.length == 0) {
} else if(doc.length == 1) {
db.collection(name + "_settings").insert(doc[0], function(err, result){
console.log("Result insert", result);
db.collection(name).remove({views: {$exists: true}}, function(err, result_del) {
console.log("Result delete", result_del);
});
});
}
});
}

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});
@@ -58,7 +58,7 @@ function list(msg, guid, coll, offline, socket) {
} else { } else {
db.createCollection(coll, function(err, docs){ db.createCollection(coll, function(err, docs){
var configs = {"addsongs":false, "adminpass":"", "allvideos":true, "frontpage":true, "longsongs":false, "removeplay": false, "shuffle": true, "skip": false, "skips": [], "startTime":Functions.get_time(), "views": [], "vote": false, "desc": ""}; var configs = {"addsongs":false, "adminpass":"", "allvideos":true, "frontpage":true, "longsongs":false, "removeplay": false, "shuffle": true, "skip": false, "skips": [], "startTime":Functions.get_time(), "views": [], "vote": false, "desc": ""};
db.collection(coll).insert(configs, function(err, docs){ db.collection(coll + "_settings").insert(configs, function(err, docs){
socket.join(coll); socket.join(coll);
List.send_list(coll, socket, true, false, true); List.send_list(coll, socket, true, false, true);
db.collection("frontpage_lists").insert({"_id": coll, "count" : 0, "frontpage": true, "accessed": Functions.get_time(), "viewers": 1}); db.collection("frontpage_lists").insert({"_id": coll, "count" : 0, "frontpage": true, "accessed": Functions.get_time(), "viewers": 1});
@@ -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){

View File

@@ -23,7 +23,12 @@ var Frontpage = {
msg msg
]); ]);
Frontpage.all_channels = msg.channels; Frontpage.all_channels = msg.channels;
Frontpage.populate_channels(msg.channels, true); if(msg.channels.length == 0) {
$("#preloader").css("display", "none");
$("#channel-list-container").append("<p>No channels yet</p>");
} else {
Frontpage.populate_channels(msg.channels, true);
}
Frontpage.set_viewers(msg.viewers); Frontpage.set_viewers(msg.viewers);
}, },

View File

@@ -9,6 +9,7 @@ var Player = {
np: {}, np: {},
youtube_listener: function(obj) { youtube_listener: function(obj) {
Helper.log(["object", obj]);
var state; var state;
if(embed && obj.np) { if(embed && obj.np) {
if(window.parentWindow && window.parentOrigin) { if(window.parentWindow && window.parentOrigin) {
@@ -42,7 +43,6 @@ var Player = {
} }
Helper.log(["video_id variable: " + video_id]); Helper.log(["video_id variable: " + video_id]);
if(!obj.np){ if(!obj.np){
$('#song-title').html("Empty channel. Add some songs!"); $('#song-title').html("Empty channel. Add some songs!");
document.title = "Zoff - the shared YouTube based radio"; document.title = "Zoff - the shared YouTube based radio";

View File

@@ -46,7 +46,7 @@ router.route('/api/approve_thumbnail').post(function(req, res){
db.collection("suggested_thumbnails").find({channel: channel}, function(err, docs){ db.collection("suggested_thumbnails").find({channel: channel}, function(err, docs){
var thumbnail = docs[0].thumbnail; var thumbnail = docs[0].thumbnail;
db.collection("frontpage_lists").update({_id: channel}, {$set:{thumbnail: thumbnail}}, {upsert: true}, function(err, docs){ db.collection("frontpage_lists").update({_id: channel}, {$set:{thumbnail: thumbnail}}, {upsert: true}, function(err, docs){
db.collection(channel).update({views:{$exists:true}}, {$set:{thumbnail: thumbnail}}, {upsert: true}, function(err, docs){ db.collection(channel + "_settings").update({views:{$exists:true}}, {$set:{thumbnail: thumbnail}}, {upsert: true}, function(err, docs){
db.collection("suggested_thumbnails").remove({channel: channel}, function(err, docs){ db.collection("suggested_thumbnails").remove({channel: channel}, function(err, docs){
res.send(true); res.send(true);
}); });
@@ -75,7 +75,7 @@ router.route('/api/approve_description').post(function(req, res){
db.collection("suggested_descriptions").find({channel: channel}, function(err, docs){ db.collection("suggested_descriptions").find({channel: channel}, function(err, docs){
var description = docs[0].description; var description = docs[0].description;
db.collection("frontpage_lists").update({_id: channel}, {$set:{description: description}}, {upsert: true}, function(err, docs){ db.collection("frontpage_lists").update({_id: channel}, {$set:{description: description}}, {upsert: true}, function(err, docs){
db.collection(channel).update({views:{$exists:true}}, {$set:{description: description}}, function(err, docs){ db.collection(channel + "_settings").update({views:{$exists:true}}, {$set:{description: description}}, function(err, docs){
db.collection("suggested_descriptions").remove({channel: channel}, function(err, docs){ db.collection("suggested_descriptions").remove({channel: channel}, function(err, docs){
res.send(true); res.send(true);
}); });
@@ -102,7 +102,7 @@ router.route('/api/remove_thumbnail').post(function(req, res){
if(req.isAuthenticated()){ if(req.isAuthenticated()){
var channel = req.body.channel; var channel = req.body.channel;
db.collection("frontpage_lists").update({_id: channel}, {$set:{thumbnail: ""}}, function(err, docs){ db.collection("frontpage_lists").update({_id: channel}, {$set:{thumbnail: ""}}, function(err, docs){
db.collection(channel).update({views:{$exists:true}}, {$set:{thumbnail: ""}}, function(err, docs){ db.collection(channel + "_settings").update({views:{$exists:true}}, {$set:{thumbnail: ""}}, function(err, docs){
res.send(true); res.send(true);
}); });
}); });
@@ -115,7 +115,7 @@ router.route('/api/remove_description').post(function(req, res){
if(req.isAuthenticated()){ if(req.isAuthenticated()){
var channel = req.body.channel; var channel = req.body.channel;
db.collection("frontpage_lists").update({_id: channel}, {$set:{description: ""}}, function(err, docs){ db.collection("frontpage_lists").update({_id: channel}, {$set:{description: ""}}, function(err, docs){
db.collection(channel).update({views:{$exists:true}}, {$set:{description: ""}}, function(err, docs){ db.collection(channel + "_settings").update({views:{$exists:true}}, {$set:{description: ""}}, function(err, docs){
res.send(true); res.send(true);
}); });
}); });
@@ -209,7 +209,7 @@ router.route('/api/pinned').post(function(req, res){
router.route('/api/admin').post(function(req, res){ router.route('/api/admin').post(function(req, res){
if(req.isAuthenticated()){ if(req.isAuthenticated()){
var to_remove = req.body._id; var to_remove = req.body._id;
db.collection(to_remove).update({views: {$exists: true}}, {$set:{adminpass: ""}}, function(err, docs){ db.collection(to_remove + "_settings").update({views: {$exists: true}}, {$set:{adminpass: ""}}, function(err, docs){
res.send(true); res.send(true);
}); });
} else { } else {
@@ -220,7 +220,7 @@ router.route('/api/admin').post(function(req, res){
router.route('/api/userpass').post(function(req, res){ router.route('/api/userpass').post(function(req, res){
if(req.isAuthenticated()){ if(req.isAuthenticated()){
var to_remove = req.body._id; var to_remove = req.body._id;
db.collection(to_remove).update({views: {$exists: true}}, {$set:{userpass: ""}}, function(err, docs){ db.collection(to_remove + "_settings").update({views: {$exists: true}}, {$set:{userpass: ""}}, function(err, docs){
res.send(true); res.send(true);
}); });
} else { } else {

View File

@@ -49,7 +49,7 @@ router.route('/api/list/:channel_name').get(function(req, res) {
router.route('/api/conf/:channel_name').get(function(req, res) { router.route('/api/conf/:channel_name').get(function(req, res) {
var channel_name = req.params.channel_name; var channel_name = req.params.channel_name;
db.collection(channel_name).find({views: {$exists: true}}, { db.collection(channel_name + "_settings").find({views: {$exists: true}}, {
addsongs: 1, addsongs: 1,
adminpass: 1, adminpass: 1,
allvideos: 1, allvideos: 1,