From c25b45c314820cb852745885ba8c238b3752b25d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Rynning-T=C3=B8nnesen?= Date: Sun, 20 May 2018 16:22:24 +0200 Subject: [PATCH] Fixed thumbnail issue --- server/handlers/frontpage.js | 4 ++-- server/handlers/list.js | 4 ++-- server/handlers/list_change.js | 10 +++++----- server/routing/client/api.js | 3 +-- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/server/handlers/frontpage.js b/server/handlers/frontpage.js index 7b8225b9..c1a673b0 100644 --- a/server/handlers/frontpage.js +++ b/server/handlers/frontpage.js @@ -17,7 +17,7 @@ function frontpage_lists(msg, socket) { }); } -function update_frontpage(coll, id, title, thumbnail, callback) { +function update_frontpage(coll, id, title, thumbnail, source, callback) { coll = coll.replace(/ /g,''); db.collection("frontpage_lists").find({_id: coll}, function(e, doc) { var updateObject = { @@ -25,7 +25,7 @@ function update_frontpage(coll, id, title, thumbnail, callback) { title: title, accessed: Functions.get_time() }; - if(doc.length > 0 && (doc[0].thumbnail == "" || doc[0].thumbnail == undefined || doc[0].thumbnail.indexOf("ttps://i1.sndcdn.com") > -1)) { + if(doc.length > 0 && ((doc[0].thumbnail != "" && doc[0].thumbnail != undefined && doc[0].thumbnail.indexOf("https://i1.sndcdn.com") > -1) || (doc[0].thumbnail == "" || doc[0].thumbnail == undefined))) { updateObject.thumbnail = thumbnail; if(thumbnail == undefined) updateObject.thumbnail = ""; } diff --git a/server/handlers/list.js b/server/handlers/list.js index 8a9c843d..61a99b26 100644 --- a/server/handlers/list.js +++ b/server/handlers/list.js @@ -381,7 +381,7 @@ function change_song_post(coll, next_song, callback, socket) { List.send_play(coll, socket, true); callback(); } - Frontpage.update_frontpage(coll, docs[0].id, docs[0].title, docs[0].thumbnail); + Frontpage.update_frontpage(coll, docs[0].id, docs[0].title, docs[0].thumbnail, docs[0].source); }); }); }); @@ -439,7 +439,7 @@ function send_list(coll, socket, send, list_send, configs, shuffled) skips:[] } }, function(err, returnDocs){ - Frontpage.update_frontpage(coll, now_playing_doc[0].id, now_playing_doc[0].title, now_playing_doc[0].thumbnail); + Frontpage.update_frontpage(coll, now_playing_doc[0].id, now_playing_doc[0].title, now_playing_doc[0].thumbnail, now_playing_doc[0].source); List.send_list(coll, socket, send, list_send, configs, shuffled); }); }); diff --git a/server/handlers/list_change.js b/server/handlers/list_change.js index b2dbe8f1..97c411b1 100644 --- a/server/handlers/list_change.js +++ b/server/handlers/list_change.js @@ -55,8 +55,8 @@ function addFromOtherList(arr, guid, offline, socket) { project_object.now_playing = { "$literal": false }; to_set_np = false; } - db.collection(new_channel + "_settings").find({id: "config"}, function(e, new_conf) { - if(new_conf.length > 0 && (new_conf[0].userpass == "" || !new_conf[0].userpass || new_conf[0].userpass == crypto.createHash('sha256').update(Functions.decrypt_string(otheruser)).digest("base64"))) { + db.collection(new_channel + "_settings").find({id: "config"}, function(e, this_conf) { + if(this_conf.length > 0 && (this_conf[0].userpass == "" || !this_conf[0].userpass || this_conf[0].userpass == crypto.createHash('sha256').update(Functions.decrypt_string(otheruser)).digest("base64"))) { db.collection(channel + "_settings").find({id: "config"}, function(e, this_conf) { var hash = Functions.hash_pass(Functions.hash_pass(Functions.decrypt_string(arr.adminpass), true)); if((this_conf[0].userpass == "" || !this_conf[0].userpass || this_conf[0].userpass == crypto.createHash('sha256').update(Functions.decrypt_string(arr.userpass)).digest("base64"))) { @@ -89,7 +89,7 @@ function addFromOtherList(arr, guid, offline, socket) { to_change.id = np_docs[0].id; to_change.title = np_docs[0].title; db.collection("frontpage_lists").find({_id: coll}, function(e, doc) { - if(doc.length > 0 && doc[0].thumbnail != "" && doc[0].thumbnail != undefined) { + if(doc.length > 0 && ((doc[0].thumbnail != "" && doc[0].thumbnail != undefined && doc[0].thumbnail.indexOf("https://i1.sndcdn.com") > -1) || (doc[0].thumbnail == "" || doc[0].thumbnail == undefined))) { to_change.thumbnail = np_docs[0].thumbnail; } @@ -225,7 +225,7 @@ function addPlaylist(arr, guid, offline, socket) { to_change.id = np_docs[0].id; to_change.title = np_docs[0].title; db.collection("frontpage_lists").find({_id: channel}, function(e, doc) { - if(doc.length > 0 && doc[0].thumbnail != "" && doc[0].thumbnail != undefined) { + if(doc.length > 0 && ((doc[0].thumbnail != "" && doc[0].thumbnail != undefined && doc[0].thumbnail.indexOf("https://i1.sndcdn.com") > -1) || (doc[0].thumbnail == "" || doc[0].thumbnail == undefined))) { to_change.thumbnail = np_docs[0].thumbnail; } @@ -398,7 +398,7 @@ function add_function(arr, coll, guid, offline, socket) { db.collection(coll + "_settings").update({ id: "config" }, {$set:{startTime: Functions.get_time()}}); List.send_play(coll, undefined); var thumbnail = arr.thumbnail != undefined ? arr.thumbnail : undefined; - Frontpage.update_frontpage(coll, id, title, thumbnail); + Frontpage.update_frontpage(coll, id, title, thumbnail, arr.source); if(source != "soundcloud") Search.get_correct_info(new_song, coll, false); } else { io.to(coll).emit("channel", {type: "added", value: new_song}); diff --git a/server/routing/client/api.js b/server/routing/client/api.js index ba906b17..833de99f 100644 --- a/server/routing/client/api.js +++ b/server/routing/client/api.js @@ -712,7 +712,6 @@ router.route('/api/list/:channel_name/:video_id').post(function(req,res) { var type = fetch_only ? "fetch_song" : "add"; validateLogin(adminpass, userpass, channel_name, type, res, function(exists, conf, authenticated) { db.collection(channel_name).find({id: video_id}, function(err, result) { - console.log(result); if(result.length == 0 || result[0].type == "suggested") { var song_type = authenticated ? "video" : "suggested"; if(fetch_only && result.length == 0) { @@ -764,7 +763,7 @@ router.route('/api/list/:channel_name/:video_id').post(function(req,res) { }); } else if(set_np) { var thumbnail = req.body.thumbnail != undefined ? req.body.thumbnail : undefined; - Frontpage.update_frontpage(channel_name, video_id, title, thumbnail, function() { + Frontpage.update_frontpage(channel_name, video_id, title, thumbnail, source, function() { io.to(channel_name).emit("np", {np: [new_song], conf: [conf]}); postEnd(channel_name, configs, new_song, guid, res, authenticated, authorized); });