mirror of
https://github.com/KevinMidboe/zoff.git
synced 2025-10-29 18:00:23 +00:00
Display and hide on frontpage only not working
This commit is contained in:
155
server/server.js
155
server/server.js
@@ -23,9 +23,52 @@ io.on('connection', function(socket){
|
||||
|
||||
var coll;
|
||||
var guid;
|
||||
var tot_lists = [];
|
||||
var in_list = false;
|
||||
|
||||
socket.on('frontpage_lists', function()
|
||||
{
|
||||
var playlists_to_send = [];
|
||||
var i = 0;
|
||||
var playlists_to_send = [];
|
||||
in_list = false;
|
||||
|
||||
db.getCollectionNames(function(err, colNames){
|
||||
colNames.forEach(function(name){
|
||||
if(name != "system.indexes")
|
||||
{
|
||||
db.collection(name).find({now_playing:true}, function(err, np){
|
||||
complete(np, i, colNames.length-2, name);
|
||||
i++;
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var complete = function(list, curr, tot, name)
|
||||
{
|
||||
console.log("inside");
|
||||
if(list.length > 0)
|
||||
{
|
||||
var id = list[0]["id"];
|
||||
var title = list[0]["title"];
|
||||
try{
|
||||
var viewers = lists[name].length;
|
||||
}catch(err){console.log("no viewers"); var viewers = 0;}
|
||||
var to_push = [viewers, id, title, name];
|
||||
playlists_to_send.push(to_push);
|
||||
}
|
||||
if(curr == tot)
|
||||
{
|
||||
socket.emit("playlists", playlists_to_send);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
socket.on('list', function(list)
|
||||
{
|
||||
in_list = true;
|
||||
list = list.split(',');
|
||||
coll = list[0].toLowerCase();
|
||||
guid = list[1];
|
||||
@@ -110,7 +153,7 @@ io.on('connection', function(socket){
|
||||
{
|
||||
var id = msg[1];
|
||||
guid = msg[3];
|
||||
var hash = has_pass(msg[4]);
|
||||
var hash = hash_pass(msg[4]);
|
||||
db.collection(coll).find({views:{$exists:true}}, function(err, docs)
|
||||
{
|
||||
if((docs[0]["vote"] == "true" && (hash == docs[0]["adminpass"] || docs[0]["adminpass"] == "")) || docs[0]["vote"] == "false")
|
||||
@@ -174,7 +217,7 @@ io.on('connection', function(socket){
|
||||
shuffle:shuffling,
|
||||
longsongs:longsongs,
|
||||
adminpass:hash}}, function(err, docs){
|
||||
socket.emit("success_settings");
|
||||
socket.emit("success_settings", "Successfully applied settings!");
|
||||
sort_list(coll,undefined,false);
|
||||
});
|
||||
|
||||
@@ -185,14 +228,37 @@ io.on('connection', function(socket){
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('shuffle', function(pass){
|
||||
var hash = hash_pass(pass);
|
||||
db.collection(coll).find({views:{$exists:true}}, function(err, docs){
|
||||
if((docs[0]["adminpass"] == hash || docs[0]["adminpass"] == "") || docs[0]["shuffle"] == "true")
|
||||
{
|
||||
db.collection(coll).find({now_playing:false}).forEach(function(err, docs){
|
||||
if(!docs){
|
||||
sort_list(coll, undefined, false);
|
||||
return;
|
||||
}else{
|
||||
console.log(docs);
|
||||
num = Math.floor(Math.random()*1000000);
|
||||
db.collection(coll).update({id:docs["id"]}, {$set:{added:num}}, function(err, d)
|
||||
{});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('disconnect', function()
|
||||
{
|
||||
try
|
||||
{
|
||||
var index = lists[coll].indexOf(guid);
|
||||
lists[coll].splice(index, 1);
|
||||
io.sockets.emit(coll+",viewers", lists[coll].length);
|
||||
}catch(err){}
|
||||
if(in_list)
|
||||
{
|
||||
try
|
||||
{
|
||||
var index = lists[coll].indexOf(guid);
|
||||
lists[coll].splice(index, 1);
|
||||
io.sockets.emit(coll+",viewers", lists[coll].length);
|
||||
}catch(err){}
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('pos', function()
|
||||
@@ -200,14 +266,16 @@ io.on('connection', function(socket){
|
||||
console.log("EMITTED");
|
||||
send_play(coll, socket);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
function del(params)
|
||||
{
|
||||
db.collection(coll).find({adminpass:hash_pass(params[4])}, function(err, docs){
|
||||
if(docs.length == 1)
|
||||
var coll = params[0].toLowerCase();
|
||||
db.collection(coll).find({views:{$exists:true}}, function(err, docs){
|
||||
console.log(docs);
|
||||
if(docs[0]["adminpass"] == hash_pass(params[4]))
|
||||
{
|
||||
console.log("del");
|
||||
db.collection(coll).remove({id:params[1]}, function(err, docs){
|
||||
sort_list(coll, undefined, false);
|
||||
})
|
||||
@@ -227,41 +295,58 @@ function vote(coll, id, guid)
|
||||
{
|
||||
db.collection(coll).update({id:id}, {$inc:{votes:1}, $set:{added:get_time()}}, function(err, docs)
|
||||
{
|
||||
/*db.collection(coll).update({id:id}, {$push :{guids: guid}}, function(err, docs)
|
||||
db.collection(coll).update({id:id}, {$push :{guids: guid}}, function(err, docs)
|
||||
{
|
||||
sort_list(coll, undefined, false);
|
||||
});*/
|
||||
sort_list(coll, undefined, false);
|
||||
});
|
||||
//sort_list(coll, undefined, false);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function change_song(coll)
|
||||
{
|
||||
db.collection(coll).update({now_playing:true},
|
||||
{$set:{
|
||||
now_playing:false,
|
||||
votes:0,
|
||||
guids:[]
|
||||
}}, function(err, docs)
|
||||
db.collection(coll).find({views:{$exists:true}}, function(err, docs){
|
||||
if(docs[0]["removeplay"] == "true")
|
||||
{
|
||||
db.collection(coll).aggregate([
|
||||
{$match:{now_playing:false}},
|
||||
{$sort:{votes:-1, added:1}},
|
||||
{$limit:1}], function(err, docs){
|
||||
db.collection(coll).update({id:docs[0]["id"]},
|
||||
{$set:{
|
||||
now_playing:true,
|
||||
votes:0,
|
||||
guids:[],
|
||||
added:get_time()}}, function(err, docs){
|
||||
db.collection(coll).update({views:{$exists:true}},
|
||||
{$set:{startTime:get_time()}}, function(err, docs){
|
||||
sort_list(coll,undefined,true);
|
||||
});
|
||||
|
||||
db.collection(coll).remove({now_playing:true}, function(err, docs)
|
||||
{
|
||||
change_song_post(coll);
|
||||
})
|
||||
}else
|
||||
{
|
||||
db.collection(coll).update({now_playing:true},
|
||||
{$set:{
|
||||
now_playing:false,
|
||||
votes:0,
|
||||
guids:[]
|
||||
}}, function(err, docs)
|
||||
{
|
||||
change_song_post(coll);
|
||||
});
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function change_song_post(coll)
|
||||
{
|
||||
db.collection(coll).aggregate([
|
||||
{$match:{now_playing:false}},
|
||||
{$sort:{votes:-1, added:1}},
|
||||
{$limit:1}], function(err, docs){
|
||||
db.collection(coll).update({id:docs[0]["id"]},
|
||||
{$set:{
|
||||
now_playing:true,
|
||||
votes:0,
|
||||
guids:[],
|
||||
added:get_time()}}, function(err, docs){
|
||||
db.collection(coll).update({views:{$exists:true}},
|
||||
{$set:{startTime:get_time()}}, function(err, docs){
|
||||
sort_list(coll,undefined,true);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user