indentations on server.js

This commit is contained in:
Kasper Rynning-Tønnesen
2017-05-06 13:46:17 +02:00
parent 627719a967
commit a84f338534
3 changed files with 1346 additions and 1289 deletions

File diff suppressed because one or more lines are too long

View File

@@ -566,8 +566,9 @@ io.on('connection', function(socket){
} else if(full_list) {
np = false;
}
} else
} else {
np = false;
}
db.collection(coll).update({id: id}, {"added": added,"guids":guids,"id":id,"now_playing":np,"title":title,"votes":votes, "duration":duration}, {upsert: true}, function(err, docs){
if(np)
{
@@ -582,9 +583,9 @@ io.on('connection', function(socket){
}
db.collection("frontpage_lists").update({_id:coll}, {$inc:{count:1}, $set:{accessed: get_time()}}, {upsert:true}, function(err, docs){});
});
if(!full_list)
if(!full_list) {
socket.emit("toast", "addedsong");
else if(full_list && last) {
} else if(full_list && last) {
socket.emit("toast", "addedplaylist");
}
});
@@ -597,13 +598,19 @@ io.on('connection', function(socket){
socket.emit("toast", "addedplaylist");
}
});
}else if(!full_list)
{
} else if(!full_list) {
db.collection(coll).find({id: id}, function(err, docs) {
if(docs.length === 0) {
db.collection(coll).update({id: id},
{$set:{
"added":get_time(), "guids": [guid], "id":id, "now_playing": false, "title":title, "votes":1, "duration":duration, type:"suggested"}},
db.collection(coll).update({id: id}, {$set:{
"added":get_time(),
"guids": [guid],
"id":id,
"now_playing": false,
"title":title,
"votes":1,
"duration":duration,
"type":"suggested"}
},
{upsert:true}, function(err, docs){
socket.emit("toast", "suggested");
io.to(coll).emit("suggested", {id: id, title: title, duration: duration});
@@ -858,11 +865,11 @@ io.on('connection', function(socket){
var hash;
if(params.description) description = params.description;
if(adminpass !== "")
if(adminpass !== "") {
hash = hash_pass(decrypt_string(socketid, adminpass));
else
} else {
hash = adminpass;
}
db.collection(coll).find({views:{$exists:true}}, function(err, docs){
if(docs !== null && docs.length !== 0 && docs[0].adminpass === "" || docs[0].adminpass == hash)
{
@@ -878,7 +885,8 @@ io.on('connection', function(socket){
adminpass:hash,
desc: description,
userpass: userpass,
}}, function(err, docs){
}
}, function(err, docs){
db.collection(coll).find({views:{$exists:true}}, function(err, docs){
if(docs[0].adminpass !== "") docs[0].adminpass = true;
if(docs[0].hasOwnProperty("userpass") && docs[0].userpass != "") docs[0].userpass = true;
@@ -886,8 +894,9 @@ io.on('connection', function(socket){
io.to(coll).emit("conf", docs);
socket.emit("toast", "savedsettings");
db.collection("frontpage_lists").update({_id: coll},
{$set:{frontpage:frontpage, accessed: get_time()}},
db.collection("frontpage_lists").update({_id: coll}, {$set:{
frontpage:frontpage, accessed: get_time()}
},
{upsert:true}, function(err, docs){});
});
});
@@ -1097,16 +1106,15 @@ function change_name(name, guid, oldname){
}
}
function update_frontpage(coll, id, title)
{
db.collection("frontpage_lists").update(
{_id: coll},
{$set:{id: id, title: title, accessed: get_time()}},
{upsert: true}, function(err, returnDocs){});
function update_frontpage(coll, id, title) {
db.collection("frontpage_lists").update({_id: coll}, {$set: {
id: id,
title: title,
accessed: get_time()}
},{upsert: true}, function(err, returnDocs){});
}
function del(params, socket, socketid)
{
function del(params, socket, socketid) {
if(params.id){
var coll = emojiStrip(params.channel).toLowerCase();
//coll = decodeURIComponent(coll);
@@ -1162,13 +1170,11 @@ function check_inlist(coll, guid, socket, name, offline)
}
}
function hash_pass(adminpass)
{
function hash_pass(adminpass) {
return crypto.createHash('sha256').update(adminpass).digest('base64');
}
function vote(coll, id, guid, socket, full_list, last)
{
function vote(coll, id, guid, socket, full_list, last) {
db.collection(coll).find({id:id, now_playing: false}, function(err, docs){
if(docs !== null && docs.length > 0 && !contains(docs[0].guids, guid))
{
@@ -1186,16 +1192,29 @@ function vote(coll, id, guid, socket, full_list, last)
}
function change_song(coll, error, id)
{
function change_song(coll, error, id) {
db.collection(coll).find({views:{$exists:true}}, function(err, docs){
var startTime = docs[0].startTime;
if(docs !== null && docs.length !== 0)
{
db.collection(coll).aggregate([
{$match:{views:{$exists: false}, type:{$ne: "suggested"}}},
{$sort:{now_playing: -1, votes:-1, added:1, title: 1}},
{$limit:2
db.collection(coll).aggregate([{
$match:{
views:{
$exists: false
},
type:{
$ne: "suggested"
}
}
}, {
$sort:{
now_playing: -1,
votes:-1,
added:1,
title: 1
}
}, {
$limit:2
}], function(err, now_playing_doc){
if((id && id == now_playing_doc[0].id) || !id) {
//db.collection(coll).find({now_playing:true}, function(err, now_playing_doc){
@@ -1212,12 +1231,13 @@ function change_song(coll, error, id)
} else {
if(skipped[coll] != get_time()){
skipped[coll] = get_time();
db.collection(coll).update({now_playing:true, id:id},
{$set:{
db.collection(coll).update({now_playing:true, id:id}, {
$set:{
now_playing:false,
votes:0,
guids:[]
}},{multi:true}, function(err, docs){
}
},{multi:true}, function(err, docs){
var next_song;
if(now_playing_doc.length == 2) next_song = now_playing_doc[1].id;
if(docs.n >= 1) change_song_post(coll, next_song);
@@ -1238,12 +1258,13 @@ function change_song(coll, error, id)
} else {
if(skipped[coll] != get_time()){
//skipped[coll] = get_time();
db.collection(coll).update({now_playing:true, id:id},
{$set:{
db.collection(coll).update({now_playing:true, id:id}, {
$set:{
now_playing:false,
votes:0,
guids:[]
}},{multi:true}, function(err, docs){
}
},{multi:true}, function(err, docs){
var next_song;
if(now_playing_doc.length == 2) next_song = now_playing_doc[1].id;
if(docs.n >= 1) change_song_post(coll, next_song);
@@ -1260,26 +1281,41 @@ function change_song(coll, error, id)
function change_song_post(coll, next_song)
{
db.collection(coll).aggregate([
{$match:{now_playing:false, type:{$ne: "suggested"}}},
{$sort:{votes:-1, added:1, title: 1}},
{$limit:1
db.collection(coll).aggregate([{
$match:{
now_playing:false,
type:{
$ne: "suggested"
}
}
}, {
$sort:{
votes:-1,
added:1,
title: 1
}
}, {
$limit:1
}], function(err, docs){
if(docs !== null && docs.length > 0){
var id = docs[0].id;
if(next_song && next_song != id) {
return;
}
db.collection(coll).update({id:id},
{$set:{
db.collection(coll).update({id:id},{
$set:{
now_playing:true,
votes:0,
guids:[],
added:get_time()
}}, function(err, returnDocs){
db.collection(coll).update({views:{$exists:true}},
{$set:{startTime:get_time(), skips:[]
}}, function(err, returnDocs){
}
}, function(err, returnDocs){
db.collection(coll).update({views:{$exists:true}},{
$set:{
startTime:get_time(),
skips:[]
}
}, function(err, returnDocs){
db.collection(coll).find({views:{$exists:true}}, function(err, conf){
io.to(coll).emit("channel", {type: "song_change", time: get_time(), remove: conf[0].removeplay});
send_play(coll);
@@ -1300,22 +1336,40 @@ function send_list(coll, socket, send, list_send, configs, shuffled)
if(docs.length > 0) {
db.collection(coll).find({now_playing: true}, function(err, np_docs) {
if(np_docs.length == 0) {
db.collection(coll).aggregate([
{$match:{views:{$exists: false}, type:{$ne: "suggested"}}},
{$sort:{now_playing: -1, votes:-1, added:1, title: 1}},
{$limit:1
db.collection(coll).aggregate([{
$match:{
views:{
$exists: false
},
type:{
$ne: "suggested"
}
}
}, {
$sort:{
now_playing: -1,
votes:-1,
added:1,
title: 1
}
}, {
$limit:1
}], function(err, now_playing_doc){
if(now_playing_doc[0].now_playing == false) {
db.collection(coll).update({id:now_playing_doc[0].id},
{$set:{
db.collection(coll).update({id:now_playing_doc[0].id}, {
$set:{
now_playing:true,
votes:0,
guids:[],
added:get_time()
}}, function(err, returnDocs){
db.collection(coll).update({views:{$exists:true}},
{$set:{startTime:get_time(), skips:[]
}}, function(err, returnDocs){
}
}, function(err, returnDocs){
db.collection(coll).update({views:{$exists:true}}, {
$set:{
startTime: get_time(),
skips:[]
}
}, function(err, returnDocs){
update_frontpage(coll, now_playing_doc[0].id, now_playing_doc[0].title);
send_list(coll, socket, send, list_send, configs, shuffled);
});
@@ -1323,26 +1377,30 @@ function send_list(coll, socket, send, list_send, configs, shuffled)
}
});
} else {
if(list_send)
if(list_send) {
io.to(coll).emit("channel", {type: "list", playlist: docs, shuffled: shuffled});
else if(!list_send)
} else if(!list_send) {
socket.emit("channel", {type: "list", playlist: docs, shuffled: shuffled});
if(socket === undefined && send)
}
if(socket === undefined && send) {
send_play(coll);
else if(send)
} else if(send) {
send_play(coll, socket);
}
}
});
} else {
if(list_send)
if(list_send) {
io.to(coll).emit("channel", {type: "list", playlist: docs, shuffled: shuffled});
else if(!list_send)
} else if(!list_send) {
socket.emit("channel", {type: "list", playlist: docs, shuffled: shuffled});
if(socket === undefined && send)
}
if(socket === undefined && send) {
send_play(coll);
else if(send)
} else if(send) {
send_play(coll, socket);
}
}
});
@@ -1365,7 +1423,6 @@ function send_play(coll, socket)
{
db.collection(coll).find({now_playing:true}, function(err, np){
db.collection(coll).find({views:{$exists:true}}, function(err, conf){
if(err !== null) console.log(err);
try{
if(get_time()-conf[0].startTime > np[0].duration){