Prettier JSON and less globally exposed variables

This commit is contained in:
Kasper Rynning-Tønnesen
2018-05-30 14:19:10 +02:00
parent 68c24b6317
commit b971074788
11 changed files with 168 additions and 129 deletions

View File

@@ -26,7 +26,7 @@ var hbs = exphbs.create({
layoutsDir: publicPath + '/layouts/client', layoutsDir: publicPath + '/layouts/client',
partialsDir: publicPath + '/partials' partialsDir: publicPath + '/partials'
}); });
uniqid = require('uniqid'); var uniqid = require('uniqid');
app.engine('handlebars', hbs.engine); app.engine('handlebars', hbs.engine);
@@ -45,36 +45,22 @@ app.use(bodyParser.urlencoded({ // to support URL-encoded bodies
extended: true extended: true
})); }));
app.use(cookieParser()); app.use(cookieParser());
app.set('json spaces', 2);
/* Starting DB and socketio */
io = require('socket.io')({ io = require('socket.io')({
pingTimeout: 25000, pingTimeout: 25000,
//path: '/zoff', //path: '/zoff',
//"origins": ("https://zoff.me:443*,https://zoff.me:8080*,zoff.me:8080*,https://remote.zoff.me:443*,https://remote.zoff.me:8080*,https://fb.zoff.me:443*,https://fb.zoff.me:8080*,https://admin.zoff.me:443*,https://admin.zoff.me:8080*, http://localhost:8080*")}); //"origins": ("https://zoff.me:443*,https://zoff.me:8080*,zoff.me:8080*,https://remote.zoff.me:443*,https://remote.zoff.me:8080*,https://fb.zoff.me:443*,https://fb.zoff.me:8080*,https://admin.zoff.me:443*,https://admin.zoff.me:8080*, http://localhost:8080*")});
}); });
db = require(pathThumbnails + '/handlers/db.js');
var socketIO = require(pathThumbnails +'/handlers/io.js'); var socketIO = require(pathThumbnails +'/handlers/io.js');
socketIO(); socketIO();
app.socketIO = io; app.socketIO = io;
request = require('request');
/* Globally needed "libraries" and files */ /* Globally needed "libraries" and files */
Functions = require(pathThumbnails + '/handlers/functions.js'); var Functions = require(pathThumbnails + '/handlers/functions.js');
ListChange = require(pathThumbnails + '/handlers/list_change.js');
Chat = require(pathThumbnails + '/handlers/chat.js');
List = require(pathThumbnails + '/handlers/list.js');
Suggestions = require(pathThumbnails + '/handlers/suggestions.js');
ListSettings = require(pathThumbnails + '/handlers/list_settings.js');
Frontpage = require(pathThumbnails + '/handlers/frontpage.js');
Notifications = require(pathThumbnails + '/handlers/notifications.js');
Search = require(pathThumbnails + '/handlers/search.js');
crypto = require('crypto');
emojiStrip = Functions.removeEmojis;
Filter = require('bad-words');
filter = new Filter({ placeHolder: 'x'});
var router = require(pathThumbnails + '/routing/client/router.js'); var router = require(pathThumbnails + '/routing/client/router.js');
var api = require(pathThumbnails + '/routing/client/api.js'); var api = require(pathThumbnails + '/routing/client/api.js');
var ico_router = require(pathThumbnails + '/routing/client/icons_routing.js'); var ico_router = require(pathThumbnails + '/routing/client/icons_routing.js');

View File

@@ -1,3 +1,9 @@
var Functions = require(pathThumbnails + '/handlers/functions.js');
var crypto = require('crypto');
var Filter = require('bad-words');
var filter = new Filter({ placeHolder: 'x'});
var db = require(pathThumbnails + '/handlers/db.js');
function get_history(channel, all, socket) { function get_history(channel, all, socket) {
var query = {}; var query = {};
if(all) { if(all) {
@@ -67,7 +73,7 @@ function chat(msg, guid, offline, socket) {
return; return;
} }
var coll = msg.channel.toLowerCase().replace(/ /g,''); var coll = msg.channel.toLowerCase().replace(/ /g,'');
coll = emojiStrip(coll).toLowerCase(); coll = Functions.removeEmojis(coll).toLowerCase();
coll = filter.clean(coll); coll = filter.clean(coll);
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass) { Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass) {
if(userpass != "" || msg.pass == undefined) { if(userpass != "" || msg.pass == undefined) {
@@ -120,7 +126,7 @@ function all_chat(msg, guid, offline, socket) {
} }
var coll = msg.channel.toLowerCase().replace(/ /g,''); var coll = msg.channel.toLowerCase().replace(/ /g,'');
var data = msg.data; var data = msg.data;
coll = emojiStrip(coll).toLowerCase(); coll = Functions.removeEmojis(coll).toLowerCase();
coll = filter.clean(coll); coll = filter.clean(coll);
Functions.check_inlist(coll, guid, socket, offline); Functions.check_inlist(coll, guid, socket, offline);
if(data !== "" && data !== undefined && data !== null && if(data !== "" && data !== undefined && data !== null &&
@@ -268,11 +274,11 @@ function generate_name(guid, announce_payload, second) {
} }
}); });
} else { } else {
Chat.generate_name(guid, announce_payload, tmp_name); generate_name(guid, announce_payload, tmp_name);
} }
}) })
} else { } else {
Chat.generate_name(guid, announce_payload, tmp_name); generate_name(guid, announce_payload, tmp_name);
} }
}) })
} }
@@ -280,7 +286,7 @@ function generate_name(guid, announce_payload, second) {
function get_name(guid, announce_payload, first) { function get_name(guid, announce_payload, first) {
db.collection("user_names").find({"guid": guid}, function(err, docs) { db.collection("user_names").find({"guid": guid}, function(err, docs) {
if(docs.length == 0) { if(docs.length == 0) {
Chat.generate_name(guid, announce_payload); generate_name(guid, announce_payload);
} else { } else {
name = docs[0].name; name = docs[0].name;
} }

View File

@@ -1,3 +1,5 @@
var Functions = require(pathThumbnails + '/handlers/functions.js');
var db = require(pathThumbnails + '/handlers/db.js');
function frontpage_lists(msg, socket) { function frontpage_lists(msg, socket) {
if(msg == undefined || !msg.hasOwnProperty('version') || msg.version != VERSION || msg.version == undefined) { if(msg == undefined || !msg.hasOwnProperty('version') || msg.version != VERSION || msg.version == undefined) {
var result = { var result = {

View File

@@ -8,6 +8,9 @@ try {
} }
var mongojs = require('mongojs'); var mongojs = require('mongojs');
var connected_db = mongojs('mongodb://' + mongo_config.host + '/user_credentials'); var connected_db = mongojs('mongodb://' + mongo_config.host + '/user_credentials');
var crypto = require('crypto');
var db = require(pathThumbnails + '/handlers/db.js');
var uniqid = require('uniqid');
function remove_unique_id(short_id) { function remove_unique_id(short_id) {
db.collection("unique_ids").update({"_id": "unique_ids"}, {$pull: {unique_ids: short_id}}, function(err, docs) {}); db.collection("unique_ids").update({"_id": "unique_ids"}, {$pull: {unique_ids: short_id}}, function(err, docs) {});
@@ -50,7 +53,7 @@ function getSession(socket) {
} }
function remove_from_array(array, element){ function remove_from_array(array, element){
if(Functions.contains(array, element)){ if(contains(array, element)){
var index = array.indexOf(element); var index = array.indexOf(element);
if(index != -1) if(index != -1)
array.splice(index, 1); array.splice(index, 1);

View File

@@ -1,5 +1,19 @@
var cookieParser = require("cookie-parser"); var cookieParser = require("cookie-parser");
var cookie = require("cookie"); var cookie = require("cookie");
var Functions = require(pathThumbnails + '/handlers/functions.js');
var ListChange = require(pathThumbnails + '/handlers/list_change.js');
var Chat = require(pathThumbnails + '/handlers/chat.js');
var List = require(pathThumbnails + '/handlers/list.js');
var Suggestions = require(pathThumbnails + '/handlers/suggestions.js');
var ListSettings = require(pathThumbnails + '/handlers/list_settings.js');
var Frontpage = require(pathThumbnails + '/handlers/frontpage.js');
var Search = require(pathThumbnails + '/handlers/search.js');
var crypto = require('crypto');
var Filter = require('bad-words');
var filter = new Filter({ placeHolder: 'x'});
var db = require(pathThumbnails + '/handlers/db.js');
module.exports = function() { module.exports = function() {
io.on('connection', function(socket){ io.on('connection', function(socket){
try { try {
@@ -68,7 +82,7 @@ module.exports = function() {
socketid = msg.socket_id; socketid = msg.socket_id;
socket.zoff_id = socketid; socket.zoff_id = socketid;
coll = msg.channel.toLowerCase().replace(/ /g,''); coll = msg.channel.toLowerCase().replace(/ /g,'');
coll = emojiStrip(coll).toLowerCase(); coll = Functions.removeEmojis(coll).toLowerCase();
coll = filter.clean(coll); coll = filter.clean(coll);
if(coll.indexOf("?") > -1){ if(coll.indexOf("?") > -1){
coll = coll.substring(0, coll.indexOf("?")); coll = coll.substring(0, coll.indexOf("?"));
@@ -96,7 +110,7 @@ module.exports = function() {
_list = _list.substring(0, _list.indexOf("?")); _list = _list.substring(0, _list.indexOf("?"));
msg.channel = _list; msg.channel = _list;
} }
coll = emojiStrip(_list).toLowerCase(); coll = Functions.removeEmojis(_list).toLowerCase();
coll = coll.replace(/_/g, ""); coll = coll.replace(/_/g, "");
coll = filter.clean(coll); coll = filter.clean(coll);
@@ -189,7 +203,7 @@ module.exports = function() {
offline = true; offline = true;
if(channel != "") coll = channel; if(channel != "") coll = channel;
if(coll !== undefined) { if(coll !== undefined) {
coll = emojiStrip(coll).toLowerCase(); coll = Functions.removeEmojis(coll).toLowerCase();
coll = filter.clean(coll); coll = filter.clean(coll);
db.collection("connected_users").findAndModify({ db.collection("connected_users").findAndModify({
@@ -314,7 +328,7 @@ module.exports = function() {
_list = _list.substring(0, _list.indexOf("?")); _list = _list.substring(0, _list.indexOf("?"));
msg.channel = _list; msg.channel = _list;
} }
coll = emojiStrip(_list).toLowerCase(); coll = Functions.removeEmojis(_list).toLowerCase();
coll = coll.replace(/_/g, ""); coll = coll.replace(/_/g, "");
// //
coll = filter.clean(coll); coll = filter.clean(coll);
@@ -339,7 +353,7 @@ module.exports = function() {
try { try {
coll = obj.channel.toLowerCase().replace(/ /g,''); coll = obj.channel.toLowerCase().replace(/ /g,'');
if(coll.length == 0) return; if(coll.length == 0) return;
coll = emojiStrip(coll).toLowerCase(); coll = Functions.removeEmojis(coll).toLowerCase();
coll = coll.replace(/_/g, ""); coll = coll.replace(/_/g, "");
coll = filter.clean(coll); coll = filter.clean(coll);
@@ -368,7 +382,7 @@ module.exports = function() {
try { try {
coll = arr.list.replace(/ /g,''); coll = arr.list.replace(/ /g,'');
if(coll.length == 0) return; if(coll.length == 0) return;
coll = emojiStrip(coll).toLowerCase(); coll = Functions.removeEmojis(coll).toLowerCase();
coll = coll.replace(/_/g, ""); coll = coll.replace(/_/g, "");
coll = filter.clean(coll); coll = filter.clean(coll);
@@ -387,7 +401,7 @@ module.exports = function() {
} }
coll = msg.channel.toLowerCase().replace(/ /g,''); coll = msg.channel.toLowerCase().replace(/ /g,'');
if(coll.length == 0) return; if(coll.length == 0) return;
coll = emojiStrip(coll).toLowerCase(); coll = Functions.removeEmojis(coll).toLowerCase();
coll = coll.replace(/_/g, ""); coll = coll.replace(/_/g, "");
coll = filter.clean(coll); coll = filter.clean(coll);
@@ -408,7 +422,7 @@ module.exports = function() {
try { try {
coll = msg.channel.toLowerCase().replace(/ /g,''); coll = msg.channel.toLowerCase().replace(/ /g,'');
if(coll.length == 0) return; if(coll.length == 0) return;
coll = emojiStrip(coll).toLowerCase(); coll = Functions.removeEmojis(coll).toLowerCase();
coll = coll.replace(/_/g, ""); coll = coll.replace(/_/g, "");
coll = filter.clean(coll); coll = filter.clean(coll);
@@ -461,7 +475,7 @@ module.exports = function() {
try { try {
coll = msg.channel.toLowerCase().replace(/ /g,''); coll = msg.channel.toLowerCase().replace(/ /g,'');
if(coll.length == 0) return; if(coll.length == 0) return;
coll = emojiStrip(coll).toLowerCase(); coll = Functions.removeEmojis(coll).toLowerCase();
coll = coll.replace(/_/g, ""); coll = coll.replace(/_/g, "");
coll = filter.clean(coll); coll = filter.clean(coll);
@@ -485,7 +499,7 @@ module.exports = function() {
try { try {
coll = obj.channel.toLowerCase().replace(/ /g,''); coll = obj.channel.toLowerCase().replace(/ /g,'');
if(coll.length == 0) return; if(coll.length == 0) return;
coll = emojiStrip(coll).toLowerCase(); coll = Functions.removeEmojis(coll).toLowerCase();
coll = coll.replace(/_/g, ""); coll = coll.replace(/_/g, "");
coll = filter.clean(coll); coll = filter.clean(coll);
@@ -514,7 +528,7 @@ module.exports = function() {
} }
if(msg.hasOwnProperty("channel") && msg.channel != "" && typeof(msg.channel) == "string") { if(msg.hasOwnProperty("channel") && msg.channel != "" && typeof(msg.channel) == "string") {
coll = msg.channel.replace(/ /g,''); coll = msg.channel.replace(/ /g,'');
coll = emojiStrip(coll).toLowerCase(); coll = Functions.removeEmojis(coll).toLowerCase();
coll = filter.clean(coll); coll = filter.clean(coll);
List.left_channel(coll, guid, short_id, in_list, socket, false); List.left_channel(coll, guid, short_id, in_list, socket, false);
} }
@@ -546,7 +560,7 @@ module.exports = function() {
try { try {
coll = obj.channel.toLowerCase().replace(/ /g,''); coll = obj.channel.toLowerCase().replace(/ /g,'');
if(coll.length == 0) return; if(coll.length == 0) return;
coll = emojiStrip(coll).toLowerCase(); coll = Functions.removeEmojis(coll).toLowerCase();
coll = coll.replace(/_/g, ""); coll = coll.replace(/_/g, "");
coll = filter.clean(coll); coll = filter.clean(coll);

View File

@@ -1,5 +1,12 @@
var ColorThief = require('color-thief-jimp'); var ColorThief = require('color-thief-jimp');
var Jimp = require('jimp'); var Jimp = require('jimp');
var Functions = require(pathThumbnails + '/handlers/functions.js');
var Frontpage = require(pathThumbnails + '/handlers/frontpage.js');
var crypto = require('crypto');
var Filter = require('bad-words');
var filter = new Filter({ placeHolder: 'x'});
var request = require('request');
var db = require(pathThumbnails + '/handlers/db.js');
function now_playing(list, fn, socket) { function now_playing(list, fn, socket) {
if(typeof(list) !== 'string' || typeof(fn) !== 'function') { if(typeof(list) !== 'string' || typeof(fn) !== 'function') {
@@ -47,7 +54,7 @@ function list(msg, guid, coll, offline, socket) {
return; return;
} }
coll = msg.channel.toLowerCase().replace(/ /g,''); coll = msg.channel.toLowerCase().replace(/ /g,'');
coll = emojiStrip(coll).toLowerCase(); coll = Functions.removeEmojis(coll).toLowerCase();
coll = filter.clean(coll); coll = filter.clean(coll);
var pass = crypto.createHash('sha256').update(Functions.decrypt_string(msg.pass)).digest("base64"); var pass = crypto.createHash('sha256').update(Functions.decrypt_string(msg.pass)).digest("base64");
db.collection('frontpage_lists').find({"_id": coll}, function(err, frontpage_lists){ db.collection('frontpage_lists').find({"_id": coll}, function(err, frontpage_lists){
@@ -71,7 +78,7 @@ function list(msg, guid, coll, offline, socket) {
io.to(coll).emit("viewers", 1); io.to(coll).emit("viewers", 1);
} }
List.send_list(coll, socket, true, false, true); send_list(coll, socket, true, false, true);
} else { } else {
socket.emit("auth_required"); socket.emit("auth_required");
@@ -83,7 +90,7 @@ function list(msg, guid, coll, offline, socket) {
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"}; 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){ db.collection(coll + "_settings").insert(configs, function(err, docs){
socket.join(coll); socket.join(coll);
List.send_list(coll, socket, true, false, true); send_list(coll, socket, true, false, true);
db.collection("frontpage_lists").insert({"_id": coll, "count" : 0, "frontpage": true, "accessed": Functions.get_time(), "viewers": 1}, function(e,d){ db.collection("frontpage_lists").insert({"_id": coll, "count" : 0, "frontpage": true, "accessed": Functions.get_time(), "viewers": 1}, function(e,d){
}); });
Functions.check_inlist(coll, guid, socket, offline); Functions.check_inlist(coll, guid, socket, offline);
@@ -114,7 +121,7 @@ function skip(list, guid, coll, offline, socket) {
try { try {
coll = list.channel.toLowerCase().replace(/ /g,''); coll = list.channel.toLowerCase().replace(/ /g,'');
if(coll.length == 0) return; if(coll.length == 0) return;
coll = emojiStrip(coll).toLowerCase(); coll = Functions.removeEmojis(coll).toLowerCase();
coll = coll.replace(/_/g, ""); coll = coll.replace(/_/g, "");
coll = filter.clean(coll); coll = filter.clean(coll);
@@ -187,7 +194,7 @@ function skip(list, guid, coll, offline, socket) {
(frontpage_viewers[0].viewers == 2 && docs[0].skips.length+1 == 2 && !Functions.contains(docs[0].skips, guid)) || (frontpage_viewers[0].viewers == 2 && docs[0].skips.length+1 == 2 && !Functions.contains(docs[0].skips, guid)) ||
(docs[0].adminpass == hash && docs[0].adminpass !== "" && docs[0].skip)) (docs[0].adminpass == hash && docs[0].adminpass !== "" && docs[0].skip))
{ {
List.change_song(coll, error, video_id); change_song(coll, error, video_id);
socket.emit("toast", "skip"); socket.emit("toast", "skip");
db.collection("user_names").find({"guid": guid}, function(err, docs) { db.collection("user_names").find({"guid": guid}, function(err, docs) {
if(docs.length == 1) { if(docs.length == 1) {
@@ -266,7 +273,7 @@ function change_song(coll, error, id, callback, socket) {
db.collection(coll).remove({now_playing:true, id:id}, function(err, docs){ db.collection(coll).remove({now_playing:true, id:id}, function(err, docs){
var next_song; var next_song;
if(now_playing_doc.length == 2) next_song = now_playing_doc[1].id; if(now_playing_doc.length == 2) next_song = now_playing_doc[1].id;
List.change_song_post(coll, next_song, callback, socket); change_song_post(coll, next_song, callback, socket);
if(!callback) { if(!callback) {
io.to(coll).emit("channel", {type: "deleted", value: now_playing_doc[0].id, removed: true}); io.to(coll).emit("channel", {type: "deleted", value: now_playing_doc[0].id, removed: true});
} }
@@ -284,7 +291,7 @@ function change_song(coll, error, id, callback, socket) {
},{multi:true}, function(err, docs){ },{multi:true}, function(err, docs){
var next_song; var next_song;
if(now_playing_doc.length == 2) next_song = now_playing_doc[1].id; if(now_playing_doc.length == 2) next_song = now_playing_doc[1].id;
if(docs.n >= 1) List.change_song_post(coll, next_song, callback, socket); if(docs.n >= 1) change_song_post(coll, next_song, callback, socket);
}); });
}); });
} }
@@ -295,7 +302,7 @@ function change_song(coll, error, id, callback, socket) {
db.collection(coll).remove({now_playing:true, id:id}, function(err, docs){ db.collection(coll).remove({now_playing:true, id:id}, function(err, docs){
var next_song; var next_song;
if(now_playing_doc.length == 2) next_song = now_playing_doc[1].id; if(now_playing_doc.length == 2) next_song = now_playing_doc[1].id;
List.change_song_post(coll, next_song, callback, socket); change_song_post(coll, next_song, callback, socket);
if(!callback) { if(!callback) {
io.to(coll).emit("channel", {type: "deleted", value: now_playing_doc[0].id, removed: true}); io.to(coll).emit("channel", {type: "deleted", value: now_playing_doc[0].id, removed: true});
} }
@@ -313,7 +320,7 @@ function change_song(coll, error, id, callback, socket) {
},{multi:true}, function(err, docs){ },{multi:true}, function(err, docs){
var next_song; var next_song;
if(now_playing_doc.length == 2) next_song = now_playing_doc[1].id; if(now_playing_doc.length == 2) next_song = now_playing_doc[1].id;
List.change_song_post(coll, next_song, callback, socket); change_song_post(coll, next_song, callback, socket);
}); });
} }
} }
@@ -375,10 +382,10 @@ function change_song_post(coll, next_song, callback, socket) {
db.collection(coll + "_settings").find({id: "config"}, function(err, conf){ db.collection(coll + "_settings").find({id: "config"}, function(err, conf){
if(!callback) { if(!callback) {
io.to(coll).emit("channel", {type: "song_change", time: Functions.get_time(), remove: conf[0].removeplay}); io.to(coll).emit("channel", {type: "song_change", time: Functions.get_time(), remove: conf[0].removeplay});
List.send_play(coll); send_play(coll);
} else { } else {
socket.to(coll).emit("channel", {type: "song_change", time: Functions.get_time(), remove: conf[0].removeplay}); socket.to(coll).emit("channel", {type: "song_change", time: Functions.get_time(), remove: conf[0].removeplay});
List.send_play(coll, socket, true); send_play(coll, socket, true);
callback(); callback();
} }
Frontpage.update_frontpage(coll, docs[0].id, docs[0].title, docs[0].thumbnail, docs[0].source); Frontpage.update_frontpage(coll, docs[0].id, docs[0].title, docs[0].thumbnail, docs[0].source);
@@ -467,7 +474,7 @@ function send_list(coll, socket, send, list_send, configs, shuffled)
} }
}, function(err, returnDocs){ }, function(err, returnDocs){
Frontpage.update_frontpage(coll, now_playing_doc[0].id, now_playing_doc[0].title, now_playing_doc[0].thumbnail, now_playing_doc[0].source); Frontpage.update_frontpage(coll, now_playing_doc[0].id, now_playing_doc[0].title, now_playing_doc[0].thumbnail, now_playing_doc[0].source);
List.send_list(coll, socket, send, list_send, configs, shuffled); send_list(coll, socket, send, list_send, configs, shuffled);
}); });
}); });
} }
@@ -492,8 +499,8 @@ function send_list(coll, socket, send, list_send, configs, shuffled)
}) })
} else { } else {
if(Functions.get_time()-conf[0].startTime > np_docs[0].duration){ if(Functions.get_time()-conf[0].startTime > np_docs[0].duration){
List.change_song(coll, false, np_docs[0].id, function() { change_song(coll, false, np_docs[0].id, function() {
List.send_list(coll, socket, send, list_send, configs, shuffled); send_list(coll, socket, send, list_send, configs, shuffled);
}, socket); }, socket);
} else { } else {
if(list_send) { if(list_send) {
@@ -502,9 +509,9 @@ function send_list(coll, socket, send, list_send, configs, shuffled)
socket.emit("channel", {type: "list", playlist: docs, shuffled: shuffled}); socket.emit("channel", {type: "list", playlist: docs, shuffled: shuffled});
} }
if(socket === undefined && send) { if(socket === undefined && send) {
List.send_play(coll); send_play(coll);
} else if(send) { } else if(send) {
List.send_play(coll, socket); send_play(coll, socket);
} }
} }
} }
@@ -516,9 +523,9 @@ function send_list(coll, socket, send, list_send, configs, shuffled)
socket.emit("channel", {type: "list", playlist: docs, shuffled: shuffled}); socket.emit("channel", {type: "list", playlist: docs, shuffled: shuffled});
} }
if(socket === undefined && send) { if(socket === undefined && send) {
List.send_play(coll); send_play(coll);
} else if(send) { } else if(send) {
List.send_play(coll, socket); send_play(coll, socket);
} }
} }
}); });
@@ -591,13 +598,13 @@ function end(obj, coll, guid, offline, socket) {
if(docs[0].removeplay === true && startTime+parseInt(np[0].duration)<=Functions.get_time()+5) if(docs[0].removeplay === true && startTime+parseInt(np[0].duration)<=Functions.get_time()+5)
{ {
db.collection(coll).remove({now_playing:true}, function(err, docs){ db.collection(coll).remove({now_playing:true}, function(err, docs){
List.change_song_post(coll); change_song_post(coll);
db.collection("frontpage_lists").update({_id:coll, count: {$gt: 0}}, {$inc:{count:-1}, $set:{accessed: Functions.get_time()}}, {upsert:true}, function(err, docs){}); db.collection("frontpage_lists").update({_id:coll, count: {$gt: 0}}, {$inc:{count:-1}, $set:{accessed: Functions.get_time()}}, {upsert:true}, function(err, docs){});
}); });
}else{ }else{
if(startTime+parseInt(np[0].duration)<=Functions.get_time()+5) if(startTime+parseInt(np[0].duration)<=Functions.get_time()+5)
{ {
List.change_song(coll, false, id); change_song(coll, false, id);
} }
} }
}); });
@@ -626,7 +633,7 @@ function send_play(coll, socket, broadcast) {
if(err !== null) console.log(err); if(err !== null) console.log(err);
try{ try{
if(Functions.get_time()-conf[0].startTime > np[0].duration){ if(Functions.get_time()-conf[0].startTime > np[0].duration){
List.change_song(coll, false, np[0].id); change_song(coll, false, np[0].id);
} else if(conf !== null && conf !== undefined && conf.length !== 0) } else if(conf !== null && conf !== undefined && conf.length !== 0)
{ {
if(conf[0].adminpass !== "") conf[0].adminpass = true; if(conf[0].adminpass !== "") conf[0].adminpass = true;
@@ -638,7 +645,7 @@ function send_play(coll, socket, broadcast) {
if(socket === undefined) { if(socket === undefined) {
io.to(coll).emit("np", toSend); io.to(coll).emit("np", toSend);
// //
List.getNextSong(coll) getNextSong(coll)
var url = 'https://img.youtube.com/vi/'+np[0].id+'/mqdefault.jpg'; var url = 'https://img.youtube.com/vi/'+np[0].id+'/mqdefault.jpg';
if(np[0].source == "soundcloud") url = np[0].thumbnail; if(np[0].source == "soundcloud") url = np[0].thumbnail;
sendColor(coll, false, url); sendColor(coll, false, url);

View File

@@ -1,3 +1,12 @@
var Functions = require(pathThumbnails + '/handlers/functions.js');
var List = require(pathThumbnails + '/handlers/list.js');
var Frontpage = require(pathThumbnails + '/handlers/frontpage.js');
var Search = require(pathThumbnails + '/handlers/search.js');
var crypto = require('crypto');
var Filter = require('bad-words');
var filter = new Filter({ placeHolder: 'x'});
var db = require(pathThumbnails + '/handlers/db.js');
function addFromOtherList(arr, guid, offline, socket) { function addFromOtherList(arr, guid, offline, socket) {
var socketid = socket.zoff_id; var socketid = socket.zoff_id;
if(typeof(arr) == "object") { if(typeof(arr) == "object") {
@@ -425,7 +434,7 @@ function add_function(arr, coll, guid, offline, socket) {
socket.emit("toast", "addedsong"); socket.emit("toast", "addedsong");
}); });
} else { } else {
ListChange.vote(coll, id, guid, socket); vote(coll, id, guid, socket);
} }
}); });
} else { } else {
@@ -460,7 +469,7 @@ function add_function(arr, coll, guid, offline, socket) {
} else if(docs[0].now_playing === true){ } else if(docs[0].now_playing === true){
socket.emit("toast", "alreadyplay"); socket.emit("toast", "alreadyplay");
} else{ } else{
if(conf[0].vote === false) ListChange.vote(coll, id, guid, socket); if(conf[0].vote === false) vote(coll, id, guid, socket);
else socket.emit("toast", "listhaspass"); else socket.emit("toast", "listhaspass");
} }
}); });
@@ -519,7 +528,7 @@ function voteUndecided(msg, coll, guid, offline, socket) {
return; return;
} }
coll = msg.channel.toLowerCase().replace(/ /g,''); coll = msg.channel.toLowerCase().replace(/ /g,'');
coll = emojiStrip(coll).toLowerCase(); coll = Functions.removeEmojis(coll).toLowerCase();
coll = filter.clean(coll); coll = filter.clean(coll);
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass) { Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass) {
if(adminpass != "" || msg.adminpass == undefined) { if(adminpass != "" || msg.adminpass == undefined) {
@@ -535,13 +544,13 @@ function voteUndecided(msg, coll, guid, offline, socket) {
Functions.check_inlist(coll, guid, socket, offline); Functions.check_inlist(coll, guid, socket, offline);
if(msg.type == "del") { if(msg.type == "del") {
ListChange.del(msg, socket, socketid); del(msg, socket, socketid);
} else { } else {
var id = msg.id; var id = msg.id;
var hash = Functions.hash_pass(Functions.hash_pass(Functions.decrypt_string(msg.adminpass), true)); 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 === "")) || if(docs !== null && docs.length !== 0 && ((docs[0].vote === true && (hash == docs[0].adminpass || docs[0].adminpass === "")) ||
docs[0].vote === false)) { docs[0].vote === false)) {
ListChange.vote(coll, id, guid, socket); vote(coll, id, guid, socket);
} else { } else {
socket.emit("toast", "listhaspass"); socket.emit("toast", "listhaspass");
} }
@@ -583,7 +592,7 @@ function shuffle(msg, coll, guid, offline, socket) {
return; return;
} }
coll = msg.channel.toLowerCase().replace(/ /g,''); coll = msg.channel.toLowerCase().replace(/ /g,'');
coll = emojiStrip(coll).toLowerCase(); coll = Functions.removeEmojis(coll).toLowerCase();
coll = filter.clean(coll); coll = filter.clean(coll);
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass) { Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass) {
if(adminpass != "" || msg.adminpass == undefined) { if(adminpass != "" || msg.adminpass == undefined) {
@@ -654,7 +663,7 @@ function shuffle(msg, coll, guid, offline, socket) {
function del(params, socket, socketid) { function del(params, socket, socketid) {
if(params.id){ if(params.id){
var coll = emojiStrip(params.channel).toLowerCase(); var coll = Functions.removeEmojis(params.channel).toLowerCase();
coll = coll.replace(/_/g, "").replace(/ /g,''); coll = coll.replace(/_/g, "").replace(/ /g,'');
coll = filter.clean(coll); coll = filter.clean(coll);
@@ -705,7 +714,7 @@ function delete_all(msg, coll, guid, offline, socket) {
coll = msg.channel; coll = msg.channel;
} }
coll = coll.replace(/ /g,''); coll = coll.replace(/ /g,'');
coll = emojiStrip(coll).toLowerCase(); coll = Functions.removeEmojis(coll).toLowerCase();
coll = filter.clean(coll); coll = filter.clean(coll);
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass, gotten) { Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass, gotten) {
if(adminpass != "" || msg.adminpass == undefined) { if(adminpass != "" || msg.adminpass == undefined) {

View File

@@ -1,3 +1,9 @@
var Functions = require(pathThumbnails + '/handlers/functions.js');
var crypto = require('crypto');
var Filter = require('bad-words');
var filter = new Filter({ placeHolder: 'x'});
var db = require(pathThumbnails + '/handlers/db.js');
function password(inp, coll, guid, offline, socket) { function password(inp, coll, guid, offline, socket) {
var sessionId = Functions.getSession(socket); var sessionId = Functions.getSession(socket);
if(sessionId == "") sessionId = "empty"; if(sessionId == "") sessionId = "empty";
@@ -22,7 +28,7 @@ function password(inp, coll, guid, offline, socket) {
try { try {
coll = inp.channel; coll = inp.channel;
if(coll.length == 0) return; if(coll.length == 0) return;
coll = emojiStrip(coll).toLowerCase(); coll = Functions.removeEmojis(coll).toLowerCase();
coll = coll.replace(/_/g, ""); coll = coll.replace(/_/g, "");
coll = filter.clean(coll); coll = filter.clean(coll);
@@ -86,7 +92,7 @@ function conf_function(params, coll, guid, offline, socket) {
try { try {
coll = params.channel.replace(/ /g,''); coll = params.channel.replace(/ /g,'');
if(coll.length == 0) return; if(coll.length == 0) return;
coll = emojiStrip(coll).toLowerCase(); coll = Functions.removeEmojis(coll).toLowerCase();
coll = coll.replace(/_/g, ""); coll = coll.replace(/_/g, "");
coll = filter.clean(coll); coll = filter.clean(coll);

View File

@@ -7,6 +7,8 @@ try {
console.log("Seems you forgot to create the file api_key.js in /server/config/. Have a look at api_key.example.js."); console.log("Seems you forgot to create the file api_key.js in /server/config/. Have a look at api_key.example.js.");
process.exit(); process.exit();
} }
var request = require('request');
var db = require(pathThumbnails + '/handlers/db.js');
function get_correct_info(song_generated, channel, broadcast, callback) { function get_correct_info(song_generated, channel, broadcast, callback) {
channel = channel.replace(/ /g,''); channel = channel.replace(/ /g,'');

View File

@@ -1,4 +1,7 @@
var Functions = require(pathThumbnails + '/handlers/functions.js');
var Notifications = require(pathThumbnails + '/handlers/notifications.js');
var crypto = require('crypto');
var db = require(pathThumbnails + '/handlers/db.js');
function thumbnail(msg, coll, guid, offline, socket) { function thumbnail(msg, coll, guid, offline, socket) {
if(msg.thumbnail != undefined && msg.channel && msg.channel != undefined && Functions.isUrl(msg.thumbnail)){ if(msg.thumbnail != undefined && msg.channel && msg.channel != undefined && Functions.isUrl(msg.thumbnail)){

View File

@@ -5,6 +5,7 @@ var mongojs = require('mongojs');
var ObjectId = mongojs.ObjectId; var ObjectId = mongojs.ObjectId;
var token_db = mongojs("tokens"); var token_db = mongojs("tokens");
var cookieParser = require("cookie-parser"); var cookieParser = require("cookie-parser");
var db = require(pathThumbnails + '/handlers/db.js');
var toShowChannel = { var toShowChannel = {
start: 1, start: 1,
@@ -112,7 +113,7 @@ router.route('/api/frontpages').get(function(req, res) {
db.collection("connected_users").find({"_id": "total_users"}, function(err, tot) { db.collection("connected_users").find({"_id": "total_users"}, function(err, tot) {
var to_return = error.no_error; var to_return = error.no_error;
to_return.results = {channels: docs, viewers: tot[0].total_users.length}; to_return.results = {channels: docs, viewers: tot[0].total_users.length};
res.status(200).send(JSON.stringify(to_return)); res.status(200).send(to_return);
return; return;
}); });
}); });
@@ -140,7 +141,7 @@ router.route('/api/list/:channel_name/:video_id').delete(function(req, res) {
}; };
var to_send = error.formatting; var to_send = error.formatting;
to_send.results.push(result); to_send.results.push(result);
res.status(400).send(JSON.stringify(to_send)); res.status(400).send(to_send);
return; return;
} }
var token = ""; var token = "";
@@ -171,7 +172,7 @@ router.route('/api/list/:channel_name/:video_id').delete(function(req, res) {
}; };
var to_send = error.formatting; var to_send = error.formatting;
to_send.results.push(result); to_send.results.push(result);
res.status(400).send(JSON.stringify(to_send)); res.status(400).send(to_send);
return; return;
} }
@@ -197,18 +198,18 @@ router.route('/api/list/:channel_name/:video_id').delete(function(req, res) {
checkTimeout(guid, res, authorized, "DELETE", function() { checkTimeout(guid, res, authorized, "DELETE", function() {
if(token != "" && !authorized) { if(token != "" && !authorized) {
updateTimeout(guid, res, authorized, "DELETE", function(err, docs) { updateTimeout(guid, res, authorized, "DELETE", function(err, docs) {
res.status(400).send(JSON.stringify(error.wrong_token)); res.status(400).send(error.wrong_token);
return; return;
}); });
} else { } else {
validateLogin(adminpass, userpass, channel_name, "delete", res, function(exists) { validateLogin(adminpass, userpass, channel_name, "delete", res, function(exists) {
if(!exists) { if(!exists) {
res.status(404).send(JSON.stringify(error.not_found.list)); res.status(404).send(error.not_found.list);
return; return;
} }
db.collection(channel_name).find({id:video_id, now_playing: false}, function(err, docs){ db.collection(channel_name).find({id:video_id, now_playing: false}, function(err, docs){
if(docs.length == 0) { if(docs.length == 0) {
res.status(404).send(JSON.stringify(error.not_found.local)); res.status(404).send(error.not_found.local);
return; return;
} }
var dont_increment = false; var dont_increment = false;
@@ -224,13 +225,13 @@ router.route('/api/list/:channel_name/:video_id').delete(function(req, res) {
if(!dont_increment) { if(!dont_increment) {
db.collection("frontpage_lists").update({_id: channel_name, count: {$gt: 0}}, {$inc: {count: -1}, $set:{accessed: Functions.get_time()}}, {upsert: true}, function(err, docs){ db.collection("frontpage_lists").update({_id: channel_name, count: {$gt: 0}}, {$inc: {count: -1}, $set:{accessed: Functions.get_time()}}, {upsert: true}, function(err, docs){
updateTimeout(guid, res, authorized, "DELETE", function(err, docs) { updateTimeout(guid, res, authorized, "DELETE", function(err, docs) {
res.status(200).send(JSON.stringify(error.no_error)); res.status(200).send(error.no_error);
return; return;
}); });
}); });
} else { } else {
updateTimeout(guid, res, authorized, "DELETE", function(err, docs) { updateTimeout(guid, res, authorized, "DELETE", function(err, docs) {
res.status(200).send(JSON.stringify(error.no_error)); res.status(200).send(error.no_error);
return; return;
}); });
} }
@@ -328,7 +329,7 @@ router.route('/api/conf/:channel_name').put(function(req, res) {
}; };
var to_send = error.formatting; var to_send = error.formatting;
to_send.results.push(result); to_send.results.push(result);
res.status(400).send(JSON.stringify(result)); res.status(400).send(result);
return; return;
} }
var cookie = req.cookies._uI; var cookie = req.cookies._uI;
@@ -352,13 +353,13 @@ router.route('/api/conf/:channel_name').put(function(req, res) {
checkTimeout(guid, res, authorized, "CONFIG", function() { checkTimeout(guid, res, authorized, "CONFIG", function() {
if(token != "" && !authorized) { if(token != "" && !authorized) {
updateTimeout(guid, res, authorized, "CONFIG", function(err, docs) { updateTimeout(guid, res, authorized, "CONFIG", function(err, docs) {
res.status(400).send(JSON.stringify(error.wrong_token)); res.status(400).send(error.wrong_token);
return; return;
}); });
} else { } else {
validateLogin(adminpass, userpass, channel_name, "config", res, function(exists, conf) { validateLogin(adminpass, userpass, channel_name, "config", res, function(exists, conf) {
if(!exists && conf.length == 0) { if(!exists && conf.length == 0) {
res.status(404).send(JSON.stringify(error.not_found.list)); res.status(404).send(error.not_found.list);
return; return;
} }
@@ -405,7 +406,7 @@ router.route('/api/conf/:channel_name').put(function(req, res) {
updateTimeout(guid, res, authorized, "CONFIG", function(err, docs) { updateTimeout(guid, res, authorized, "CONFIG", function(err, docs) {
var to_return = error.no_error; var to_return = error.no_error;
to_return.results = [obj]; to_return.results = [obj];
res.status(200).send(JSON.stringify(to_return)); res.status(200).send(to_return);
return; return;
}); });
}); });
@@ -454,7 +455,7 @@ router.route('/api/list/:channel_name/:video_id').put(function(req,res) {
}; };
var to_send = error.formatting; var to_send = error.formatting;
to_send.results.push(result); to_send.results.push(result);
res.status(400).send(JSON.stringify(to_send)); res.status(400).send(to_send);
return; return;
} }
var cookie = req.cookies._uI; var cookie = req.cookies._uI;
@@ -478,21 +479,21 @@ router.route('/api/list/:channel_name/:video_id').put(function(req,res) {
checkTimeout(guid, res, authorized, "PUT", function() { checkTimeout(guid, res, authorized, "PUT", function() {
if(token != "" && !authorized) { if(token != "" && !authorized) {
updateTimeout(guid, res, authorized, "PUT", function(err, docs) { updateTimeout(guid, res, authorized, "PUT", function(err, docs) {
res.status(400).send(JSON.stringify(error.wrong_token)); res.status(400).send(error.wrong_token);
return; return;
}); });
} else { } else {
validateLogin(adminpass, userpass, channel_name, "vote", res, function(exists) { validateLogin(adminpass, userpass, channel_name, "vote", res, function(exists) {
if(!exists) { if(!exists) {
res.status(404).send(JSON.stringify(error.not_found.list)); res.status(404).send(error.not_found.list);
return; return;
} }
db.collection(channel_name).find({id: video_id, now_playing: false}, function(err, song) { db.collection(channel_name).find({id: video_id, now_playing: false}, function(err, song) {
if(song.length == 0 || (song.hasOwnProperty("type") && song.type == "suggested")) { if(song.length == 0 || (song.hasOwnProperty("type") && song.type == "suggested")) {
res.status(404).send(JSON.stringify(error.not_found.local)); res.status(404).send(error.not_found.local);
return; return;
} else if(song[0].guids.indexOf(guid) > -1) { } else if(song[0].guids.indexOf(guid) > -1) {
res.status(409).send(JSON.stringify(error.conflicting)); res.status(409).send(error.conflicting);
return; return;
} else { } else {
song[0].votes += 1; song[0].votes += 1;
@@ -506,7 +507,7 @@ router.route('/api/list/:channel_name/:video_id').put(function(req,res) {
updateTimeout(guid, res, authorized, "PUT", function(err, docs) { updateTimeout(guid, res, authorized, "PUT", function(err, docs) {
var to_return = error.no_error; var to_return = error.no_error;
to_return.results = song; to_return.results = song;
res.status(200).send(JSON.stringify(to_return)); res.status(200).send(to_return);
return; return;
}); });
}); });
@@ -551,7 +552,7 @@ router.route('/api/list/:channel_name/__np__').post(function(req, res) {
}; };
var to_send = error.formatting; var to_send = error.formatting;
to_send.results.push(result); to_send.results.push(result);
res.status(400).send(JSON.stringify(to_send)); res.status(400).send(to_send);
return; return;
} }
var cookie = req.cookies._uI; var cookie = req.cookies._uI;
@@ -572,7 +573,7 @@ router.route('/api/list/:channel_name/__np__').post(function(req, res) {
checkTimeout(guid, res, authorized, "POST", function() { checkTimeout(guid, res, authorized, "POST", function() {
if(token != "" && !authorized) { if(token != "" && !authorized) {
updateTimeout(guid, res, authorized, "POST", function(err, docs) { updateTimeout(guid, res, authorized, "POST", function(err, docs) {
res.status(400).send(JSON.stringify(error.wrong_token)); res.status(400).send(error.wrong_token);
return; return;
}); });
} else { } else {
@@ -583,10 +584,10 @@ router.route('/api/list/:channel_name/__np__').post(function(req, res) {
incrementToken(token); incrementToken(token);
} }
if(conf.length == 0) { if(conf.length == 0) {
res.status(404).send(JSON.stringify(error.not_found.list)); res.status(404).send(error.not_found.list);
return; return;
} else if(conf[0].userpass != userpass && conf[0].userpass != "" && conf[0].userpass != undefined) { } else if(conf[0].userpass != userpass && conf[0].userpass != "" && conf[0].userpass != undefined) {
res.status(403).send(JSON.stringify(error.not_authenticated)); res.status(403).send(error.not_authenticated);
return; return;
} }
updateTimeout(guid, res, authorized, "POST", function(err, docs) { updateTimeout(guid, res, authorized, "POST", function(err, docs) {
@@ -598,12 +599,12 @@ router.route('/api/list/:channel_name/__np__').post(function(req, res) {
list[0].thumbnail = "https://img.youtube.com/vi/" + list[0].id + "/mqdefault.jpg" list[0].thumbnail = "https://img.youtube.com/vi/" + list[0].id + "/mqdefault.jpg"
} }
to_return.results = list; to_return.results = list;
res.status(200).send(JSON.stringify(to_return)); res.status(200).send(to_return);
return; return;
}); });
}); });
} else { } else {
res.status(404).send(JSON.stringify(error.not_found.list)); res.status(404).send(error.not_found.list);
return; return;
} }
}); });
@@ -686,7 +687,7 @@ router.route('/api/list/:channel_name/:video_id').post(function(req,res) {
}; };
var to_send = error.formatting; var to_send = error.formatting;
to_send.results.push(result); to_send.results.push(result);
res.status(400).send(JSON.stringify(to_send)); res.status(400).send(to_send);
return; return;
} }
var cookie = req.cookies._uI; var cookie = req.cookies._uI;
@@ -710,7 +711,7 @@ router.route('/api/list/:channel_name/:video_id').post(function(req,res) {
checkTimeout(guid, res, authorized, "POST", function() { checkTimeout(guid, res, authorized, "POST", function() {
if(token != "" && !authorized) { if(token != "" && !authorized) {
updateTimeout(guid, res, authorized, "POST", function(err, docs) { updateTimeout(guid, res, authorized, "POST", function(err, docs) {
res.status(400).send(JSON.stringify(error.wrong_token)); res.status(400).send(error.wrong_token);
return; return;
}); });
} else { } else {
@@ -720,7 +721,7 @@ router.route('/api/list/:channel_name/:video_id').post(function(req,res) {
if(result.length == 0 || result[0].type == "suggested") { if(result.length == 0 || result[0].type == "suggested") {
var song_type = authenticated ? "video" : "suggested"; var song_type = authenticated ? "video" : "suggested";
if(fetch_only && result.length == 0) { if(fetch_only && result.length == 0) {
res.status(404).send(JSON.stringify(error.not_found.local)); res.status(404).send(error.not_found.local);
return; return;
} }
db.collection(channel_name).find({now_playing: true}, function(err, now_playing) { db.collection(channel_name).find({now_playing: true}, function(err, now_playing) {
@@ -742,7 +743,7 @@ router.route('/api/list/:channel_name/:video_id').post(function(req,res) {
} else if(source == "youtube") new_song.thumbnail = "https://img.youtube.com/vi/" + new_song.id + "/mqdefault.jpg"; } else if(source == "youtube") new_song.thumbnail = "https://img.youtube.com/vi/" + new_song.id + "/mqdefault.jpg";
runFunction(new_song, channel_name, false, function(element, found) { runFunction(new_song, channel_name, false, function(element, found) {
if(!found) { if(!found) {
res.status(404).send(JSON.stringify(error.not_found.youtube)); res.status(404).send(error.not_found.youtube);
return; return;
} }
new_song = element; new_song = element;
@@ -793,10 +794,10 @@ router.route('/api/list/:channel_name/:video_id').post(function(req,res) {
} else if(fetch_only) { } else if(fetch_only) {
var to_return = error.no_error; var to_return = error.no_error;
to_return.results = result; to_return.results = result;
res.status(200).send(JSON.stringify(to_return)); res.status(200).send(to_return);
return; return;
} else { } else {
res.status(409).send(JSON.stringify(error.conflicting)); res.status(409).send(error.conflicting);
return; return;
} }
}); });
@@ -844,18 +845,18 @@ router.route('/api/list/:channel_name').get(function(req, res) {
if(docs.length > 0) { if(docs.length > 0) {
db.collection(channel_name + "_settings").find({ id: "config" }, function(err, conf) { db.collection(channel_name + "_settings").find({ id: "config" }, function(err, conf) {
if(conf.length == 0) { if(conf.length == 0) {
res.status(404).send(JSON.stringify(error.not_found.list)); res.status(404).send(error.not_found.list);
return; return;
} else if(conf[0].userpass != "" && conf[0].userpass != undefined) { } else if(conf[0].userpass != "" && conf[0].userpass != undefined) {
res.status(403).send(JSON.stringify(error.not_authenticated)); res.status(403).send(error.not_authenticated);
return; return;
} }
var to_return = error.no_error; var to_return = error.no_error;
to_return.results = docs; to_return.results = docs;
res.status(200).send(JSON.stringify(to_return)); res.status(200).send(to_return);
}); });
} else { } else {
res.status(404).send(JSON.stringify(error.not_found.list)); res.status(404).send(error.not_found.list);
} }
}); });
}); });
@@ -874,14 +875,14 @@ router.route('/api/list/:channel_name/:video_id').get(function(req, res) {
db.collection(channel_name).find(searchQuery, toShowChannel, function(err, docs) { db.collection(channel_name).find(searchQuery, toShowChannel, function(err, docs) {
db.collection(channel_name + "_settings").find({ id: "config" }, function(err, conf) { db.collection(channel_name + "_settings").find({ id: "config" }, function(err, conf) {
if(conf.length == 0) { if(conf.length == 0) {
res.status(404).send(JSON.stringify(error.not_found.list)); res.status(404).send(error.not_found.list);
return; return;
} else if(conf[0].userpass != "" && conf[0].userpass != undefined) { } else if(conf[0].userpass != "" && conf[0].userpass != undefined) {
res.status(403).send(JSON.stringify(error.not_authenticated)); res.status(403).send(error.not_authenticated);
return; return;
} }
if(docs.length == 0) { if(docs.length == 0) {
res.status(404).send(JSON.stringify(error.not_found.local)); res.status(404).send(error.not_found.local);
return; return;
} }
var to_return = error.no_error; var to_return = error.no_error;
@@ -892,7 +893,7 @@ router.route('/api/list/:channel_name/:video_id').get(function(req, res) {
docs[0].thumbnail = "https://img.youtube.com/vi/" + docs[0].id + "/mqdefault.jpg" docs[0].thumbnail = "https://img.youtube.com/vi/" + docs[0].id + "/mqdefault.jpg"
} }
to_return.results = docs; to_return.results = docs;
res.status(200).send(JSON.stringify(to_return)); res.status(200).send(to_return);
return; return;
}); });
}); });
@@ -919,12 +920,12 @@ router.route('/api/conf/:channel_name').get(function(req, res) {
} }
var to_return = error.no_error; var to_return = error.no_error;
to_return.results = [conf]; to_return.results = [conf];
res.status(200).send(JSON.stringify(to_return)); res.status(200).send(to_return);
} else if(docs.length > 0 && docs[0].userpass != "" && docs[0].userpass != undefined){ } else if(docs.length > 0 && docs[0].userpass != "" && docs[0].userpass != undefined){
res.status(403).send(JSON.stringify(error.not_authenticated)); res.status(403).send(error.not_authenticated);
return; return;
} else { } else {
res.status(404).send(JSON.stringify(error.not_found.list)); res.status(404).send(error.not_found.list);
return; return;
} }
}); });
@@ -961,7 +962,7 @@ router.route('/api/conf/:channel_name').post(function(req, res) {
}; };
var to_send = error.formatting; var to_send = error.formatting;
to_send.results.push(result); to_send.results.push(result);
res.status(400).send(JSON.stringify(to_send)); res.status(400).send(to_send);
return; return;
} }
var cookie = req.cookies._uI; var cookie = req.cookies._uI;
@@ -983,7 +984,7 @@ router.route('/api/conf/:channel_name').post(function(req, res) {
checkTimeout(guid, res, authorized, "POST", function() { checkTimeout(guid, res, authorized, "POST", function() {
if(token != "" && !authorized) { if(token != "" && !authorized) {
updateTimeout(guid, res, authorized, "DELETE", function(err, docs) { updateTimeout(guid, res, authorized, "DELETE", function(err, docs) {
res.status(400).send(JSON.stringify(error.wrong_token)); res.status(400).send(error.wrong_token);
return; return;
}); });
} else { } else {
@@ -1006,13 +1007,13 @@ router.route('/api/conf/:channel_name').post(function(req, res) {
updateTimeout(guid, res, authorized, "POST", function(err, docs) { updateTimeout(guid, res, authorized, "POST", function(err, docs) {
var to_return = error.no_error; var to_return = error.no_error;
to_return.results = [conf]; to_return.results = [conf];
res.status(200).send(JSON.stringify(to_return)); res.status(200).send(to_return);
}); });
} else if(docs.length > 0 && docs[0].userpass != userpass) { } else if(docs.length > 0 && docs[0].userpass != userpass) {
res.status(403).send(JSON.stringify(error.not_authenticated)); res.status(403).send(error.not_authenticated);
return; return;
} else { } else {
res.status(404).send(JSON.stringify(error.not_found.list)); res.status(404).send(error.not_found.list);
return; return;
} }
}); });
@@ -1037,7 +1038,7 @@ function checkOveruseApiToken(authorized, token_docs, res, callback) {
var retry_in = (date.getTime() - now.getTime()) / 1000; var retry_in = (date.getTime() - now.getTime()) / 1000;
if(this_doc.used > token_docs[0].limit && retry_in > 0) { if(this_doc.used > token_docs[0].limit && retry_in > 0) {
res.header({'Retry-After': retry_in}); res.header({'Retry-After': retry_in});
res.status(429).send(JSON.stringify(error.tooMany)); res.status(429).send(error.tooMany);
return; return;
} else { } else {
db.collection("timeout_api").update({guid: token_docs[0].token}, {$inc: {used: 1}}, function(e, d) { db.collection("timeout_api").update({guid: token_docs[0].token}, {$inc: {used: 1}}, function(e, d) {
@@ -1083,7 +1084,7 @@ router.route('/api/list/:channel_name').post(function(req, res) {
}; };
var to_send = error.formatting; var to_send = error.formatting;
to_send.results.push(result); to_send.results.push(result);
res.status(400).send(JSON.stringify(to_send)); res.status(400).send(to_send);
return; return;
} }
@@ -1107,7 +1108,7 @@ router.route('/api/list/:channel_name').post(function(req, res) {
checkTimeout(guid, res, authorized, "POST", function() { checkTimeout(guid, res, authorized, "POST", function() {
if(token != "" && !authorized) { if(token != "" && !authorized) {
updateTimeout(guid, res, authorized, "POST", function(err, docs) { updateTimeout(guid, res, authorized, "POST", function(err, docs) {
res.status(400).send(JSON.stringify(error.wrong_token)); res.status(400).send(error.wrong_token);
return; return;
}); });
} else { } else {
@@ -1141,10 +1142,10 @@ router.route('/api/list/:channel_name').post(function(req, res) {
if(list.length > 0) { if(list.length > 0) {
db.collection(channel_name + "_settings").find({ id: "config" }, function(err, conf) { db.collection(channel_name + "_settings").find({ id: "config" }, function(err, conf) {
if(conf.length == 0) { if(conf.length == 0) {
res.status(404).send(JSON.stringify(error.not_found.list)); res.status(404).send(error.not_found.list);
return; return;
} else if(conf[0].userpass != userpass && conf[0].userpass != "" && conf[0].userpass != undefined) { } else if(conf[0].userpass != userpass && conf[0].userpass != "" && conf[0].userpass != undefined) {
res.status(403).send(JSON.stringify(error.not_authenticated)); res.status(403).send(error.not_authenticated);
return; return;
} }
if(authorized) { if(authorized) {
@@ -1153,12 +1154,12 @@ router.route('/api/list/:channel_name').post(function(req, res) {
updateTimeout(guid, res, authorized, "POST", function(err, docs) { updateTimeout(guid, res, authorized, "POST", function(err, docs) {
var to_return = error.no_error; var to_return = error.no_error;
to_return.results = list; to_return.results = list;
res.status(200).send(JSON.stringify(to_return)); res.status(200).send(to_return);
return; return;
}); });
}); });
} else { } else {
res.status(404).send(JSON.stringify(error.not_found.list)); res.status(404).send(error.not_found.list);
return; return;
} }
}); });
@@ -1374,7 +1375,7 @@ function checkTimeout(guid, res, authorized, type, callback) {
var retry_in = (date.getTime() - now.getTime()) / 1000; var retry_in = (date.getTime() - now.getTime()) / 1000;
if(retry_in > 0) { if(retry_in > 0) {
res.header({'Retry-After': retry_in}); res.header({'Retry-After': retry_in});
res.status(429).send(JSON.stringify(error.tooMany)); res.status(429).send(error.tooMany);
return; return;
} }
} }
@@ -1396,10 +1397,10 @@ function validateLogin(adminpass, userpass, channel_name, type, res, callback) {
if(conf.length > 0 && ((conf[0].userpass == undefined || conf[0].userpass == "" || conf[0].userpass == userpass))) { if(conf.length > 0 && ((conf[0].userpass == undefined || conf[0].userpass == "" || conf[0].userpass == userpass))) {
exists = true; exists = true;
} else if(conf.length > 0 && type == "config") { } else if(conf.length > 0 && type == "config") {
res.status(404).send(JSON.stringify(error.not_found.list)); res.status(404).send(error.not_found.list);
return; return;
} else if(conf.length == 0) { } else if(conf.length == 0) {
res.status(404).send(JSON.stringify(error.not_found.list)); res.status(404).send(error.not_found.list);
return; return;
} }
@@ -1414,7 +1415,7 @@ function validateLogin(adminpass, userpass, channel_name, type, res, callback) {
} else if(type == "add") { } else if(type == "add") {
callback(exists, conf, false); callback(exists, conf, false);
} else { } else {
res.status(403).send(JSON.stringify(error.not_authenticated)); res.status(403).send(error.not_authenticated);
return; return;
} }
}); });
@@ -1432,7 +1433,7 @@ function postEnd(channel_name, configs, new_song, guid, res, authenticated, auth
to_return.success = true; to_return.success = true;
} }
to_return.results = [new_song]; to_return.results = [new_song];
res.status(authenticated ? 200 : 403).send(JSON.stringify(to_return)); res.status(authenticated ? 200 : 403).send(to_return);
return; return;
}); });
}); });