mirror of
https://github.com/KevinMidboe/zoff.git
synced 2025-12-08 20:48:48 +00:00
Added function for timing out playlist adds when not logged in
This commit is contained in:
@@ -434,6 +434,46 @@ function left_channel(coll, guid, short_id, in_list, socket, change, caller) {
|
|||||||
remove_unique_id(short_id);
|
remove_unique_id(short_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function checkTimeout(type, timeout, channel, guid, conf_pass, this_pass, socket, callback, error_message){
|
||||||
|
if(conf_pass != "" && conf_pass == this_pass) {
|
||||||
|
callback();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
db.collection("timeout_api").find({
|
||||||
|
type: type,
|
||||||
|
guid: guid,
|
||||||
|
}, function(err, docs) {
|
||||||
|
if(docs.length > 0) {
|
||||||
|
var date = new Date(docs[0].createdAt);
|
||||||
|
date.setSeconds(date.getSeconds() + timeout);
|
||||||
|
var now = new Date();
|
||||||
|
|
||||||
|
var retry_in = (date.getTime() - now.getTime()) / 1000;
|
||||||
|
if(retry_in > 0) {
|
||||||
|
if(error_message) {
|
||||||
|
socket.emit("toast", error_message + Math.ceil(retry_in) + " seconds.");
|
||||||
|
} else {
|
||||||
|
socket.emit("toast", "wait_longer");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var now_date = new Date();
|
||||||
|
db.collection("timeout_api").update({type: type, guid: guid}, {
|
||||||
|
$set: {
|
||||||
|
"createdAt": now_date,
|
||||||
|
type: type,
|
||||||
|
guid: guid,
|
||||||
|
},
|
||||||
|
}, {upsert: true}, function(err, docs) {
|
||||||
|
callback();
|
||||||
|
return;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.checkTimeout = checkTimeout;
|
||||||
module.exports.left_channel = left_channel;
|
module.exports.left_channel = left_channel;
|
||||||
module.exports.setChromecastHost = setChromecastHost;
|
module.exports.setChromecastHost = setChromecastHost;
|
||||||
module.exports.decodeChannelName = decodeChannelName;
|
module.exports.decodeChannelName = decodeChannelName;
|
||||||
|
|||||||
@@ -33,11 +33,10 @@ function addFromOtherList(arr, guid, offline, socket) {
|
|||||||
var channel = arr.channel;//.replace(/ /g,'').toLowerCase();
|
var channel = arr.channel;//.replace(/ /g,'').toLowerCase();
|
||||||
var new_channel = Functions.encodeChannelName(arr.new_channel);//.replace(/ /g, '').toLowerCase();
|
var new_channel = Functions.encodeChannelName(arr.new_channel);//.replace(/ /g, '').toLowerCase();
|
||||||
db.collection("frontpage_lists").find({_id: new_channel}, function(err, fp) {
|
db.collection("frontpage_lists").find({_id: new_channel}, function(err, fp) {
|
||||||
if(fp.length == 0) {
|
if(fp.length == 0 || channel == new_channel) {
|
||||||
socket.emit("toast", "nolist");
|
socket.emit("toast", "nolist");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Functions.getSessionAdminUser(Functions.getSession(socket), channel, function(userpass, adminpass) {
|
Functions.getSessionAdminUser(Functions.getSession(socket), channel, function(userpass, adminpass) {
|
||||||
if(userpass != "" || arr.userpass == undefined) {
|
if(userpass != "" || arr.userpass == undefined) {
|
||||||
arr.userpass = userpass;
|
arr.userpass = userpass;
|
||||||
@@ -83,6 +82,7 @@ function addFromOtherList(arr, guid, offline, socket) {
|
|||||||
db.collection(channel + "_settings").find({id: "config"}, function(e, this_conf) {
|
db.collection(channel + "_settings").find({id: "config"}, function(e, this_conf) {
|
||||||
var hash = arr.adminpass;
|
var hash = arr.adminpass;
|
||||||
if((this_conf[0].userpass == "" || !this_conf[0].userpass || this_conf[0].userpass == arr.userpass)) {
|
if((this_conf[0].userpass == "" || !this_conf[0].userpass || this_conf[0].userpass == arr.userpass)) {
|
||||||
|
Functions.checkTimeout("add_playlist", 60, channel, guid, this_conf[0].adminpass, hash, socket, function() {
|
||||||
if(((this_conf[0].addsongs === true && (hash == this_conf[0].adminpass || this_conf[0].adminpass === "")) ||
|
if(((this_conf[0].addsongs === true && (hash == this_conf[0].adminpass || this_conf[0].adminpass === "")) ||
|
||||||
this_conf[0].addsongs === false)) {
|
this_conf[0].addsongs === false)) {
|
||||||
db.collection(new_channel).aggregate([
|
db.collection(new_channel).aggregate([
|
||||||
@@ -142,11 +142,12 @@ function addFromOtherList(arr, guid, offline, socket) {
|
|||||||
socket.emit("toast", "listhaspass");
|
socket.emit("toast", "listhaspass");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}, "Log in to do that, or please wait ");
|
||||||
} else {
|
} else {
|
||||||
socket.emit("auth_required");
|
socket.emit("auth_required");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
} else {
|
} else {
|
||||||
socket.emit("toast", "other_list_pass");
|
socket.emit("toast", "other_list_pass");
|
||||||
return;
|
return;
|
||||||
@@ -208,6 +209,7 @@ function addPlaylist(arr, guid, offline, socket) {
|
|||||||
if((conf[0].userpass == "" || !conf[0].userpass || conf[0].userpass == arr.userpass)) {
|
if((conf[0].userpass == "" || !conf[0].userpass || conf[0].userpass == arr.userpass)) {
|
||||||
if(((conf[0].addsongs === true && (hash == conf[0].adminpass || conf[0].adminpass === "")) ||
|
if(((conf[0].addsongs === true && (hash == conf[0].adminpass || conf[0].adminpass === "")) ||
|
||||||
conf[0].addsongs === false)) {
|
conf[0].addsongs === false)) {
|
||||||
|
Functions.checkTimeout("add_playlist", 60, channel, guid, conf[0].adminpass, hash, socket, function() {
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var mongo_config = require(path.join(path.join(__dirname, '../config/'), 'mongo_config.js'));
|
var mongo_config = require(path.join(path.join(__dirname, '../config/'), 'mongo_config.js'));
|
||||||
var MongoClient = require('mongodb').MongoClient;
|
var MongoClient = require('mongodb').MongoClient;
|
||||||
@@ -287,6 +289,7 @@ function addPlaylist(arr, guid, offline, socket) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
}, "Log in to do that, or please wait ");
|
||||||
} else {
|
} else {
|
||||||
socket.emit("toast", "listhaspass");
|
socket.emit("toast", "listhaspass");
|
||||||
return;
|
return;
|
||||||
@@ -310,7 +313,6 @@ function add_function(arr, coll, guid, offline, socket) {
|
|||||||
var socketid = socket.zoff_id;
|
var socketid = socket.zoff_id;
|
||||||
if(typeof(arr) === 'object' && arr !== undefined && arr !== null && arr !== "" && !isNaN(parseInt(arr.duration)))
|
if(typeof(arr) === 'object' && arr !== undefined && arr !== null && arr !== "" && !isNaN(parseInt(arr.duration)))
|
||||||
{
|
{
|
||||||
|
|
||||||
if(coll == "" || coll == undefined || coll == null ||
|
if(coll == "" || coll == undefined || coll == null ||
|
||||||
!arr.hasOwnProperty("start") || !arr.hasOwnProperty("end")) {
|
!arr.hasOwnProperty("start") || !arr.hasOwnProperty("end")) {
|
||||||
var result = {
|
var result = {
|
||||||
@@ -393,7 +395,7 @@ function add_function(arr, coll, guid, offline, socket) {
|
|||||||
socket.emit('update_required', result);
|
socket.emit('update_required', result);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//coll = coll.replace(/ /g,'');
|
|
||||||
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass) {
|
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass) {
|
||||||
if(adminpass != "" || arr.adminpass == undefined) {
|
if(adminpass != "" || arr.adminpass == undefined) {
|
||||||
arr.adminpass = Functions.hash_pass(adminpass);
|
arr.adminpass = Functions.hash_pass(adminpass);
|
||||||
@@ -414,8 +416,6 @@ function add_function(arr, coll, guid, offline, socket) {
|
|||||||
var hash = arr.adminpass;
|
var hash = arr.adminpass;
|
||||||
var duration = parseInt(arr.duration);
|
var duration = parseInt(arr.duration);
|
||||||
var source = arr.source;
|
var source = arr.source;
|
||||||
/*db.collection(coll + "_settings").find(function(err, docs)
|
|
||||||
{*/
|
|
||||||
conf = docs;
|
conf = docs;
|
||||||
if(docs !== null && docs.length !== 0 && ((docs[0].addsongs === true && (hash == docs[0].adminpass || docs[0].adminpass === "")) ||
|
if(docs !== null && docs.length !== 0 && ((docs[0].addsongs === true && (hash == docs[0].adminpass || docs[0].adminpass === "")) ||
|
||||||
docs[0].addsongs === false)) {
|
docs[0].addsongs === false)) {
|
||||||
@@ -482,8 +482,7 @@ function add_function(arr, coll, guid, offline, socket) {
|
|||||||
} else {
|
} else {
|
||||||
suggestedAdd.source = "youtube";
|
suggestedAdd.source = "youtube";
|
||||||
}
|
}
|
||||||
db.collection(coll).update({id: id}, {$set: suggestedAdd},
|
db.collection(coll).update({id: id}, {$set: suggestedAdd}, {upsert:true}, function(err, docs){
|
||||||
{upsert:true}, function(err, docs){
|
|
||||||
socket.emit("toast", "suggested");
|
socket.emit("toast", "suggested");
|
||||||
var toSend = {id: id, title: title, duration: duration, source: suggestedAdd.source};
|
var toSend = {id: id, title: title, duration: duration, source: suggestedAdd.source};
|
||||||
if(source == "soundcloud") toSend.thumbnail = arr.thumbnail;
|
if(source == "soundcloud") toSend.thumbnail = arr.thumbnail;
|
||||||
@@ -497,7 +496,6 @@ function add_function(arr, coll, guid, offline, socket) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
//});
|
|
||||||
} else {
|
} else {
|
||||||
socket.emit("auth_required");
|
socket.emit("auth_required");
|
||||||
}
|
}
|
||||||
@@ -516,9 +514,9 @@ function add_function(arr, coll, guid, offline, socket) {
|
|||||||
};
|
};
|
||||||
socket.emit('update_required', result);
|
socket.emit('update_required', result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function voteUndecided(msg, coll, guid, offline, socket) {
|
function voteUndecided(msg, coll, guid, offline, socket) {
|
||||||
var socketid = socket.zoff_id;
|
var socketid = socket.zoff_id;
|
||||||
if(typeof(msg) === 'object' && msg !== undefined && msg !== null){
|
if(typeof(msg) === 'object' && msg !== undefined && msg !== null){
|
||||||
if(msg.hasOwnProperty("id")) msg.id = msg.id + "";
|
if(msg.hasOwnProperty("id")) msg.id = msg.id + "";
|
||||||
@@ -596,9 +594,9 @@ function add_function(arr, coll, guid, offline, socket) {
|
|||||||
};
|
};
|
||||||
socket.emit('update_required', result);
|
socket.emit('update_required', result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function shuffle(msg, coll, guid, offline, socket) {
|
function shuffle(msg, coll, guid, offline, socket) {
|
||||||
var socketid = socket.zoff_id;
|
var socketid = socket.zoff_id;
|
||||||
if(!msg.hasOwnProperty("channel") || typeof(msg.channel) != "string") {
|
if(!msg.hasOwnProperty("channel") || typeof(msg.channel) != "string") {
|
||||||
var result = {
|
var result = {
|
||||||
@@ -634,31 +632,9 @@ function add_function(arr, coll, guid, offline, socket) {
|
|||||||
} else if(msg.hasOwnProperty("pass")) {
|
} else if(msg.hasOwnProperty("pass")) {
|
||||||
msg.pass = crypto.createHash('sha256').update(Functions.decrypt_string(msg.pass)).digest("base64");
|
msg.pass = crypto.createHash('sha256').update(Functions.decrypt_string(msg.pass)).digest("base64");
|
||||||
}
|
}
|
||||||
db.collection("timeout_api").find({
|
Functions.checkTimeout("shuffle", 5, coll, coll, "foo", "bar", socket, function() {
|
||||||
type: "shuffle",
|
|
||||||
guid: coll,
|
|
||||||
}, function(err, docs) {
|
|
||||||
if(docs.length > 0) {
|
|
||||||
var date = new Date(docs[0].createdAt);
|
|
||||||
date.setSeconds(date.getSeconds() + 5);
|
|
||||||
var now = new Date();
|
|
||||||
var retry_in = (date.getTime() - now.getTime()) / 1000;
|
|
||||||
if(retry_in > 0) {
|
|
||||||
socket.emit("toast", "wait_longer");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var now_date = new Date();
|
|
||||||
db.collection("timeout_api").update({type: "shuffle", guid: coll}, {
|
|
||||||
$set: {
|
|
||||||
"createdAt": now_date,
|
|
||||||
type: "shuffle",
|
|
||||||
guid: coll,
|
|
||||||
},
|
|
||||||
}, {upsert: true}, function(err, docs) {
|
|
||||||
Functions.check_inlist(coll, guid, socket, offline, undefined, "place 7");
|
Functions.check_inlist(coll, guid, socket, offline, undefined, "place 7");
|
||||||
var hash = msg.adminpass;
|
var hash = msg.adminpass;
|
||||||
|
|
||||||
db.collection(coll + "_settings").find(function(err, docs){
|
db.collection(coll + "_settings").find(function(err, docs){
|
||||||
if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == msg.pass))) {
|
if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == msg.pass))) {
|
||||||
if(docs !== null && docs.length !== 0 && ((docs[0].adminpass == hash && docs[0].adminpass != "") || docs[0].shuffle === false))
|
if(docs !== null && docs.length !== 0 && ((docs[0].adminpass == hash && docs[0].adminpass != "") || docs[0].shuffle === false))
|
||||||
@@ -689,11 +665,11 @@ function add_function(arr, coll, guid, offline, socket) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function del(params, socket, socketid) {
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function del(params, socket, socketid) {
|
||||||
if(params.id){
|
if(params.id){
|
||||||
var coll = Functions.removeEmojis(params.channel).toLowerCase();
|
var coll = Functions.removeEmojis(params.channel).toLowerCase();
|
||||||
//coll = coll.replace(/_/g, "").replace(/ /g,'');
|
//coll = coll.replace(/_/g, "").replace(/ /g,'');
|
||||||
@@ -719,9 +695,9 @@ function add_function(arr, coll, guid, offline, socket) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function delete_all(msg, coll, guid, offline, socket) {
|
function delete_all(msg, coll, guid, offline, socket) {
|
||||||
var socketid = socket.zoff_id;
|
var socketid = socket.zoff_id;
|
||||||
if(typeof(msg) == 'object' ) {
|
if(typeof(msg) == 'object' ) {
|
||||||
if(!msg.hasOwnProperty('channel') || typeof(msg.channel) != "string") {
|
if(!msg.hasOwnProperty('channel') || typeof(msg.channel) != "string") {
|
||||||
@@ -786,9 +762,9 @@ function add_function(arr, coll, guid, offline, socket) {
|
|||||||
socket.emit('update_required', result);
|
socket.emit('update_required', result);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function vote(coll, id, guid, socket) {
|
function vote(coll, id, guid, socket) {
|
||||||
//coll = coll.replace(/ /g,'');
|
//coll = coll.replace(/ /g,'');
|
||||||
db.collection(coll).find({id:id, now_playing: false, type:"video"}, function(err, docs){
|
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))
|
if(docs !== null && docs.length > 0 && !Functions.contains(docs[0].guids, guid))
|
||||||
@@ -805,13 +781,13 @@ function add_function(arr, coll, guid, offline, socket) {
|
|||||||
socket.emit("toast", "alreadyvoted");
|
socket.emit("toast", "alreadyvoted");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.addPlaylist = addPlaylist;
|
module.exports.addPlaylist = addPlaylist;
|
||||||
module.exports.addFromOtherList = addFromOtherList;
|
module.exports.addFromOtherList = addFromOtherList;
|
||||||
module.exports.add_function = add_function;
|
module.exports.add_function = add_function;
|
||||||
module.exports.voteUndecided = voteUndecided;
|
module.exports.voteUndecided = voteUndecided;
|
||||||
module.exports.shuffle = shuffle;
|
module.exports.shuffle = shuffle;
|
||||||
module.exports.del = del;
|
module.exports.del = del;
|
||||||
module.exports.delete_all = delete_all;
|
module.exports.delete_all = delete_all;
|
||||||
module.exports.vote = vote;
|
module.exports.vote = vote;
|
||||||
|
|||||||
Reference in New Issue
Block a user