Added functionality to add songs from another channel

This commit is contained in:
Kasper Rynning-Tønnesen
2018-03-21 15:01:14 +01:00
parent 8d14b14c65
commit 859062204c
13 changed files with 230 additions and 34 deletions

View File

@@ -14,7 +14,9 @@ function get_history(channel, all, socket) {
var pass = "";
if(!query.all) {
Functions.getSessionAdminUser(Functions.getSession(socket), channel, function(userpass) {
pass = userpass;
if(userpass != "" || pass == undefined) {
pass = userpass;
}
db.collection(channel + "_settings").find({id: "config"}, function(err, conf) {
if(conf.length > 0) {
if(conf[0].userpass == "" || conf[0].userpass == crypto.createHash('sha256').update(Functions.decrypt_string(socket.zoff_id, pass)).digest('base64')) {
@@ -66,7 +68,9 @@ function chat(msg, guid, offline, socket) {
}
var coll = msg.channel.toLowerCase().replace(/ /g,'');
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass) {
msg.pass = userpass;
if(userpass != "" || msg.pass == undefined) {
msg.pass = userpass;
}
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 == crypto.createHash('sha256').update(Functions.decrypt_string(socket.zoff_id, msg.pass)).digest("base64")))) {
var data = msg.data;

View File

@@ -227,7 +227,6 @@ function setSessionUserPass(id, userpass, list, callback) {
callback();
return;
}
connected_db.collection(id).update({_id: list}, {$set: {userpass: userpass}}, {upsert: true}, function(e, d){
callback();
return;

View File

@@ -233,6 +233,10 @@ module.exports = function() {
Frontpage.frontpage_lists(msg, socket);
});
socket.on('import_zoff', function(msg) {
ListChange.addFromOtherList(msg, guid, socket);
})
socket.on('now_playing', function(list, fn)
{
List.now_playing(list, fn, socket);
@@ -448,7 +452,9 @@ module.exports = function() {
db.collection(coll + "_settings").find(function(err, docs) {
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass) {
obj.pass = userpass;
if(userpass != "" || obj.pass == undefined) {
obj.pass = userpass;
}
if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (obj.hasOwnProperty('pass') && docs[0].userpass == crypto.createHash('sha256').update(Functions.decrypt_string(socketid, obj.pass)).digest("base64")))) {
Functions.check_inlist(coll, guid, socket, offline);
List.send_play(coll, socket);

View File

@@ -78,12 +78,14 @@ function list(msg, guid, coll, offline, socket) {
});
} else {
db.createCollection(coll, function(err, docs){
var configs = {"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: "", id: "config"};
db.collection(coll + "_settings").insert(configs, function(err, docs){
socket.join(coll);
List.send_list(coll, socket, true, false, true);
db.collection("frontpage_lists").insert({"_id": coll, "count" : 0, "frontpage": true, "accessed": Functions.get_time(), "viewers": 1});
Functions.check_inlist(coll, guid, socket, offline);
db.collection(coll).createIndex({ id: 1}, {unique: true}, function(e, d) {
var configs = {"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: "", id: "config"};
db.collection(coll + "_settings").insert(configs, function(err, docs){
socket.join(coll);
List.send_list(coll, socket, true, false, true);
db.collection("frontpage_lists").insert({"_id": coll, "count" : 0, "frontpage": true, "accessed": Functions.get_time(), "viewers": 1});
Functions.check_inlist(coll, guid, socket, offline);
});
});
});
}
@@ -142,8 +144,12 @@ function skip(list, guid, coll, offline, socket) {
return;
}
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass) {
list.pass = adminpass;
list.userpass = userpass;
if(adminpass != "" || list.pass == undefined) {
list.pass = adminpass;
}
if(userpass != "" || list.userpass == undefined) {
list.userpass = userpass;
}
db.collection(coll + "_settings").find(function(err, docs){
if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (list.hasOwnProperty('userpass') && docs[0].userpass == crypto.createHash('sha256').update(Functions.decrypt_string(socketid, list.userpass)).digest("base64")))) {
@@ -539,7 +545,9 @@ function end(obj, coll, guid, offline, socket) {
}
coll = coll.replace(/ /g,'');
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass) {
obj.pass = userpass;
if(userpass != "" || obj.pass == undefined) {
obj.pass = userpass;
}
db.collection(coll + "_settings").find(function(err, docs){
if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (obj.hasOwnProperty('pass') && docs[0].userpass == crypto.createHash('sha256').update(Functions.decrypt_string(socketid, obj.pass)).digest("base64")))) {

View File

@@ -1,3 +1,97 @@
function addFromOtherList(arr, guid, socket) {
var MongoClient = require('mongodb').MongoClient;
var socketid = socket.zoff_id;
if(typeof(arr) == "object") {
if(!arr.hasOwnProperty("channel") || !arr.hasOwnProperty("new_channel")
|| typeof(arr.channel) != "string" || typeof(arr.new_channel) != "string") {
var result = {
channel: {
expected: "string",
got: arr.hasOwnProperty("channel") ? typeof(arr.channel) : undefined
},
new_channel: {
expected: "string",
got: arr.hasOwnProperty("new_channel") ? typeof(arr.new_channel) : undefined
}
};
socket.emit('update_required', result);
return;
}
var channel = arr.channel.replace(/ /g,'').toLowerCase();
var new_channel = arr.new_channel.replace(/ /g, '').toLowerCase();
db.collection("frontpage_lists").find({_id: new_channel}, function(err, fp) {
if(fp.length == 0) {
socket.emit("toast", "nolist");
return;
}
Functions.getSessionAdminUser(Functions.getSession(socket), channel, function(userpass) {
if(userpass != "" || arr.userpass == undefined) {
arr.userpass = userpass;
}
Functions.getSessionAdminUser(Functions.getSession(socket), new_channel, function(userpass) {
var otheruser = "";
if(userpass != "") {
otheruser = userpass;
}
db.collection(channel).find({now_playing: true}, function(e, np) {
var project_object = {
"id": 1,
"added": 1,
"guids": { "$literal": [] },
"now_playing": 1,
"title": 1,
"votes": { "$literal": 0 },
"start": 1,
"duration": 1,
"end": 1,
"type": 1
};
if(np.length > 0) project_object.now_playing = { "$literal": 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(socketid, otheruser)).digest("base64"))) {
db.collection(channel + "_settings").find({id: "config"}, function(e, this_conf) {
if(this_conf.userpass == "" || !this_conf.userpass || this_conf.userpass == crypto.createHash('sha256').update(Functions.decrypt_string(socketid, arr.userpass)).digest("base64")) {
db.collection(new_channel).aggregate([
{
"$match": { type: "video" }
},
{
"$project": project_object
}
], function(e, docs) {
var path = require('path');
var mongo_config = require(path.join(path.join(__dirname, '../config/'), 'mongo_config.js'));
var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://" + mongo_config.host + ":" + mongo_config.port + "/";
MongoClient.connect(url, function(err, _db) {
var dbo = _db.db(mongo_config.config);
dbo.collection(channel).insertMany(docs, {ordered: false}, function(err, res) {
List.send_list(channel, undefined, false, true, false);
List.send_play(channel, undefined);
socket.emit("toast", "addedplaylist");
_db.close();
});
});
})
} else {
socket.emit("auth_required");
return;
}
})
} else {
socket.emit("toast", "other_list_pass");
return;
}
})
});
});
});
});
}
}
function add_function(arr, coll, guid, offline, socket) {
var socketid = socket.zoff_id;
if(typeof(arr) === 'object' && arr !== undefined && arr !== null && arr !== "" && !isNaN(parseInt(arr.duration)))
@@ -91,8 +185,12 @@ function add_function(arr, coll, guid, offline, socket) {
}
coll = coll.replace(/ /g,'');
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass) {
arr.adminpass = adminpass;
arr.userpass = userpass;
if(adminpass != "" || arr.adminpass == undefined) {
arr.adminpass = adminpass;
}
if(userpass != "" || arr.userpass == undefined) {
arr.userpass = userpass;
}
db.collection(coll + "_settings").find(function(err, docs){
if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (arr.hasOwnProperty('pass') && docs[0].userpass == crypto.createHash('sha256').update(Functions.decrypt_string(socketid, arr.pass)).digest("base64")))) {
@@ -280,8 +378,12 @@ function voteUndecided(msg, coll, guid, offline, socket) {
}
coll = msg.channel.toLowerCase().replace(/ /g,'');
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass) {
msg.adminpass = adminpass;
msg.pass = userpass;
if(adminpass != "" || msg.adminpass == undefined) {
msg.adminpass = adminpass;
}
if(userpass != "" || msg.pass == undefined) {
msg.pass = userpass;
}
db.collection(coll + "_settings").find({id: "config"}, function(err, docs){
if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == crypto.createHash('sha256').update(Functions.decrypt_string(socketid, msg.pass)).digest("base64")))) {
@@ -341,8 +443,12 @@ function shuffle(msg, coll, guid, offline, socket) {
coll = msg.channel.toLowerCase().replace(/ /g,'');
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass) {
msg.adminpass = adminpass;
msg.pass = userpass;
if(adminpass != "" || msg.adminpass == undefined) {
msg.adminpass = adminpass;
}
if(userpass != "" || msg.pass == undefined) {
msg.pass = userpass;
}
db.collection("timeout_api").find({
type: "shuffle",
guid: coll,
@@ -454,8 +560,12 @@ function delete_all(msg, coll, guid, offline, socket) {
}
coll = coll.replace(/ /g,'');
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass, gotten) {
msg.adminpass = adminpass;
msg.pass = userpass;
if(adminpass != "" || msg.adminpass == undefined) {
msg.adminpass = adminpass;
}
if(userpass != "" || msg.pass == undefined) {
msg.pass = userpass;
}
var hash = Functions.hash_pass(Functions.hash_pass(Functions.decrypt_string(socketid, msg.adminpass),true));
var hash_userpass = crypto.createHash('sha256').update(Functions.decrypt_string(socketid, msg.pass)).digest("base64");
db.collection(coll + "_settings").find(function(err, conf) {
@@ -505,6 +615,7 @@ function vote(coll, id, guid, socket, full_list, last) {
});
}
module.exports.addFromOtherList = addFromOtherList;
module.exports.add_function = add_function;
module.exports.voteUndecided = voteUndecided;
module.exports.shuffle = shuffle;

View File

@@ -25,8 +25,12 @@ function thumbnail(msg, coll, guid, offline, socket) {
}
coll = coll.replace(/ /g,'');
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass) {
msg.userpass = userpass;
msg.adminpass = adminpass;
if(userpass != "" || msg.userpass == undefined) {
msg.userpass = userpass;
}
if(adminpass != "" || msg.adminpass == undefined) {
msg.adminpass = adminpass;
}
msg.thumbnail = msg.thumbnail.replace(/^https?\:\/\//i, "");
if(msg.thumbnail.substring(0,2) != "//") msg.thumbnail = "//" + msg.thumbnail;
@@ -76,8 +80,12 @@ function description(msg, coll, guid, offline, socket) {
}
coll = coll.replace(/ /g,'');
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass, gotten) {
msg.userpass = userpass;
msg.adminpass = adminpass;
if(userpass != "" || msg.userpass == undefined) {
msg.userpass = userpass;
}
if(adminpass != "" || msg.adminpass == undefined) {
msg.adminpass = adminpass;
}
var channel = msg.channel.toLowerCase();
var hash = Functions.hash_pass(Functions.decrypt_string(socket.zoff_id, msg.adminpass));
db.collection(channel + "_settings").find({id: "config"}, function(err, docs){