mirror of
https://github.com/KevinMidboe/zoff.git
synced 2025-10-29 18:00:23 +00:00
Fixed issue with suggested being duplicated and RESTApi posting
This commit is contained in:
@@ -308,15 +308,15 @@ function del(params, socket, socketid) {
|
|||||||
if(docs !== null && docs.length !== 0 && docs[0].adminpass == Functions.hash_pass(Functions.decrypt_string(socketid, params.adminpass)))
|
if(docs !== null && docs.length !== 0 && docs[0].adminpass == Functions.hash_pass(Functions.decrypt_string(socketid, params.adminpass)))
|
||||||
{
|
{
|
||||||
db.collection(coll).find({id:params.id}, function(err, docs){
|
db.collection(coll).find({id:params.id}, function(err, docs){
|
||||||
dont_increment = true;
|
var dont_increment = false;
|
||||||
if(docs[0]){
|
if(docs[0]){
|
||||||
if(docs[0].type == "suggested"){
|
if(docs[0].type == "suggested"){
|
||||||
dont_increment = false;
|
dont_increment = true;
|
||||||
}
|
}
|
||||||
db.collection(coll).remove({id:params.id}, function(err, docs){
|
db.collection(coll).remove({id:params.id}, function(err, docs){
|
||||||
socket.emit("toast", "deletesong");
|
socket.emit("toast", "deletesong");
|
||||||
io.to(coll).emit("channel", {type:"deleted", value: params.id});
|
io.to(coll).emit("channel", {type:"deleted", value: params.id});
|
||||||
if(dont_increment) db.collection("frontpage_lists").update({_id: coll, count: {$gt: 0}}, {$inc: {count: -1}, $set:{accessed: Functions.get_time()}}, {upsert: true}, function(err, docs){});
|
if(!dont_increment) db.collection("frontpage_lists").update({_id: coll, count: {$gt: 0}}, {$inc: {count: -1}, $set:{accessed: Functions.get_time()}}, {upsert: true}, function(err, docs){});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ function get_correct_info(song_generated, channel, broadcast, callback) {
|
|||||||
}, function(err, docs) {
|
}, function(err, docs) {
|
||||||
if(broadcast && docs.nModified == 1) {
|
if(broadcast && docs.nModified == 1) {
|
||||||
song_generated.new_id = song_generated.id;
|
song_generated.new_id = song_generated.id;
|
||||||
|
//if(song_generated.type == "video")
|
||||||
io.to(channel).emit("channel", {type: "changed_values", value: song_generated});
|
io.to(channel).emit("channel", {type: "changed_values", value: song_generated});
|
||||||
if(typeof(callback) == "function") {
|
if(typeof(callback) == "function") {
|
||||||
callback();
|
callback();
|
||||||
|
|||||||
@@ -76,6 +76,16 @@ var List = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
changedValues: function(song) {
|
changedValues: function(song) {
|
||||||
|
if(song.type == "suggested") {
|
||||||
|
$("#suggested-" + song.id).find(".vote-container").attr("title", song.title);
|
||||||
|
$("#suggested-" + song.id).find(".list-title").attr("title", song.title);
|
||||||
|
$("#suggested-" + song.id).find(".list-title").text(song.title);
|
||||||
|
var _temp_duration = Helper.secondsToOther(song.duration);
|
||||||
|
$("#suggested-" + song.id).find(".card-duration").text(Helper.pad(_temp_duration[0]) + ":" + Helper.pad(_temp_duration[1]));
|
||||||
|
$("#suggested-" + song.id).find(".list-image").attr("style", "background-image:url('//img.youtube.com/vi/"+song.new_id+"/mqdefault.jpg');");
|
||||||
|
$("#suggested-" + song.id).attr("id", song.new_id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
var i = List.getIndexOfSong(song.id);
|
var i = List.getIndexOfSong(song.id);
|
||||||
if(i >= 0 && window.location.pathname != "/") {
|
if(i >= 0 && window.location.pathname != "/") {
|
||||||
full_playlist[i].title = song.title;
|
full_playlist[i].title = song.title;
|
||||||
|
|||||||
@@ -6,6 +6,11 @@ var Suggestions = {
|
|||||||
} else {
|
} else {
|
||||||
number_suggested = number_suggested + params.length;
|
number_suggested = number_suggested + params.length;
|
||||||
}
|
}
|
||||||
|
for(var i = 0; i < params.length; i++) {
|
||||||
|
if($("#suggested-" + params[i].id).length > 0) {
|
||||||
|
number_suggested -= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
var to_display = number_suggested > 9 ? "9+" : number_suggested;
|
var to_display = number_suggested > 9 ? "9+" : number_suggested;
|
||||||
if($(".suggested-link span.badge.new.white").hasClass("hide") && number_suggested > 0){
|
if($(".suggested-link span.badge.new.white").hasClass("hide") && number_suggested > 0){
|
||||||
$(".suggested-link span.badge.new.white").removeClass("hide");
|
$(".suggested-link span.badge.new.white").removeClass("hide");
|
||||||
@@ -26,7 +31,9 @@ var Suggestions = {
|
|||||||
var video_id = params.id;
|
var video_id = params.id;
|
||||||
var video_title = params.title;
|
var video_title = params.title;
|
||||||
var song = List.generateSong({id: video_id, title: video_title, length: params.duration, duration: duration}, false, false, false, true);
|
var song = List.generateSong({id: video_id, title: video_title, length: params.duration, duration: duration}, false, false, false, true);
|
||||||
$("#user-suggest-html").append(song);
|
if($("#" + $(song).attr("id")).length == 0) {
|
||||||
|
$("#user-suggest-html").append(song);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
fetchYoutubeSuggests: function(id){
|
fetchYoutubeSuggests: function(id){
|
||||||
|
|||||||
@@ -89,14 +89,14 @@ router.route('/api/list/:channel_name/:video_id').delete(function(req, res) {
|
|||||||
res.sendStatus(404);
|
res.sendStatus(404);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
dont_increment = true;
|
var dont_increment = false;
|
||||||
if(docs[0]){
|
if(docs[0]){
|
||||||
if(docs[0].type == "suggested"){
|
if(docs[0].type == "suggested"){
|
||||||
dont_increment = false;
|
dont_increment = true;
|
||||||
}
|
}
|
||||||
db.collection(channel_name).remove({id:video_id}, function(err, docs){
|
db.collection(channel_name).remove({id:video_id}, function(err, docs){
|
||||||
io.to(channel_name).emit("channel", {type:"deleted", value: video_id});
|
io.to(channel_name).emit("channel", {type:"deleted", value: video_id});
|
||||||
if(dont_increment) {
|
if(!dont_increment) {
|
||||||
db.collection("frontpage_lists").update({_id: channel_name, count: {$gt: 0}}, {$inc: {count: -1}, $set:{accessed: Functions.get_time()}}, {upsert: true}, function(err, docs){
|
db.collection("frontpage_lists").update({_id: channel_name, count: {$gt: 0}}, {$inc: {count: -1}, $set:{accessed: Functions.get_time()}}, {upsert: true}, function(err, docs){
|
||||||
updateTimeout(guid, res, "DELETE", function(err, docs) {
|
updateTimeout(guid, res, "DELETE", function(err, docs) {
|
||||||
res.sendStatus(200);
|
res.sendStatus(200);
|
||||||
@@ -378,25 +378,29 @@ router.route('/api/list/:channel_name/:video_id').post(function(req,res) {
|
|||||||
io.to(channel_name).emit("conf", configs);
|
io.to(channel_name).emit("conf", configs);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
db.collection(channel_name).update(new_song, {upsert: true}, function(err, success) {
|
db.collection(channel_name).update({"id": new_song.id}, new_song, {upsert: true}, function(err, success) {
|
||||||
if(create_frontpage_lists) {
|
if(create_frontpage_lists) {
|
||||||
db.collection("frontpage_lists").update({"_id": channel_name, "count" : 1, "frontpage": true, "accessed": Functions.get_time(), "viewers": 1}, {upsert: true}, function(err, docs) {
|
db.collection("frontpage_lists").update({"_id": channel_name, "count" : (authenticated ? 1 : 0), "frontpage": true, "accessed": Functions.get_time(), "viewers": 1}, {upsert: true}, function(err, docs) {
|
||||||
if(authenticated) {
|
if(authenticated) {
|
||||||
io.to(channel_name).emit("channel", {type: "added", value: new_song});
|
io.to(channel_name).emit("channel", {type: "added", value: new_song});
|
||||||
} else {
|
} else {
|
||||||
io.to(coll).emit("suggested", new_song);
|
io.to(channel_name).emit("suggested", new_song);
|
||||||
}
|
}
|
||||||
postEnd(channel_name, configs, new_song, guid, res);
|
postEnd(channel_name, configs, new_song, guid, res, authenticated);
|
||||||
});
|
});
|
||||||
} else if(set_np) {
|
} else if(set_np) {
|
||||||
Frontpage.update_frontpage(channel_name, video_id, title, function() {
|
Frontpage.update_frontpage(channel_name, video_id, title, function() {
|
||||||
io.to(channel_name).emit("np", new_song);
|
io.to(channel_name).emit("np", new_song);
|
||||||
postEnd(channel_name, configs, new_song, guid, res);
|
postEnd(channel_name, configs, new_song, guid, res, authenticated);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
db.collection("frontpage_lists").update({"_id": channel_name}, {$inc: {count: 1}}, function(err, docs) {
|
db.collection("frontpage_lists").update({"_id": channel_name}, {$inc: {count: (authenticated ? 1 : 0)}}, function(err, docs) {
|
||||||
io.to(channel_name).emit("channel", {type: "added", value: new_song});
|
if(authenticated) {
|
||||||
postEnd(channel_name, configs, new_song, guid, res);
|
io.to(channel_name).emit("channel", {type: "added", value: new_song});
|
||||||
|
} else {
|
||||||
|
io.to(channel_name).emit("suggested", new_song);
|
||||||
|
}
|
||||||
|
postEnd(channel_name, configs, new_song, guid, res, authenticated);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -718,7 +722,7 @@ function validateLogin(adminpass, userpass, channel_name, type, res, callback) {
|
|||||||
(type == "vote" && ((conf[0].vote && (conf[0].adminpass == "" || conf[0].adminpass == undefined || conf[0].adminpass == adminpass)) || !conf[0].vote)) ||
|
(type == "vote" && ((conf[0].vote && (conf[0].adminpass == "" || conf[0].adminpass == undefined || conf[0].adminpass == adminpass)) || !conf[0].vote)) ||
|
||||||
(type == "config" && (conf[0].adminpass == "" || conf[0].adminpass == undefined || conf[0].adminpass == adminpass))
|
(type == "config" && (conf[0].adminpass == "" || conf[0].adminpass == undefined || conf[0].adminpass == adminpass))
|
||||||
) {
|
) {
|
||||||
callback(exists, conf);
|
callback(exists, conf, true);
|
||||||
} else if(type == "add") {
|
} else if(type == "add") {
|
||||||
callback(exists, conf, false);
|
callback(exists, conf, false);
|
||||||
} else {
|
} else {
|
||||||
@@ -728,7 +732,7 @@ function validateLogin(adminpass, userpass, channel_name, type, res, callback) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function postEnd(channel_name, configs, new_song, guid, res) {
|
function postEnd(channel_name, configs, new_song, guid, res, authenticated) {
|
||||||
if(configs != undefined) {
|
if(configs != undefined) {
|
||||||
io.to(channel_name).emit("conf", configs);
|
io.to(channel_name).emit("conf", configs);
|
||||||
}
|
}
|
||||||
@@ -736,7 +740,7 @@ function postEnd(channel_name, configs, new_song, guid, res) {
|
|||||||
updateTimeout(guid, res, "POST", function(err, docs) {
|
updateTimeout(guid, res, "POST", function(err, docs) {
|
||||||
Search.get_correct_info(new_song, channel_name, !new_song.now_playing, function() {
|
Search.get_correct_info(new_song, channel_name, !new_song.now_playing, function() {
|
||||||
res.header({'Content-Type': 'application/json'});
|
res.header({'Content-Type': 'application/json'});
|
||||||
res.status(200).send(JSON.stringify(new_song));
|
res.status(authenticated ? 200 : 403).send(JSON.stringify(new_song));
|
||||||
return;
|
return;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user