mirror of
https://github.com/KevinMidboe/zoff.git
synced 2025-12-29 13:31:00 +00:00
indentations on server.js
This commit is contained in:
2
server/public/assets/dist/embed.min.js
vendored
2
server/public/assets/dist/embed.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -11,7 +11,7 @@ var Search = {
|
|||||||
}
|
}
|
||||||
$("#song-title").toggleClass("hide");
|
$("#song-title").toggleClass("hide");
|
||||||
$("#results").empty();
|
$("#results").empty();
|
||||||
if($("#search-btn i").html() == "close"){
|
if($("#search-btn i").html() == "close") {
|
||||||
$("#search-btn i").html("search");
|
$("#search-btn i").html("search");
|
||||||
} else {
|
} else {
|
||||||
$("#search-btn i").html("close");
|
$("#search-btn i").html("close");
|
||||||
|
|||||||
209
server/server.js
209
server/server.js
@@ -118,8 +118,8 @@ app.use('/assets', express.static(publicPath + '/assets'));
|
|||||||
|
|
||||||
|
|
||||||
/*process.on('uncaughtException', function(e){
|
/*process.on('uncaughtException', function(e){
|
||||||
console.log("\n" + new Date().toString() + "\n", e.stack || e);
|
console.log("\n" + new Date().toString() + "\n", e.stack || e);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
})*/
|
})*/
|
||||||
|
|
||||||
db.on('error',function(err) {
|
db.on('error',function(err) {
|
||||||
@@ -566,8 +566,9 @@ io.on('connection', function(socket){
|
|||||||
} else if(full_list) {
|
} else if(full_list) {
|
||||||
np = false;
|
np = false;
|
||||||
}
|
}
|
||||||
} else
|
} else {
|
||||||
np = false;
|
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){
|
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)
|
if(np)
|
||||||
{
|
{
|
||||||
@@ -582,13 +583,13 @@ io.on('connection', function(socket){
|
|||||||
}
|
}
|
||||||
db.collection("frontpage_lists").update({_id:coll}, {$inc:{count:1}, $set:{accessed: get_time()}}, {upsert:true}, function(err, docs){});
|
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");
|
socket.emit("toast", "addedsong");
|
||||||
else if(full_list && last) {
|
} else if(full_list && last) {
|
||||||
socket.emit("toast", "addedplaylist");
|
socket.emit("toast", "addedplaylist");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}else if(!full_list){
|
} else if(!full_list) {
|
||||||
vote(coll, id, guid, socket, full_list, last);
|
vote(coll, id, guid, socket, full_list, last);
|
||||||
if(full_list && last) {
|
if(full_list && last) {
|
||||||
socket.emit("toast", "addedplaylist");
|
socket.emit("toast", "addedplaylist");
|
||||||
@@ -597,20 +598,26 @@ io.on('connection', function(socket){
|
|||||||
socket.emit("toast", "addedplaylist");
|
socket.emit("toast", "addedplaylist");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}else if(!full_list)
|
} else if(!full_list) {
|
||||||
{
|
db.collection(coll).find({id: id}, function(err, docs) {
|
||||||
db.collection(coll).find({id: id}, function(err, docs){
|
if(docs.length === 0) {
|
||||||
if(docs.length === 0){
|
db.collection(coll).update({id: id}, {$set:{
|
||||||
db.collection(coll).update({id: id},
|
"added":get_time(),
|
||||||
{$set:{
|
"guids": [guid],
|
||||||
"added":get_time(), "guids": [guid], "id":id, "now_playing": false, "title":title, "votes":1, "duration":duration, type:"suggested"}},
|
"id":id,
|
||||||
|
"now_playing": false,
|
||||||
|
"title":title,
|
||||||
|
"votes":1,
|
||||||
|
"duration":duration,
|
||||||
|
"type":"suggested"}
|
||||||
|
},
|
||||||
{upsert:true}, function(err, docs){
|
{upsert:true}, function(err, docs){
|
||||||
socket.emit("toast", "suggested");
|
socket.emit("toast", "suggested");
|
||||||
io.to(coll).emit("suggested", {id: id, title: title, duration: duration});
|
io.to(coll).emit("suggested", {id: id, title: title, duration: duration});
|
||||||
});
|
});
|
||||||
}else if(docs[0].now_playing === true){
|
} else if(docs[0].now_playing === true){
|
||||||
socket.emit("toast", "alreadyplay");
|
socket.emit("toast", "alreadyplay");
|
||||||
}else{
|
} else{
|
||||||
if(conf[0].vote === false) vote(coll, id, guid, socket, full_list, last);
|
if(conf[0].vote === false) vote(coll, id, guid, socket, full_list, last);
|
||||||
else socket.emit("toast", "listhaspass");
|
else socket.emit("toast", "listhaspass");
|
||||||
}
|
}
|
||||||
@@ -858,11 +865,11 @@ io.on('connection', function(socket){
|
|||||||
var hash;
|
var hash;
|
||||||
if(params.description) description = params.description;
|
if(params.description) description = params.description;
|
||||||
|
|
||||||
if(adminpass !== "")
|
if(adminpass !== "") {
|
||||||
hash = hash_pass(decrypt_string(socketid, adminpass));
|
hash = hash_pass(decrypt_string(socketid, adminpass));
|
||||||
else
|
} else {
|
||||||
hash = adminpass;
|
hash = adminpass;
|
||||||
|
}
|
||||||
db.collection(coll).find({views:{$exists:true}}, function(err, docs){
|
db.collection(coll).find({views:{$exists:true}}, 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)
|
||||||
{
|
{
|
||||||
@@ -878,7 +885,8 @@ io.on('connection', function(socket){
|
|||||||
adminpass:hash,
|
adminpass:hash,
|
||||||
desc: description,
|
desc: description,
|
||||||
userpass: userpass,
|
userpass: userpass,
|
||||||
}}, function(err, docs){
|
}
|
||||||
|
}, function(err, docs){
|
||||||
db.collection(coll).find({views:{$exists:true}}, function(err, docs){
|
db.collection(coll).find({views:{$exists:true}}, 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;
|
||||||
@@ -886,12 +894,13 @@ io.on('connection', function(socket){
|
|||||||
io.to(coll).emit("conf", docs);
|
io.to(coll).emit("conf", docs);
|
||||||
socket.emit("toast", "savedsettings");
|
socket.emit("toast", "savedsettings");
|
||||||
|
|
||||||
db.collection("frontpage_lists").update({_id: coll},
|
db.collection("frontpage_lists").update({_id: coll}, {$set:{
|
||||||
{$set:{frontpage:frontpage, accessed: get_time()}},
|
frontpage:frontpage, accessed: get_time()}
|
||||||
|
},
|
||||||
{upsert:true}, function(err, docs){});
|
{upsert:true}, function(err, docs){});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}else{
|
} else{
|
||||||
socket.emit("toast", "wrongpass");
|
socket.emit("toast", "wrongpass");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -1097,16 +1106,15 @@ function change_name(name, guid, oldname){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function update_frontpage(coll, id, title)
|
function update_frontpage(coll, id, title) {
|
||||||
{
|
db.collection("frontpage_lists").update({_id: coll}, {$set: {
|
||||||
db.collection("frontpage_lists").update(
|
id: id,
|
||||||
{_id: coll},
|
title: title,
|
||||||
{$set:{id: id, title: title, accessed: get_time()}},
|
accessed: get_time()}
|
||||||
{upsert: true}, function(err, returnDocs){});
|
},{upsert: true}, function(err, returnDocs){});
|
||||||
}
|
}
|
||||||
|
|
||||||
function del(params, socket, socketid)
|
function del(params, socket, socketid) {
|
||||||
{
|
|
||||||
if(params.id){
|
if(params.id){
|
||||||
var coll = emojiStrip(params.channel).toLowerCase();
|
var coll = emojiStrip(params.channel).toLowerCase();
|
||||||
//coll = decodeURIComponent(coll);
|
//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');
|
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){
|
db.collection(coll).find({id:id, now_playing: false}, function(err, docs){
|
||||||
if(docs !== null && docs.length > 0 && !contains(docs[0].guids, guid))
|
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){
|
db.collection(coll).find({views:{$exists:true}}, 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)
|
||||||
{
|
{
|
||||||
db.collection(coll).aggregate([
|
db.collection(coll).aggregate([{
|
||||||
{$match:{views:{$exists: false}, type:{$ne: "suggested"}}},
|
$match:{
|
||||||
{$sort:{now_playing: -1, votes:-1, added:1, title: 1}},
|
views:{
|
||||||
{$limit:2
|
$exists: false
|
||||||
|
},
|
||||||
|
type:{
|
||||||
|
$ne: "suggested"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
$sort:{
|
||||||
|
now_playing: -1,
|
||||||
|
votes:-1,
|
||||||
|
added:1,
|
||||||
|
title: 1
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
$limit:2
|
||||||
}], function(err, now_playing_doc){
|
}], function(err, now_playing_doc){
|
||||||
if((id && id == now_playing_doc[0].id) || !id) {
|
if((id && id == now_playing_doc[0].id) || !id) {
|
||||||
//db.collection(coll).find({now_playing:true}, function(err, now_playing_doc){
|
//db.collection(coll).find({now_playing:true}, function(err, now_playing_doc){
|
||||||
@@ -1209,15 +1228,16 @@ function change_song(coll, error, id)
|
|||||||
io.to(coll).emit("channel", {type: "deleted", value: now_playing_doc[0].id, removed: true});
|
io.to(coll).emit("channel", {type: "deleted", value: now_playing_doc[0].id, removed: true});
|
||||||
db.collection("frontpage_lists").update({_id: coll}, {$inc: {count: -1}, $set:{accessed: get_time()}}, {upsert: true}, function(err, docs){});
|
db.collection("frontpage_lists").update({_id: coll}, {$inc: {count: -1}, $set:{accessed: get_time()}}, {upsert: true}, function(err, docs){});
|
||||||
});
|
});
|
||||||
}else{
|
} else {
|
||||||
if(skipped[coll] != get_time()){
|
if(skipped[coll] != get_time()){
|
||||||
skipped[coll] = get_time();
|
skipped[coll] = get_time();
|
||||||
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,
|
||||||
votes:0,
|
votes:0,
|
||||||
guids:[]
|
guids:[]
|
||||||
}},{multi:true}, function(err, docs){
|
}
|
||||||
|
},{multi:true}, function(err, docs){
|
||||||
var next_song;
|
var next_song;
|
||||||
if(now_playing_doc.length == 2) next_song = now_playing_doc[1].id;
|
if(now_playing_doc.length == 2) next_song = now_playing_doc[1].id;
|
||||||
if(docs.n >= 1) change_song_post(coll, next_song);
|
if(docs.n >= 1) change_song_post(coll, next_song);
|
||||||
@@ -1238,12 +1258,13 @@ function change_song(coll, error, id)
|
|||||||
} else {
|
} else {
|
||||||
if(skipped[coll] != get_time()){
|
if(skipped[coll] != get_time()){
|
||||||
//skipped[coll] = get_time();
|
//skipped[coll] = get_time();
|
||||||
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,
|
||||||
votes:0,
|
votes:0,
|
||||||
guids:[]
|
guids:[]
|
||||||
}},{multi:true}, function(err, docs){
|
}
|
||||||
|
},{multi:true}, function(err, docs){
|
||||||
var next_song;
|
var next_song;
|
||||||
if(now_playing_doc.length == 2) next_song = now_playing_doc[1].id;
|
if(now_playing_doc.length == 2) next_song = now_playing_doc[1].id;
|
||||||
if(docs.n >= 1) change_song_post(coll, next_song);
|
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)
|
function change_song_post(coll, next_song)
|
||||||
{
|
{
|
||||||
db.collection(coll).aggregate([
|
db.collection(coll).aggregate([{
|
||||||
{$match:{now_playing:false, type:{$ne: "suggested"}}},
|
$match:{
|
||||||
{$sort:{votes:-1, added:1, title: 1}},
|
now_playing:false,
|
||||||
{$limit:1
|
type:{
|
||||||
|
$ne: "suggested"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
$sort:{
|
||||||
|
votes:-1,
|
||||||
|
added:1,
|
||||||
|
title: 1
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
$limit:1
|
||||||
}], function(err, docs){
|
}], function(err, docs){
|
||||||
if(docs !== null && docs.length > 0){
|
if(docs !== null && docs.length > 0){
|
||||||
var id = docs[0].id;
|
var id = docs[0].id;
|
||||||
if(next_song && next_song != id) {
|
if(next_song && next_song != id) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
db.collection(coll).update({id:id},
|
db.collection(coll).update({id:id},{
|
||||||
{$set:{
|
$set:{
|
||||||
now_playing:true,
|
now_playing:true,
|
||||||
votes:0,
|
votes:0,
|
||||||
guids:[],
|
guids:[],
|
||||||
added:get_time()
|
added:get_time()
|
||||||
}}, function(err, returnDocs){
|
}
|
||||||
db.collection(coll).update({views:{$exists:true}},
|
}, function(err, returnDocs){
|
||||||
{$set:{startTime:get_time(), skips:[]
|
db.collection(coll).update({views:{$exists:true}},{
|
||||||
}}, function(err, returnDocs){
|
$set:{
|
||||||
|
startTime:get_time(),
|
||||||
|
skips:[]
|
||||||
|
}
|
||||||
|
}, function(err, returnDocs){
|
||||||
db.collection(coll).find({views:{$exists:true}}, function(err, conf){
|
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});
|
io.to(coll).emit("channel", {type: "song_change", time: get_time(), remove: conf[0].removeplay});
|
||||||
send_play(coll);
|
send_play(coll);
|
||||||
@@ -1300,22 +1336,40 @@ function send_list(coll, socket, send, list_send, configs, shuffled)
|
|||||||
if(docs.length > 0) {
|
if(docs.length > 0) {
|
||||||
db.collection(coll).find({now_playing: true}, function(err, np_docs) {
|
db.collection(coll).find({now_playing: true}, function(err, np_docs) {
|
||||||
if(np_docs.length == 0) {
|
if(np_docs.length == 0) {
|
||||||
db.collection(coll).aggregate([
|
db.collection(coll).aggregate([{
|
||||||
{$match:{views:{$exists: false}, type:{$ne: "suggested"}}},
|
$match:{
|
||||||
{$sort:{now_playing: -1, votes:-1, added:1, title: 1}},
|
views:{
|
||||||
{$limit:1
|
$exists: false
|
||||||
|
},
|
||||||
|
type:{
|
||||||
|
$ne: "suggested"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
$sort:{
|
||||||
|
now_playing: -1,
|
||||||
|
votes:-1,
|
||||||
|
added:1,
|
||||||
|
title: 1
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
$limit:1
|
||||||
}], function(err, now_playing_doc){
|
}], function(err, now_playing_doc){
|
||||||
if(now_playing_doc[0].now_playing == false) {
|
if(now_playing_doc[0].now_playing == false) {
|
||||||
db.collection(coll).update({id:now_playing_doc[0].id},
|
db.collection(coll).update({id:now_playing_doc[0].id}, {
|
||||||
{$set:{
|
$set:{
|
||||||
now_playing:true,
|
now_playing:true,
|
||||||
votes:0,
|
votes:0,
|
||||||
guids:[],
|
guids:[],
|
||||||
added:get_time()
|
added:get_time()
|
||||||
}}, function(err, returnDocs){
|
}
|
||||||
db.collection(coll).update({views:{$exists:true}},
|
}, function(err, returnDocs){
|
||||||
{$set:{startTime:get_time(), skips:[]
|
db.collection(coll).update({views:{$exists:true}}, {
|
||||||
}}, function(err, returnDocs){
|
$set:{
|
||||||
|
startTime: get_time(),
|
||||||
|
skips:[]
|
||||||
|
}
|
||||||
|
}, function(err, returnDocs){
|
||||||
update_frontpage(coll, now_playing_doc[0].id, now_playing_doc[0].title);
|
update_frontpage(coll, now_playing_doc[0].id, now_playing_doc[0].title);
|
||||||
send_list(coll, socket, send, list_send, configs, shuffled);
|
send_list(coll, socket, send, list_send, configs, shuffled);
|
||||||
});
|
});
|
||||||
@@ -1323,26 +1377,30 @@ function send_list(coll, socket, send, list_send, configs, shuffled)
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
if(list_send)
|
if(list_send) {
|
||||||
io.to(coll).emit("channel", {type: "list", playlist: docs, shuffled: shuffled});
|
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});
|
socket.emit("channel", {type: "list", playlist: docs, shuffled: shuffled});
|
||||||
if(socket === undefined && send)
|
}
|
||||||
|
if(socket === undefined && send) {
|
||||||
send_play(coll);
|
send_play(coll);
|
||||||
else if(send)
|
} else if(send) {
|
||||||
send_play(coll, socket);
|
send_play(coll, socket);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
if(list_send)
|
if(list_send) {
|
||||||
io.to(coll).emit("channel", {type: "list", playlist: docs, shuffled: shuffled});
|
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});
|
socket.emit("channel", {type: "list", playlist: docs, shuffled: shuffled});
|
||||||
if(socket === undefined && send)
|
}
|
||||||
|
if(socket === undefined && send) {
|
||||||
send_play(coll);
|
send_play(coll);
|
||||||
else if(send)
|
} else if(send) {
|
||||||
send_play(coll, socket);
|
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({now_playing:true}, function(err, np){
|
||||||
db.collection(coll).find({views:{$exists:true}}, function(err, conf){
|
db.collection(coll).find({views:{$exists:true}}, function(err, conf){
|
||||||
|
|
||||||
if(err !== null) console.log(err);
|
if(err !== null) console.log(err);
|
||||||
try{
|
try{
|
||||||
if(get_time()-conf[0].startTime > np[0].duration){
|
if(get_time()-conf[0].startTime > np[0].duration){
|
||||||
|
|||||||
Reference in New Issue
Block a user