mirror of
https://github.com/KevinMidboe/zoff.git
synced 2025-10-29 18:00:23 +00:00
Changed functionality for adding playlists
dquote> - Sending event for addPlaylist, and sending the whole list instead of one-by one
This commit is contained in:
@@ -35,6 +35,19 @@
|
||||
pass: Base64(channel_pass)
|
||||
}
|
||||
|
||||
'addPlaylist', {
|
||||
channel: CHANNEL_NAME,
|
||||
userpass: Base64(CHANNEL_PASSWORD),
|
||||
adminpass: Base64(PASSWORD),
|
||||
songs: [
|
||||
{
|
||||
id: song_id,
|
||||
title: song_title,
|
||||
duration: song_duration
|
||||
}, ... { ... }
|
||||
]
|
||||
}
|
||||
|
||||
// Imports songs from another zoff-channel
|
||||
'import_zoff', {
|
||||
channel: CHANNELNAME,
|
||||
|
||||
@@ -285,6 +285,10 @@ module.exports = function() {
|
||||
List.end(obj, coll, guid, offline, socket);
|
||||
});
|
||||
|
||||
socket.on('addPlaylist', function(arr) {
|
||||
ListChange.addPlaylist(arr, guid, offline, socket);
|
||||
})
|
||||
|
||||
socket.on('add', function(arr)
|
||||
{
|
||||
if(coll !== undefined) {
|
||||
|
||||
@@ -59,52 +59,58 @@ function addFromOtherList(arr, guid, offline, socket) {
|
||||
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) {
|
||||
var hash = Functions.hash_pass(Functions.hash_pass(Functions.decrypt_string(socketid, arr.adminpass), true));
|
||||
if((this_conf[0].userpass == "" || !this_conf[0].userpass || this_conf[0].userpass == crypto.createHash('sha256').update(Functions.decrypt_string(socketid, arr.userpass)).digest("base64")) &&
|
||||
((this_conf[0].addsongs === true && (hash == this_conf[0].adminpass || this_conf[0].adminpass === "")) ||
|
||||
this_conf[0].addsongs === false)) {
|
||||
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) {
|
||||
if(to_set_np) {
|
||||
var to_change = {
|
||||
_id: channel,
|
||||
count: docs.length,
|
||||
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").update({_id: channel}, {$set: to_change}, function(e, d) {
|
||||
List.send_list(channel, undefined, false, true, false);
|
||||
List.send_play(channel, undefined);
|
||||
socket.emit("toast", "addedplaylist");
|
||||
_db.close();
|
||||
});
|
||||
if((this_conf[0].userpass == "" || !this_conf[0].userpass || this_conf[0].userpass == crypto.createHash('sha256').update(Functions.decrypt_string(socketid, arr.userpass)).digest("base64"))) {
|
||||
if(((this_conf[0].addsongs === true && (hash == this_conf[0].adminpass || this_conf[0].adminpass === "")) ||
|
||||
this_conf[0].addsongs === false)) {
|
||||
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) {
|
||||
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,
|
||||
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").update({_id: channel}, {$set: to_change}, function(e, d) {
|
||||
List.send_list(channel, undefined, false, true, false);
|
||||
List.send_play(channel, undefined);
|
||||
socket.emit("toast", "addedplaylist");
|
||||
_db.close();
|
||||
});
|
||||
});
|
||||
} else {
|
||||
db.collection("frontpage_lists").update({_id: channel}, {$inc: {count: res.nInserted != undefined ? res.nInserted : res.insertedCount}}, function(e, d) {
|
||||
List.send_list(channel, undefined, false, true, false);
|
||||
List.send_play(channel, undefined);
|
||||
socket.emit("toast", "addedplaylist");
|
||||
_db.close();
|
||||
})
|
||||
}
|
||||
});
|
||||
} else {
|
||||
db.collection("frontpage_lists").update({_id: channel}, {$inc: {count: res.nInserted != undefined ? res.nInserted : res.insertedCount}}, function(e, d) {
|
||||
List.send_list(channel, undefined, false, true, false);
|
||||
List.send_play(channel, undefined);
|
||||
socket.emit("toast", "addedplaylist");
|
||||
_db.close();
|
||||
})
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
})
|
||||
} else {
|
||||
socket.emit("toast", "listhaspass");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
socket.emit("auth_required");
|
||||
return;
|
||||
@@ -122,11 +128,11 @@ function addFromOtherList(arr, guid, offline, socket) {
|
||||
}
|
||||
}
|
||||
|
||||
function addPlaylist(arr, guid, socket) {
|
||||
function addPlaylist(arr, guid, offline, socket) {
|
||||
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") {
|
||||
if(!arr.hasOwnProperty("channel") || !arr.hasOwnProperty("songs")
|
||||
|| typeof(arr.channel) != "string" || typeof(arr.songs) != "object") {
|
||||
var result = {
|
||||
channel: {
|
||||
expected: "string",
|
||||
@@ -160,39 +166,75 @@ function addPlaylist(arr, guid, socket) {
|
||||
db.collection(channel + "_settings").find({id: "config"}, function(e, conf) {
|
||||
if(conf.length > 0) {
|
||||
var hash = Functions.hash_pass(Functions.hash_pass(Functions.decrypt_string(socketid, arr.adminpass), true));
|
||||
if((conf[0].userpass == "" || !conf[0].userpass || conf[0].userpass == crypto.createHash('sha256').update(Functions.decrypt_string(socketid, arr.userpass)).digest("base64")) &&
|
||||
((conf[0].addsongs === true && (hash == conf[0].adminpass || conf[0].adminpass === "")) ||
|
||||
conf[0].addsongs === false)) {
|
||||
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);
|
||||
var number_elements = arr.songs.length + 1;
|
||||
var time = Functions.get_time() - number_elements;
|
||||
var bulk = dbo.collection(channel).initializeUnorderedBulkOp({useLegacyOps: true});
|
||||
for(var i = 0; i < arr.songs.length; i++) {
|
||||
var this_element = arr.songs[i];
|
||||
this_element.added = time;
|
||||
this_element.now_playing = now_playing;
|
||||
this_element.votes = 0;
|
||||
this_element.guids = [];
|
||||
this_element.start = parseInt(this_element.start);
|
||||
this_element.end = parseInt(this_element.end);
|
||||
this_element.duration = parseInt(this_element.duration);
|
||||
if(this_element.start > this_element.end) {
|
||||
this_element.start = 0;
|
||||
if((conf[0].userpass == "" || !conf[0].userpass || conf[0].userpass == crypto.createHash('sha256').update(Functions.decrypt_string(socketid, arr.userpass)).digest("base64"))) {
|
||||
if(((conf[0].addsongs === true && (hash == conf[0].adminpass || conf[0].adminpass === "")) ||
|
||||
conf[0].addsongs === false)) {
|
||||
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);
|
||||
var number_elements = arr.songs.length + 1;
|
||||
var time = Functions.get_time() - number_elements;
|
||||
var to_set_np = now_playing;
|
||||
var bulk = dbo.collection(channel).initializeUnorderedBulkOp({useLegacyOps: true});
|
||||
for(var i = 0; i < arr.songs.length; i++) {
|
||||
var this_element = arr.songs[i];
|
||||
if(!this_element.hasOwnProperty("duration") || !this_element.hasOwnProperty("id") || !this_element.hasOwnProperty("title")) {
|
||||
continue;
|
||||
}
|
||||
this_element.added = time;
|
||||
this_element.now_playing = now_playing;
|
||||
this_element.votes = 0;
|
||||
this_element.guids = [];
|
||||
if(!this_element.hasOwnProperty("start")) this_element.start = 0;
|
||||
if(!this_element.hasOwnProperty("end")) this_element.end = this_element.duration;
|
||||
this_element.start = parseInt(this_element.start);
|
||||
this_element.end = parseInt(this_element.end);
|
||||
this_element.duration = parseInt(this_element.duration);
|
||||
if(this_element.start > this_element.end) {
|
||||
this_element.start = 0;
|
||||
}
|
||||
if(now_playing) {
|
||||
now_playing = false;
|
||||
}
|
||||
bulk.insert(this_element);
|
||||
}
|
||||
if(now_playing) {
|
||||
now_playing = false;
|
||||
}
|
||||
bulk.insert(this_element);
|
||||
}
|
||||
bulk.execute(function(err, results) {
|
||||
console.log(err, results);
|
||||
bulk.execute(function(err, results) {
|
||||
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,
|
||||
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").update({_id: channel}, {$set: to_change}, function(e, d) {
|
||||
List.send_list(channel, undefined, false, true, false);
|
||||
List.send_play(channel, undefined);
|
||||
socket.emit("toast", "addedplaylist");
|
||||
_db.close();
|
||||
});
|
||||
});
|
||||
} else {
|
||||
db.collection("frontpage_lists").update({_id: channel}, {$inc: {count: results.nInserted != undefined ? results.nInserted : results.insertedCount}}, function(e, d) {
|
||||
List.send_list(channel, undefined, false, true, false);
|
||||
List.send_play(channel, undefined);
|
||||
socket.emit("toast", "addedplaylist");
|
||||
_db.close();
|
||||
})
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
} else {
|
||||
socket.emit("toast", "listhaspass");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
socket.emit("auth_required");
|
||||
return;
|
||||
@@ -731,6 +773,7 @@ function vote(coll, id, guid, socket, full_list, last) {
|
||||
});
|
||||
}
|
||||
|
||||
module.exports.addPlaylist = addPlaylist;
|
||||
module.exports.addFromOtherList = addFromOtherList;
|
||||
module.exports.add_function = add_function;
|
||||
module.exports.voteUndecided = voteUndecided;
|
||||
|
||||
@@ -689,6 +689,8 @@ function toast(msg) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
document.getElementById("import_spotify").disabled = false;
|
||||
document.getElementById("import").disabled = false;
|
||||
tried_again = false;
|
||||
msg=Helper.rnd(["I'm sorry, but you have to be an admin to do that!", "Only admins can do that", "You're not allowed to do that, try logging in!", "I can't let you do that", "Please log in to do that"]);
|
||||
//Crypt.remove_pass(chan.toLowerCase());
|
||||
|
||||
@@ -282,9 +282,10 @@ var Search = {
|
||||
Search.submitArrayExpected -= 1;
|
||||
}
|
||||
if((Search.submitArray.length - 1) == Search.submitArrayExpected) {
|
||||
$.each(Search.submitArray, function(i, data){
|
||||
socket.emit("addPlaylist", {channel: chan.toLowerCase(), songs: Search.submitArray});
|
||||
/*$.each(Search.submitArray, function(i, data){
|
||||
Search.submit(data.id, data.title, data.duration, true, i, Search.submitArray.length - 1, 0, data.duration);
|
||||
});
|
||||
});*/
|
||||
document.getElementById("import_spotify").disabled = false;
|
||||
$("#import_spotify").removeClass("hide");
|
||||
$("#playlist_loader_spotify").addClass("hide");
|
||||
@@ -424,13 +425,15 @@ var Search = {
|
||||
enc_title= song.snippet.title;//encodeURIComponent(song.snippet.title);
|
||||
//Search.submit(song.id, enc_title, duration, playlist, i);
|
||||
x += 1;
|
||||
to_add.push({id: song.id, enc_title: enc_title, duration: duration, playlist: playlist});
|
||||
to_add.push({id: song.id, title: enc_title, duration: duration, playlist: playlist});
|
||||
}
|
||||
});
|
||||
socket.emit("addPlaylist", {channel: chan.toLowerCase(), songs: to_add});
|
||||
/*
|
||||
$.each(to_add, function(i, item){
|
||||
Search.submit(item.id, item.enc_title, item.duration, item.playlist, i, x, 0, item.duration);
|
||||
});
|
||||
|
||||
*/
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user