Fix for crashes

This commit is contained in:
Kasper Rynning-Tønnesen
2018-03-03 16:17:11 +01:00
parent 5c1e91467f
commit 731f26e3d4

View File

@@ -191,6 +191,7 @@ function change_song(coll, error, id, callback) {
}, { }, {
$limit:2 $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) {
if(error){ if(error){
request('http://img.youtube.com/vi/'+now_playing_doc[0].id+'/mqdefault.jpg', function (err, response, body) { request('http://img.youtube.com/vi/'+now_playing_doc[0].id+'/mqdefault.jpg', function (err, response, body) {
@@ -234,6 +235,7 @@ function change_song(coll, error, id, callback) {
db.collection("frontpage_lists").update({_id: coll, count: {$gt: 0}}, {$inc: {count: -1}, $set:{accessed: Functions.get_time()}}, {upsert: true}, function(err, docs){}); db.collection("frontpage_lists").update({_id: coll, count: {$gt: 0}}, {$inc: {count: -1}, $set:{accessed: Functions.get_time()}}, {upsert: true}, function(err, docs){});
}); });
} 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({now_playing:true, id:id}, { db.collection(coll).update({now_playing:true, id:id}, {
$set:{ $set:{
@@ -291,13 +293,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 + "_settings").update({id: "configs"}, { db.collection(coll + "_settings").update({id: "config"}, {
$set:{ $set:{
startTime:Functions.get_time(), startTime:Functions.get_time(),
skips:[] skips:[]
} }
}, function(err, returnDocs){ }, function(err, returnDocs){
db.collection(coll + "_settings").find(function(err, conf){ db.collection(coll + "_settings").find({id: "config"}, 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);
@@ -314,7 +316,14 @@ 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 + "_settings").find(function(err, conf){ db.collection(coll + "_settings").find({id: "config"}, function(err, _conf){
var conf = _conf;
if(conf.length == 0) {
var conf = {"id": "config", "addsongs":false, "adminpass":"", "allvideos":true, "frontpage":true, "longsongs":false, "removeplay": false, "shuffle": true, "skip": false, "skips": [], "startTime":Functions.get_time(), "views": [], "vote": false, "desc": "", userpass: ""};
db.collection(coll + "_settings").update({id: "config"}, conf, {upsert: true}, function(err, docs) {
send_list(coll, socket, send, list_send, configs, shuffled);
});
} else {
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) {
@@ -391,6 +400,7 @@ function send_list(coll, socket, send, list_send, configs, shuffled)
List.send_play(coll, socket); List.send_play(coll, socket);
} }
} }
});
if(configs) if(configs)
{ {
if(conf.length > 0) { if(conf.length > 0) {
@@ -405,7 +415,7 @@ function send_list(coll, socket, send, list_send, configs, shuffled)
}); });
} }
} }
}); }
}); });
if(socket){ if(socket){
db.collection(coll).find({type:"suggested"}).sort({added: 1}, function(err, sugg){ db.collection(coll).find({type:"suggested"}).sort({added: 1}, function(err, sugg){