This commit is contained in:
Kasper Rynning-Tønnesen
2018-07-10 16:21:16 +02:00
parent 061b3832ae
commit d3e6af4643
4 changed files with 406 additions and 396 deletions

View File

@@ -6,9 +6,9 @@ var crypto = require('crypto');
var Filter = require('bad-words');
var filter = new Filter({ placeHolder: 'x'});
/*var filter = {
clean: function(str) {
return str;
}
clean: function(str) {
return str;
}
}*/
var db = require(pathThumbnails + '/handlers/db.js');
@@ -93,17 +93,19 @@ function addFromOtherList(arr, guid, offline, socket) {
MongoClient.connect(url, function(err, _db) {
var dbo = _db.db(mongo_config.config);
dbo.collection(channel).insertMany(docs, {ordered: false}, function(err, res) {
db.collection(channel).count({type: {$ne: "suggested"}}, function(err, count) {
db.collection(channel + "_settings").update({id: "config"}, {$set: {startTime: Functions.get_time()}}, function(e,d) {
if(to_set_np) {
var to_change = {
_id: channel,
count: res.nInserted != undefined ? res.nInserted : res.insertedCount,
count: count,
frontpage: true,
accessed: Functions.get_time(),
}
db.collection(channel).find({now_playing: true}, function(e, np_docs) {
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 && (doc[0].thumbnail.indexOf("https://i1.sndcdn.com") > -1 || doc[0].thumbnail.indexOf("https://w1.sndcdn.com") > -1)) || (doc[0].thumbnail == "" || doc[0].thumbnail == undefined))) {
to_change.thumbnail = np_docs[0].thumbnail;
@@ -118,7 +120,7 @@ function addFromOtherList(arr, guid, offline, socket) {
});
});
} else {
db.collection("frontpage_lists").update({_id: channel}, {$inc: {count: res.nInserted != undefined ? res.nInserted : res.insertedCount}}, function(e, d) {
db.collection("frontpage_lists").update({_id: channel}, {$set: {count: count}}, function(e, d) {
List.send_list(channel, undefined, false, true, false);
List.send_play(channel, undefined);
socket.emit("toast", "addedplaylist");
@@ -129,6 +131,7 @@ function addFromOtherList(arr, guid, offline, socket) {
});
});
});
});
} else {
socket.emit("toast", "listhaspass");
return;
@@ -236,11 +239,12 @@ function addPlaylist(arr, guid, offline, socket) {
bulk.insert(this_element);
}
bulk.execute(function(err, results) {
db.collection(channel).count({type: {$ne: "suggested"}}, function(err, count) {
db.collection(channel + "_settings").update({id: "config"}, {$set: {startTime: Functions.get_time()}}, function(e,d) {
if(to_set_np) {
var to_change = {
_id: channel,
count: results.nInserted,
count: count,
frontpage: true,
accessed: Functions.get_time(),
}
@@ -261,7 +265,7 @@ function addPlaylist(arr, guid, offline, socket) {
});
});
} else {
db.collection("frontpage_lists").update({_id: channel}, {$inc: {count: results.nInserted != undefined ? results.nInserted : results.insertedCount}}, function(e, d) {
db.collection("frontpage_lists").update({_id: channel}, {$set: {count: count}}, function(e, d) {
List.send_list(channel, undefined, false, true, false);
List.send_play(channel, undefined);
socket.emit("toast", "addedplaylist");
@@ -271,6 +275,7 @@ function addPlaylist(arr, guid, offline, socket) {
});
});
});
});
} else {
socket.emit("toast", "listhaspass");
return;
@@ -496,9 +501,9 @@ function add_function(arr, coll, guid, offline, socket) {
};
socket.emit('update_required', result);
}
}
}
function voteUndecided(msg, coll, guid, offline, socket) {
function voteUndecided(msg, coll, guid, offline, socket) {
var socketid = socket.zoff_id;
if(typeof(msg) === 'object' && msg !== undefined && msg !== null){
@@ -572,9 +577,9 @@ function voteUndecided(msg, coll, guid, offline, socket) {
};
socket.emit('update_required', result);
}
}
}
function shuffle(msg, coll, guid, offline, socket) {
function shuffle(msg, coll, guid, offline, socket) {
var socketid = socket.zoff_id;
if(!msg.hasOwnProperty("channel") || typeof(msg.channel) != "string") {
var result = {
@@ -662,9 +667,9 @@ function shuffle(msg, coll, guid, offline, socket) {
});
});
});
}
}
function del(params, socket, socketid) {
function del(params, socket, socketid) {
if(params.id){
var coll = Functions.removeEmojis(params.channel).toLowerCase();
//coll = coll.replace(/_/g, "").replace(/ /g,'');
@@ -690,9 +695,9 @@ function del(params, socket, socketid) {
}
});
}
}
}
function delete_all(msg, coll, guid, offline, socket) {
function delete_all(msg, coll, guid, offline, socket) {
var socketid = socket.zoff_id;
if(typeof(msg) == 'object' ) {
if(!msg.hasOwnProperty('channel') || typeof(msg.channel) != "string") {
@@ -753,9 +758,9 @@ function delete_all(msg, coll, guid, offline, socket) {
socket.emit('update_required', result);
return;
}
}
}
function vote(coll, id, guid, socket) {
function vote(coll, id, guid, socket) {
//coll = coll.replace(/ /g,'');
db.collection(coll).find({id:id, now_playing: false, type:"video"}, function(err, docs){
if(docs !== null && docs.length > 0 && !Functions.contains(docs[0].guids, guid))
@@ -772,13 +777,13 @@ function vote(coll, id, guid, socket) {
socket.emit("toast", "alreadyvoted");
}
});
}
}
module.exports.addPlaylist = addPlaylist;
module.exports.addFromOtherList = addFromOtherList;
module.exports.add_function = add_function;
module.exports.voteUndecided = voteUndecided;
module.exports.shuffle = shuffle;
module.exports.del = del;
module.exports.delete_all = delete_all;
module.exports.vote = vote;
module.exports.addPlaylist = addPlaylist;
module.exports.addFromOtherList = addFromOtherList;
module.exports.add_function = add_function;
module.exports.voteUndecided = voteUndecided;
module.exports.shuffle = shuffle;
module.exports.del = del;
module.exports.delete_all = delete_all;
module.exports.vote = vote;

View File

@@ -30,7 +30,7 @@ function getColor(id) {
id: id
}),
success: function(c) {
c = JSON.parse(c);
//c = JSON.parse(c);
if(typeof(c) == "object") {
Player.setBGimage({color:c, only:true});
}
@@ -201,7 +201,7 @@ function get_list_ajax() {
if(response.results.length > 0) {
if(response.status == 403) {
start_auth();
}
} else if(response.status == 404) return;
if(client) {
Helper.removeElement("#channel-load");
}
@@ -209,14 +209,14 @@ function get_list_ajax() {
}
},
error: function(response) {
response = JSON.parse(response);
//response = JSON.parse(response);
if(response.status == 403) {
start_auth();
} else if(response.status == 429) {
setTimeout(function() {
get_list_ajax();
}, xmlhttp.getResponseHeader("Retry-After") * 1000)
}
} else if(response.status == 404) return;
if(client) {
Helper.removeElement("#channel-load");
}
@@ -289,7 +289,7 @@ function get_np_ajax() {
Player.getTitle(response.results[0].title, 1);
},
error: function(response, xmlhttp) {
response = JSON.parse(response);
//response = JSON.parse(response);
if(response.status == 403) {
start_auth();
} else if(response.status == 429) {
@@ -320,7 +320,7 @@ function del_ajax(id) {
get_list_ajax();
},
error: function(response, xmlhttp) {
response = JSON.parse(response);
//response = JSON.parse(response);
if(response.status == 403) {
toast("listhaspass");
} else if(response.status == 429) {
@@ -357,7 +357,7 @@ function add_ajax(id, title, duration, playlist, num, full_num, start, end, sour
get_list_ajax();
},
error: function(response, xmlhttp) {
response = JSON.parse(response);
//response = JSON.parse(response);
if(response.status == 403) {
toast("listhaspass");
} else if(response.status == 409) {
@@ -390,7 +390,7 @@ function vote_ajax(id) {
get_list_ajax();
},
error: function(response, xmlhttp) {
response = JSON.parse(response);
//response = JSON.parse(response);
if(response.status == 403) {
toast("listhaspass");
} else if(response.status == 429) {
@@ -1070,7 +1070,7 @@ function before_toast(){
} catch(e) {
}
//}*/
//M.Toast.dismissAll();
M.Toast.dismissAll();
//Materialize.Toast.removeAll();
}

View File

@@ -1308,10 +1308,14 @@ window.addEventListener("resize", function(){
} else if(window.innerWidth < 601) {
if(!client && !embed) {
var scPlaying = false;
var ytPlaying = false;
try {
ytPlaying = Player.player.getPlayerState() == YT.PlayerState.PLAYING || Player.player.getPlayerState() == YT.PlayerState.BUFFERING;
} catch(e) {}
try {
scPlaying = Player.soundcloud_player.isPlaying();
} catch(e){}
resizePlaylistPlaying(Player.player.getPlayerState() == YT.PlayerState.PLAYING || scPlaying || Player.player.getPlayerState() == YT.PlayerState.BUFFERING);
resizePlaylistPlaying(ytPlaying || scPlaying);
return;
}
}

View File

@@ -481,6 +481,7 @@ var Player = {
},
playNext: function(){
if(full_playlist.length == 0) return;
var next_song = full_playlist[0];
video_id = next_song.id;
@@ -517,7 +518,7 @@ var Player = {
var length = full_playlist.length - 2;
if(length < 0) {
length = 0;
}
} else if(length == 0) return;
var next_song = full_playlist[length];
video_id = next_song.id;
time = (new Date()).getTime();