mirror of
https://github.com/KevinMidboe/zoff.git
synced 2025-10-29 18:00:23 +00:00
Fixes
This commit is contained in:
@@ -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');
|
||||
|
||||
@@ -28,7 +28,7 @@ function addFromOtherList(arr, guid, offline, socket) {
|
||||
}
|
||||
};
|
||||
socket.emit('update_required', result);
|
||||
return;
|
||||
return;
|
||||
}
|
||||
var channel = arr.channel;//.replace(/ /g,'').toLowerCase();
|
||||
var new_channel = Functions.encodeChannelName(arr.new_channel);//.replace(/ /g, '').toLowerCase();
|
||||
@@ -93,38 +93,41 @@ 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 + "_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").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;
|
||||
}
|
||||
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: 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").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();
|
||||
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;
|
||||
}
|
||||
|
||||
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}, {$set: {count: count}}, function(e, d) {
|
||||
List.send_list(channel, undefined, false, true, false);
|
||||
List.send_play(channel, undefined);
|
||||
socket.emit("toast", "addedplaylist");
|
||||
_db.close();
|
||||
})
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -166,7 +169,7 @@ function addPlaylist(arr, guid, offline, socket) {
|
||||
}
|
||||
};
|
||||
socket.emit('update_required', result);
|
||||
return;
|
||||
return;
|
||||
}
|
||||
var channel = arr.channel;//.replace(/ /g,'').toLowerCase();
|
||||
db.collection("frontpage_lists").find({_id: channel}, function(err, fp) {
|
||||
@@ -236,38 +239,40 @@ function addPlaylist(arr, guid, offline, socket) {
|
||||
bulk.insert(this_element);
|
||||
}
|
||||
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").find({_id: channel}, 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;
|
||||
}
|
||||
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: 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: channel}, 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;
|
||||
}
|
||||
|
||||
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();
|
||||
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 {
|
||||
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");
|
||||
_db.close();
|
||||
})
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -296,18 +301,18 @@ function add_function(arr, coll, guid, offline, socket) {
|
||||
{
|
||||
|
||||
if(coll == "" || coll == undefined || coll == null ||
|
||||
!arr.hasOwnProperty("start") || !arr.hasOwnProperty("end")) {
|
||||
var result = {
|
||||
start: {
|
||||
expected: "number or string that can be cast to int",
|
||||
got: arr.hasOwnProperty("start") ? typeof(arr.start) : undefined
|
||||
},
|
||||
end: {
|
||||
expected: "number or string that can be cast to int",
|
||||
got: arr.hasOwnProperty("end") ? typeof(arr.end) : undefined
|
||||
}
|
||||
};
|
||||
socket.emit('update_required', result);
|
||||
!arr.hasOwnProperty("start") || !arr.hasOwnProperty("end")) {
|
||||
var result = {
|
||||
start: {
|
||||
expected: "number or string that can be cast to int",
|
||||
got: arr.hasOwnProperty("start") ? typeof(arr.start) : undefined
|
||||
},
|
||||
end: {
|
||||
expected: "number or string that can be cast to int",
|
||||
got: arr.hasOwnProperty("end") ? typeof(arr.end) : undefined
|
||||
}
|
||||
};
|
||||
socket.emit('update_required', result);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -332,51 +337,51 @@ function add_function(arr, coll, guid, offline, socket) {
|
||||
|
||||
|
||||
if(typeof(arr.id) != "string" || typeof(arr.start) != "number" ||
|
||||
typeof(arr.end) != "number" || typeof(arr.title) != "string" ||
|
||||
typeof(arr.list) != "string" || typeof(arr.duration) != "number" ||
|
||||
typeof(arr.source) != "string" ||
|
||||
(arr.source == "soundcloud" && (!arr.hasOwnProperty("thumbnail") || !Functions.isUrl(arr.thumbnail)))) {
|
||||
var result = {
|
||||
start: {
|
||||
expected: "number or string that can be cast to int",
|
||||
got: arr.hasOwnProperty("start") ? typeof(arr.start) : undefined
|
||||
},
|
||||
end: {
|
||||
expected: "number or string that can be cast to int",
|
||||
got: arr.hasOwnProperty("end") ? typeof(arr.end) : undefined
|
||||
},
|
||||
title: {
|
||||
expected: "string",
|
||||
got: arr.hasOwnProperty("title") ? typeof(arr.title) : undefined
|
||||
},
|
||||
list: {
|
||||
expected: "string",
|
||||
got: arr.hasOwnProperty("list") ? typeof(arr.list) : undefined
|
||||
},
|
||||
duration: {
|
||||
expected: "number or string that can be cast to int",
|
||||
got: arr.hasOwnProperty("duration") ? typeof(arr.duration) : undefined
|
||||
},
|
||||
pass: {
|
||||
expected: "string",
|
||||
got: arr.hasOwnProperty("pass") ? typeof(arr.pass) : undefined
|
||||
},
|
||||
adminpass: {
|
||||
expected: "string",
|
||||
got: arr.hasOwnProperty("adminpass") ? typeof(arr.adminpass) : undefined
|
||||
},
|
||||
source: {
|
||||
expected: "string (youtube or soundcloud)",
|
||||
got: arr.hasOwnProperty("source") ? typeof(arr.source) : undefined
|
||||
},
|
||||
thumbnail: {
|
||||
expected: "url if source == soundcloud",
|
||||
got: arr.hasOwnProperty("thumbnail") ? typeof(arr.thumbnail) : undefined
|
||||
}
|
||||
};
|
||||
socket.emit('update_required', result);
|
||||
return;
|
||||
}
|
||||
typeof(arr.end) != "number" || typeof(arr.title) != "string" ||
|
||||
typeof(arr.list) != "string" || typeof(arr.duration) != "number" ||
|
||||
typeof(arr.source) != "string" ||
|
||||
(arr.source == "soundcloud" && (!arr.hasOwnProperty("thumbnail") || !Functions.isUrl(arr.thumbnail)))) {
|
||||
var result = {
|
||||
start: {
|
||||
expected: "number or string that can be cast to int",
|
||||
got: arr.hasOwnProperty("start") ? typeof(arr.start) : undefined
|
||||
},
|
||||
end: {
|
||||
expected: "number or string that can be cast to int",
|
||||
got: arr.hasOwnProperty("end") ? typeof(arr.end) : undefined
|
||||
},
|
||||
title: {
|
||||
expected: "string",
|
||||
got: arr.hasOwnProperty("title") ? typeof(arr.title) : undefined
|
||||
},
|
||||
list: {
|
||||
expected: "string",
|
||||
got: arr.hasOwnProperty("list") ? typeof(arr.list) : undefined
|
||||
},
|
||||
duration: {
|
||||
expected: "number or string that can be cast to int",
|
||||
got: arr.hasOwnProperty("duration") ? typeof(arr.duration) : undefined
|
||||
},
|
||||
pass: {
|
||||
expected: "string",
|
||||
got: arr.hasOwnProperty("pass") ? typeof(arr.pass) : undefined
|
||||
},
|
||||
adminpass: {
|
||||
expected: "string",
|
||||
got: arr.hasOwnProperty("adminpass") ? typeof(arr.adminpass) : undefined
|
||||
},
|
||||
source: {
|
||||
expected: "string (youtube or soundcloud)",
|
||||
got: arr.hasOwnProperty("source") ? typeof(arr.source) : undefined
|
||||
},
|
||||
thumbnail: {
|
||||
expected: "url if source == soundcloud",
|
||||
got: arr.hasOwnProperty("thumbnail") ? typeof(arr.thumbnail) : undefined
|
||||
}
|
||||
};
|
||||
socket.emit('update_required', result);
|
||||
return;
|
||||
}
|
||||
//coll = coll.replace(/ /g,'');
|
||||
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass) {
|
||||
if(adminpass != "" || arr.adminpass == undefined) {
|
||||
@@ -396,73 +401,73 @@ function add_function(arr, coll, guid, offline, socket) {
|
||||
var source = arr.source;
|
||||
/*db.collection(coll + "_settings").find(function(err, docs)
|
||||
{*/
|
||||
conf = docs;
|
||||
if(docs !== null && docs.length !== 0 && ((docs[0].addsongs === true && (hash == docs[0].adminpass || docs[0].adminpass === "")) ||
|
||||
docs[0].addsongs === false)) {
|
||||
db.collection(coll).find({id:id, type:{$ne:"suggested"}}, function(err, docs){
|
||||
if(docs !== null && docs.length === 0) {
|
||||
var guids = [guid];
|
||||
var added = Functions.get_time();
|
||||
var votes = 1;
|
||||
db.collection(coll).find({now_playing:true}, function(err, docs){
|
||||
if((docs !== null && docs.length === 0)){
|
||||
np = true;
|
||||
} else {
|
||||
np = false;
|
||||
}
|
||||
var new_song = {"added": added,"guids":guids,"id":id,"now_playing":np,"title":title,"votes":votes, "duration":duration, "start": parseInt(start), "end": parseInt(end), "type": "video", "source": source};
|
||||
if(source == "soundcloud") {
|
||||
if(arr.thumbnail.indexOf("https://i1.sndcdn.com") > -1 || arr.thumbnail.indexOf("https://w1.sndcdn.com") > -1) {
|
||||
new_song.thumbnail = arr.thumbnail;
|
||||
} else {
|
||||
new_song.thumbnail = "https://img.youtube.com/vi/404_notfound/mqdefault.jpg";
|
||||
}
|
||||
} else if(source == "youtube") new_song.thumbnail = "https://img.youtube.com/vi/" + new_song.id + "/mqdefault.jpg";
|
||||
db.collection(coll).update({id: id}, new_song, {upsert: true}, function(err, docs){
|
||||
new_song._id = "asd";
|
||||
if(np) {
|
||||
List.send_list(coll, undefined, false, true, false);
|
||||
db.collection(coll + "_settings").update({ id: "config" }, {$set:{startTime: Functions.get_time()}});
|
||||
List.send_play(coll, undefined);
|
||||
var thumbnail = arr.thumbnail != undefined ? arr.thumbnail : undefined;
|
||||
Frontpage.update_frontpage(coll, id, title, thumbnail, arr.source);
|
||||
if(source != "soundcloud") Search.get_correct_info(new_song, coll, false);
|
||||
} else {
|
||||
io.to(coll).emit("channel", {type: "added", value: new_song});
|
||||
if(source != "soundcloud") Search.get_correct_info(new_song, coll, true);
|
||||
}
|
||||
db.collection("frontpage_lists").update({_id:coll}, {$inc:{count:1}, $set:{accessed: Functions.get_time()}}, {upsert:true}, function(err, docs){});
|
||||
List.getNextSong(coll, undefined);
|
||||
});
|
||||
socket.emit("toast", "addedsong");
|
||||
});
|
||||
} else {
|
||||
vote(coll, id, guid, socket);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
db.collection(coll).find({id: id}, function(err, docs) {
|
||||
if(docs.length === 0) {
|
||||
var suggestedAdd = {
|
||||
"added":Functions.get_time(),
|
||||
"guids": [guid],
|
||||
"id":id,
|
||||
"now_playing": false,
|
||||
"title":title,
|
||||
"votes":1,
|
||||
"duration":duration,
|
||||
"start": start,
|
||||
"end": end,
|
||||
"type":"suggested"
|
||||
};
|
||||
var source = arr.source;
|
||||
if(source == "soundcloud") {
|
||||
suggestedAdd.thumbnail = arr.thumbnail;
|
||||
suggestedAdd.source = source;
|
||||
conf = docs;
|
||||
if(docs !== null && docs.length !== 0 && ((docs[0].addsongs === true && (hash == docs[0].adminpass || docs[0].adminpass === "")) ||
|
||||
docs[0].addsongs === false)) {
|
||||
db.collection(coll).find({id:id, type:{$ne:"suggested"}}, function(err, docs){
|
||||
if(docs !== null && docs.length === 0) {
|
||||
var guids = [guid];
|
||||
var added = Functions.get_time();
|
||||
var votes = 1;
|
||||
db.collection(coll).find({now_playing:true}, function(err, docs){
|
||||
if((docs !== null && docs.length === 0)){
|
||||
np = true;
|
||||
} else {
|
||||
suggestedAdd.source = "youtube";
|
||||
np = false;
|
||||
}
|
||||
db.collection(coll).update({id: id}, {$set: suggestedAdd},
|
||||
var new_song = {"added": added,"guids":guids,"id":id,"now_playing":np,"title":title,"votes":votes, "duration":duration, "start": parseInt(start), "end": parseInt(end), "type": "video", "source": source};
|
||||
if(source == "soundcloud") {
|
||||
if(arr.thumbnail.indexOf("https://i1.sndcdn.com") > -1 || arr.thumbnail.indexOf("https://w1.sndcdn.com") > -1) {
|
||||
new_song.thumbnail = arr.thumbnail;
|
||||
} else {
|
||||
new_song.thumbnail = "https://img.youtube.com/vi/404_notfound/mqdefault.jpg";
|
||||
}
|
||||
} else if(source == "youtube") new_song.thumbnail = "https://img.youtube.com/vi/" + new_song.id + "/mqdefault.jpg";
|
||||
db.collection(coll).update({id: id}, new_song, {upsert: true}, function(err, docs){
|
||||
new_song._id = "asd";
|
||||
if(np) {
|
||||
List.send_list(coll, undefined, false, true, false);
|
||||
db.collection(coll + "_settings").update({ id: "config" }, {$set:{startTime: Functions.get_time()}});
|
||||
List.send_play(coll, undefined);
|
||||
var thumbnail = arr.thumbnail != undefined ? arr.thumbnail : undefined;
|
||||
Frontpage.update_frontpage(coll, id, title, thumbnail, arr.source);
|
||||
if(source != "soundcloud") Search.get_correct_info(new_song, coll, false);
|
||||
} else {
|
||||
io.to(coll).emit("channel", {type: "added", value: new_song});
|
||||
if(source != "soundcloud") Search.get_correct_info(new_song, coll, true);
|
||||
}
|
||||
db.collection("frontpage_lists").update({_id:coll}, {$inc:{count:1}, $set:{accessed: Functions.get_time()}}, {upsert:true}, function(err, docs){});
|
||||
List.getNextSong(coll, undefined);
|
||||
});
|
||||
socket.emit("toast", "addedsong");
|
||||
});
|
||||
} else {
|
||||
vote(coll, id, guid, socket);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
db.collection(coll).find({id: id}, function(err, docs) {
|
||||
if(docs.length === 0) {
|
||||
var suggestedAdd = {
|
||||
"added":Functions.get_time(),
|
||||
"guids": [guid],
|
||||
"id":id,
|
||||
"now_playing": false,
|
||||
"title":title,
|
||||
"votes":1,
|
||||
"duration":duration,
|
||||
"start": start,
|
||||
"end": end,
|
||||
"type":"suggested"
|
||||
};
|
||||
var source = arr.source;
|
||||
if(source == "soundcloud") {
|
||||
suggestedAdd.thumbnail = arr.thumbnail;
|
||||
suggestedAdd.source = source;
|
||||
} else {
|
||||
suggestedAdd.source = "youtube";
|
||||
}
|
||||
db.collection(coll).update({id: id}, {$set: suggestedAdd},
|
||||
{upsert:true}, function(err, docs){
|
||||
socket.emit("toast", "suggested");
|
||||
var toSend = {id: id, title: title, duration: duration, source: suggestedAdd.source};
|
||||
@@ -477,32 +482,32 @@ function add_function(arr, coll, guid, offline, socket) {
|
||||
}
|
||||
});
|
||||
}
|
||||
//});
|
||||
} else {
|
||||
socket.emit("auth_required");
|
||||
}
|
||||
//});
|
||||
} else {
|
||||
socket.emit("auth_required");
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
} else {
|
||||
var result = {
|
||||
arr: {
|
||||
expected: "object",
|
||||
got: typeof(arr)
|
||||
},
|
||||
duration: {
|
||||
expected: "number or string that can be cast to int",
|
||||
got: arr.hasOwnProperty("duration") ? typeof(arr.duration) : undefined,
|
||||
}
|
||||
};
|
||||
socket.emit('update_required', result);
|
||||
} else {
|
||||
var result = {
|
||||
arr: {
|
||||
expected: "object",
|
||||
got: typeof(arr)
|
||||
},
|
||||
duration: {
|
||||
expected: "number or string that can be cast to int",
|
||||
got: arr.hasOwnProperty("duration") ? typeof(arr.duration) : undefined,
|
||||
}
|
||||
};
|
||||
socket.emit('update_required', result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function voteUndecided(msg, coll, guid, offline, socket) {
|
||||
var socketid = socket.zoff_id;
|
||||
if(typeof(msg) === 'object' && msg !== undefined && msg !== null){
|
||||
function voteUndecided(msg, coll, guid, offline, socket) {
|
||||
var socketid = socket.zoff_id;
|
||||
if(typeof(msg) === 'object' && msg !== undefined && msg !== null){
|
||||
|
||||
if(!msg.hasOwnProperty("channel") || !msg.hasOwnProperty("id") ||
|
||||
if(!msg.hasOwnProperty("channel") || !msg.hasOwnProperty("id") ||
|
||||
!msg.hasOwnProperty("type") || typeof(msg.channel) != "string" ||
|
||||
typeof(msg.id) != "string" || typeof(msg.type) != "string") {
|
||||
var result = {
|
||||
@@ -530,53 +535,53 @@ function voteUndecided(msg, coll, guid, offline, socket) {
|
||||
socket.emit('update_required', result);
|
||||
return;
|
||||
}
|
||||
coll = msg.channel.toLowerCase();//.replace(/ /g,'');
|
||||
coll = Functions.removeEmojis(coll).toLowerCase();
|
||||
coll = filter.clean(coll);
|
||||
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass) {
|
||||
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(msg.pass)).digest("base64")))) {
|
||||
|
||||
Functions.check_inlist(coll, guid, socket, offline);
|
||||
|
||||
if(msg.type == "del") {
|
||||
del(msg, socket, socketid);
|
||||
} else {
|
||||
var id = msg.id;
|
||||
var hash = Functions.hash_pass(Functions.hash_pass(Functions.decrypt_string(msg.adminpass), true));
|
||||
if(docs !== null && docs.length !== 0 && ((docs[0].vote === true && (hash == docs[0].adminpass || docs[0].adminpass === "")) ||
|
||||
docs[0].vote === false)) {
|
||||
vote(coll, id, guid, socket);
|
||||
} else {
|
||||
socket.emit("toast", "listhaspass");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
socket.emit("auth_required");
|
||||
coll = msg.channel.toLowerCase();//.replace(/ /g,'');
|
||||
coll = Functions.removeEmojis(coll).toLowerCase();
|
||||
coll = filter.clean(coll);
|
||||
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass) {
|
||||
if(adminpass != "" || msg.adminpass == undefined) {
|
||||
msg.adminpass = adminpass;
|
||||
}
|
||||
if(userpass != "" || msg.pass == undefined) {
|
||||
msg.pass = userpass;
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
var result = {
|
||||
msg: {
|
||||
expected: "object",
|
||||
got: typeof(msg)
|
||||
}
|
||||
};
|
||||
socket.emit('update_required', result);
|
||||
}
|
||||
}
|
||||
|
||||
function shuffle(msg, coll, guid, offline, socket) {
|
||||
var socketid = socket.zoff_id;
|
||||
if(!msg.hasOwnProperty("channel") || typeof(msg.channel) != "string") {
|
||||
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(msg.pass)).digest("base64")))) {
|
||||
|
||||
Functions.check_inlist(coll, guid, socket, offline);
|
||||
|
||||
if(msg.type == "del") {
|
||||
del(msg, socket, socketid);
|
||||
} else {
|
||||
var id = msg.id;
|
||||
var hash = Functions.hash_pass(Functions.hash_pass(Functions.decrypt_string(msg.adminpass), true));
|
||||
if(docs !== null && docs.length !== 0 && ((docs[0].vote === true && (hash == docs[0].adminpass || docs[0].adminpass === "")) ||
|
||||
docs[0].vote === false)) {
|
||||
vote(coll, id, guid, socket);
|
||||
} else {
|
||||
socket.emit("toast", "listhaspass");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
socket.emit("auth_required");
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
var result = {
|
||||
msg: {
|
||||
expected: "object",
|
||||
got: typeof(msg)
|
||||
}
|
||||
};
|
||||
socket.emit('update_required', result);
|
||||
}
|
||||
}
|
||||
|
||||
function shuffle(msg, coll, guid, offline, socket) {
|
||||
var socketid = socket.zoff_id;
|
||||
if(!msg.hasOwnProperty("channel") || typeof(msg.channel) != "string") {
|
||||
var result = {
|
||||
channel: {
|
||||
expected: "string",
|
||||
@@ -594,108 +599,108 @@ function shuffle(msg, coll, guid, offline, socket) {
|
||||
socket.emit('update_required', result);
|
||||
return;
|
||||
}
|
||||
coll = msg.channel.toLowerCase();//.replace(/ /g,'');
|
||||
coll = Functions.removeEmojis(coll).toLowerCase();
|
||||
coll = filter.clean(coll);
|
||||
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass) {
|
||||
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,
|
||||
}, 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;
|
||||
}
|
||||
coll = msg.channel.toLowerCase();//.replace(/ /g,'');
|
||||
coll = Functions.removeEmojis(coll).toLowerCase();
|
||||
coll = filter.clean(coll);
|
||||
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass) {
|
||||
if(adminpass != "" || msg.adminpass == undefined) {
|
||||
msg.adminpass = adminpass;
|
||||
}
|
||||
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);
|
||||
var hash;
|
||||
if(msg.adminpass === "") hash = msg.adminpass;
|
||||
else hash = Functions.hash_pass(Functions.hash_pass(Functions.decrypt_string(msg.adminpass),true));
|
||||
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(msg.pass)).digest("base64")))) {
|
||||
if(docs !== null && docs.length !== 0 && ((docs[0].adminpass == hash && docs[0].adminpass != "") || docs[0].shuffle === false))
|
||||
if(userpass != "" || msg.pass == undefined) {
|
||||
msg.pass = userpass;
|
||||
}
|
||||
db.collection("timeout_api").find({
|
||||
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);
|
||||
var hash;
|
||||
if(msg.adminpass === "") hash = msg.adminpass;
|
||||
else hash = Functions.hash_pass(Functions.hash_pass(Functions.decrypt_string(msg.adminpass),true));
|
||||
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(msg.pass)).digest("base64")))) {
|
||||
if(docs !== null && docs.length !== 0 && ((docs[0].adminpass == hash && docs[0].adminpass != "") || docs[0].shuffle === false))
|
||||
{
|
||||
db.collection(coll).find({now_playing:false}).forEach(function(err, docs){
|
||||
if(!docs){
|
||||
List.send_list(coll, undefined, false, true, false, true);
|
||||
socket.emit("toast", "shuffled");
|
||||
|
||||
return;
|
||||
}else{
|
||||
num = Math.floor(Math.random()*1000000);
|
||||
db.collection(coll).update({id:docs.id}, {$set:{added:num}});
|
||||
}
|
||||
});
|
||||
}else
|
||||
socket.emit("toast", "wrongpass");
|
||||
} else {
|
||||
socket.emit("auth_required");
|
||||
}
|
||||
});
|
||||
|
||||
var complete = function(tot, curr){
|
||||
if(tot == curr)
|
||||
{
|
||||
db.collection(coll).find({now_playing:false}).forEach(function(err, docs){
|
||||
if(!docs){
|
||||
List.send_list(coll, undefined, false, true, false, true);
|
||||
socket.emit("toast", "shuffled");
|
||||
|
||||
return;
|
||||
}else{
|
||||
num = Math.floor(Math.random()*1000000);
|
||||
db.collection(coll).update({id:docs.id}, {$set:{added:num}});
|
||||
}
|
||||
});
|
||||
}else
|
||||
socket.emit("toast", "wrongpass");
|
||||
} else {
|
||||
socket.emit("auth_required");
|
||||
}
|
||||
List.send_list(coll, undefined, false, true, false);
|
||||
List.getNextSong(coll, undefined);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
var complete = function(tot, curr){
|
||||
if(tot == curr)
|
||||
{
|
||||
List.send_list(coll, undefined, false, true, false);
|
||||
List.getNextSong(coll, undefined);
|
||||
}
|
||||
};
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function del(params, socket, socketid) {
|
||||
if(params.id){
|
||||
var coll = Functions.removeEmojis(params.channel).toLowerCase();
|
||||
//coll = coll.replace(/_/g, "").replace(/ /g,'');
|
||||
|
||||
coll = filter.clean(coll);
|
||||
db.collection(coll + "_settings").find(function(err, docs){
|
||||
if(docs !== null && docs.length !== 0 && docs[0].adminpass == Functions.hash_pass(Functions.hash_pass(Functions.decrypt_string(params.adminpass),true)))
|
||||
{
|
||||
db.collection(coll).find({id:params.id}, function(err, docs){
|
||||
var dont_increment = false;
|
||||
if(docs[0]){
|
||||
if(docs[0].type == "suggested"){
|
||||
dont_increment = true;
|
||||
}
|
||||
db.collection(coll).remove({id:params.id}, function(err, docs){
|
||||
socket.emit("toast", "deletesong");
|
||||
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){});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
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") {
|
||||
function del(params, socket, socketid) {
|
||||
if(params.id){
|
||||
var coll = Functions.removeEmojis(params.channel).toLowerCase();
|
||||
//coll = coll.replace(/_/g, "").replace(/ /g,'');
|
||||
|
||||
coll = filter.clean(coll);
|
||||
db.collection(coll + "_settings").find(function(err, docs){
|
||||
if(docs !== null && docs.length !== 0 && docs[0].adminpass == Functions.hash_pass(Functions.hash_pass(Functions.decrypt_string(params.adminpass),true)))
|
||||
{
|
||||
db.collection(coll).find({id:params.id}, function(err, docs){
|
||||
var dont_increment = false;
|
||||
if(docs[0]){
|
||||
if(docs[0].type == "suggested"){
|
||||
dont_increment = true;
|
||||
}
|
||||
db.collection(coll).remove({id:params.id}, function(err, docs){
|
||||
socket.emit("toast", "deletesong");
|
||||
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){});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
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") {
|
||||
var result = {
|
||||
channel: {
|
||||
expected: "string",
|
||||
@@ -742,43 +747,43 @@ function delete_all(msg, coll, guid, offline, socket) {
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
var result = {
|
||||
msg: {
|
||||
expected: "object",
|
||||
got: typeof(msg)
|
||||
},
|
||||
};
|
||||
socket.emit('update_required', result);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
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))
|
||||
{
|
||||
db.collection(coll).update({id:id}, {$inc:{votes:1}, $set:{added:Functions.get_time()}, $push :{guids: guid}}, function(err, docs)
|
||||
{
|
||||
socket.emit("toast", "voted");
|
||||
io.to(coll).emit("channel", {type: "vote", value: id, time: Functions.get_time()});
|
||||
|
||||
List.getNextSong(coll, undefined);
|
||||
});
|
||||
}else
|
||||
{
|
||||
socket.emit("toast", "alreadyvoted");
|
||||
} else {
|
||||
var result = {
|
||||
msg: {
|
||||
expected: "object",
|
||||
got: typeof(msg)
|
||||
},
|
||||
};
|
||||
socket.emit('update_required', result);
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
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))
|
||||
{
|
||||
db.collection(coll).update({id:id}, {$inc:{votes:1}, $set:{added:Functions.get_time()}, $push :{guids: guid}}, function(err, docs)
|
||||
{
|
||||
socket.emit("toast", "voted");
|
||||
io.to(coll).emit("channel", {type: "vote", value: id, time: Functions.get_time()});
|
||||
|
||||
List.getNextSong(coll, undefined);
|
||||
});
|
||||
}else
|
||||
{
|
||||
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;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -481,7 +481,8 @@ var Player = {
|
||||
},
|
||||
|
||||
playNext: function(){
|
||||
var next_song = full_playlist[0];
|
||||
if(full_playlist.length == 0) return;
|
||||
var next_song = full_playlist[0];
|
||||
|
||||
video_id = next_song.id;
|
||||
time = (new Date()).getTime();
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user