mirror of
				https://github.com/KevinMidboe/zoff.git
				synced 2025-10-29 18:00:23 +00:00 
			
		
		
		
	Add linting and unused cleanup
This commit is contained in:
		| @@ -10,12 +10,24 @@ var toShowConfig = { | |||||||
|   startTime: 1, |   startTime: 1, | ||||||
|   userpass: 1, |   userpass: 1, | ||||||
|   vote: 1, |   vote: 1, | ||||||
|   toggleChat: { $ifNull: ["$toggleChat", true] }, |   toggleChat: { | ||||||
|   strictSkip: { $ifNull: ["$strictSkip", false] }, |     $ifNull: ["$toggleChat", true] | ||||||
|   strictSkipNumber: { $ifNull: ["$strictSkipNumber", 10] }, |   }, | ||||||
|   description: { $ifNull: ["$description", ""] }, |   strictSkip: { | ||||||
|   thumbnail: { $ifNull: ["$thumbnail", ""] }, |     $ifNull: ["$strictSkip", false] | ||||||
|   rules: { $ifNull: ["$rules", ""] }, |   }, | ||||||
|  |   strictSkipNumber: { | ||||||
|  |     $ifNull: ["$strictSkipNumber", 10] | ||||||
|  |   }, | ||||||
|  |   description: { | ||||||
|  |     $ifNull: ["$description", ""] | ||||||
|  |   }, | ||||||
|  |   thumbnail: { | ||||||
|  |     $ifNull: ["$thumbnail", ""] | ||||||
|  |   }, | ||||||
|  |   rules: { | ||||||
|  |     $ifNull: ["$rules", ""] | ||||||
|  |   }, | ||||||
|   _id: 0 |   _id: 0 | ||||||
| }; | }; | ||||||
|  |  | ||||||
| @@ -30,8 +42,12 @@ var project_object = { | |||||||
|   duration: 1, |   duration: 1, | ||||||
|   end: 1, |   end: 1, | ||||||
|   type: 1, |   type: 1, | ||||||
|   added_by: { $ifNull: ["$added_by", "Anonymous"] }, |   added_by: { | ||||||
|   source: { $ifNull: ["$source", "youtube"] }, |     $ifNull: ["$added_by", "Anonymous"] | ||||||
|  |   }, | ||||||
|  |   source: { | ||||||
|  |     $ifNull: ["$source", "youtube"] | ||||||
|  |   }, | ||||||
|   thumbnail: { |   thumbnail: { | ||||||
|     $ifNull: [ |     $ifNull: [ | ||||||
|       "$thumbnail", |       "$thumbnail", | ||||||
| @@ -40,7 +56,9 @@ var project_object = { | |||||||
|       } |       } | ||||||
|     ] |     ] | ||||||
|   }, |   }, | ||||||
|   tags: { $ifNull: ["$tags", []] } |   tags: { | ||||||
|  |     $ifNull: ["$tags", []] | ||||||
|  |   } | ||||||
| }; | }; | ||||||
|  |  | ||||||
| var toShowChannel = { | var toShowChannel = { | ||||||
| @@ -62,4 +80,4 @@ var toShowChannel = { | |||||||
|  |  | ||||||
| module.exports.project_object = project_object; | module.exports.project_object = project_object; | ||||||
| module.exports.toShowConfig = toShowConfig; | module.exports.toShowConfig = toShowConfig; | ||||||
| module.exports.toShowChannel = toShowChannel; | module.exports.toShowChannel = toShowChannel; | ||||||
| @@ -1,12 +1,5 @@ | |||||||
| var Functions = require(pathThumbnails + "/handlers/functions.js"); | var Functions = require(pathThumbnails + "/handlers/functions.js"); | ||||||
| var crypto = require("crypto"); | var crypto = require("crypto"); | ||||||
| var Filter = require("bad-words"); |  | ||||||
| var filter = new Filter({ placeHolder: "x" }); |  | ||||||
| /*var filter = { |  | ||||||
| clean: function(str) { |  | ||||||
| return str; |  | ||||||
| } |  | ||||||
| }*/ |  | ||||||
| var db = require(pathThumbnails + "/handlers/db.js"); | var db = require(pathThumbnails + "/handlers/db.js"); | ||||||
|  |  | ||||||
| function get_history(channel, all, socket) { | function get_history(channel, all, socket) { | ||||||
| @@ -27,7 +20,7 @@ function get_history(channel, all, socket) { | |||||||
|     Functions.getSessionAdminUser( |     Functions.getSessionAdminUser( | ||||||
|       Functions.getSession(socket), |       Functions.getSession(socket), | ||||||
|       channel, |       channel, | ||||||
|       function(userpass) { |       function (userpass) { | ||||||
|         if (userpass != "" || pass == undefined) { |         if (userpass != "" || pass == undefined) { | ||||||
|           pass = userpass; |           pass = userpass; | ||||||
|         } else { |         } else { | ||||||
| @@ -36,7 +29,9 @@ function get_history(channel, all, socket) { | |||||||
|             .update(Functions.decrypt_string(pass)) |             .update(Functions.decrypt_string(pass)) | ||||||
|             .digest("base64"); |             .digest("base64"); | ||||||
|         } |         } | ||||||
|         db.collection(channel + "_settings").find({ id: "config" }, function( |         db.collection(channel + "_settings").find({ | ||||||
|  |           id: "config" | ||||||
|  |         }, function ( | ||||||
|           err, |           err, | ||||||
|           conf |           conf | ||||||
|         ) { |         ) { | ||||||
| @@ -65,14 +60,21 @@ function getAndSendLogs(channel, all, socket, pass, query) { | |||||||
|       icon: 1, |       icon: 1, | ||||||
|       _id: 0 |       _id: 0 | ||||||
|     }) |     }) | ||||||
|     .sort({ createdAt: 1 }) |     .sort({ | ||||||
|     .limit(20, function(err, docs) { |       createdAt: 1 | ||||||
|       socket.emit("chat_history", { all: all, data: docs }); |     }) | ||||||
|  |     .limit(20, function (err, docs) { | ||||||
|  |       socket.emit("chat_history", { | ||||||
|  |         all: all, | ||||||
|  |         data: docs | ||||||
|  |       }); | ||||||
|     }); |     }); | ||||||
| } | } | ||||||
|  |  | ||||||
| function getUserNameByGuid(guid, callback) { | function getUserNameByGuid(guid, callback) { | ||||||
|   db.collection("user_names").find({ guid: guid }, function(err, usernames) { |   db.collection("user_names").find({ | ||||||
|  |     guid: guid | ||||||
|  |   }, function (err, usernames) { | ||||||
|     if (usernames.length == 1) { |     if (usernames.length == 1) { | ||||||
|       callback(usernames[0].name); |       callback(usernames[0].name); | ||||||
|       return; |       return; | ||||||
| @@ -110,8 +112,8 @@ function chat(msg, guid, offline, socket) { | |||||||
|   coll = Functions.removeEmojis(coll).toLowerCase(); |   coll = Functions.removeEmojis(coll).toLowerCase(); | ||||||
|   //coll = filter.clean(coll); |   //coll = filter.clean(coll); | ||||||
|  |  | ||||||
|   checkIfUserIsBanned(coll, socket, guid, function() { |   checkIfUserIsBanned(coll, socket, guid, function () { | ||||||
|     Functions.getSessionAdminUser(Functions.getSession(socket), coll, function( |     Functions.getSessionAdminUser(Functions.getSession(socket), coll, function ( | ||||||
|       userpass, |       userpass, | ||||||
|       adminpass |       adminpass | ||||||
|     ) { |     ) { | ||||||
| @@ -123,7 +125,7 @@ function chat(msg, guid, offline, socket) { | |||||||
|           .update(Functions.decrypt_string(msg.pass)) |           .update(Functions.decrypt_string(msg.pass)) | ||||||
|           .digest("base64"); |           .digest("base64"); | ||||||
|       } |       } | ||||||
|       db.collection(coll + "_settings").find(function(err, conf) { |       db.collection(coll + "_settings").find(function (err, conf) { | ||||||
|         if ( |         if ( | ||||||
|           conf.length > 0 && |           conf.length > 0 && | ||||||
|           (conf[0].hasOwnProperty("toggleChat") && !conf[0].toggleChat) |           (conf[0].hasOwnProperty("toggleChat") && !conf[0].toggleChat) | ||||||
| @@ -147,18 +149,18 @@ function chat(msg, guid, offline, socket) { | |||||||
|             guid, |             guid, | ||||||
|             socket, |             socket, | ||||||
|             offline, |             offline, | ||||||
|             function() { |             function () { | ||||||
|               if (data == "/who") { |               if (data == "/who") { | ||||||
|                 db.collection("user_names").distinct( |                 db.collection("user_names").distinct( | ||||||
|                   "name", |                   "name", { | ||||||
|                   { channels: coll }, |                     channels: coll | ||||||
|                   function(err, docs) { |                   }, | ||||||
|  |                   function (err, docs) { | ||||||
|                     var userAdd = "s"; |                     var userAdd = "s"; | ||||||
|                     if (docs.length == 1) userAdd = ""; |                     if (docs.length == 1) userAdd = ""; | ||||||
|                     socket.emit("chat", { |                     socket.emit("chat", { | ||||||
|                       from: "System", |                       from: "System", | ||||||
|                       msg: |                       msg: ": User" + | ||||||
|                         ": User" + |  | ||||||
|                         userAdd + |                         userAdd + | ||||||
|                         " in channel are: " + |                         " in channel are: " + | ||||||
|                         docs.join(", "), |                         docs.join(", "), | ||||||
| @@ -173,7 +175,9 @@ function chat(msg, guid, offline, socket) { | |||||||
|                 data.length < 151 && |                 data.length < 151 && | ||||||
|                 data.replace(/\s/g, "").length |                 data.replace(/\s/g, "").length | ||||||
|               ) { |               ) { | ||||||
|                 db.collection("user_names").find({ guid: guid }, function( |                 db.collection("user_names").find({ | ||||||
|  |                   guid: guid | ||||||
|  |                 }, function ( | ||||||
|                   err, |                   err, | ||||||
|                   docs |                   docs | ||||||
|                 ) { |                 ) { | ||||||
| @@ -186,9 +190,10 @@ function chat(msg, guid, offline, socket) { | |||||||
|                       if (splitData[1].length > 0) { |                       if (splitData[1].length > 0) { | ||||||
|                         var passToCompare = Functions.hash_pass(adminpass); |                         var passToCompare = Functions.hash_pass(adminpass); | ||||||
|                         if (passToCompare == conf[0].adminpass) { |                         if (passToCompare == conf[0].adminpass) { | ||||||
|                           db.collection("user_names").find( |                           db.collection("user_names").find({ | ||||||
|                             { name: splitData[1] }, |                               name: splitData[1] | ||||||
|                             function(err, name) { |                             }, | ||||||
|  |                             function (err, name) { | ||||||
|                               if (name.length == 1) { |                               if (name.length == 1) { | ||||||
|                                 if ( |                                 if ( | ||||||
|                                   data.startsWith("/ban") && |                                   data.startsWith("/ban") && | ||||||
| @@ -200,36 +205,31 @@ function chat(msg, guid, offline, socket) { | |||||||
|                                   var connection_id = name[0].connection_id; |                                   var connection_id = name[0].connection_id; | ||||||
|                                   var yourSelf = Functions.hash_pass( |                                   var yourSelf = Functions.hash_pass( | ||||||
|                                     socket.handshake.headers["user-agent"] + |                                     socket.handshake.headers["user-agent"] + | ||||||
|                                       socket.handshake.address + |                                     socket.handshake.address + | ||||||
|                                       socket.handshake.headers[ |                                     socket.handshake.headers[ | ||||||
|                                         "accept-language" |                                       "accept-language" | ||||||
|                                       ] |                                     ] | ||||||
|                                   ); |                                   ); | ||||||
|                                   if (connection_id != yourSelf) { |                                   if (connection_id != yourSelf) { | ||||||
|                                     db.collection(coll + "_banned_chat").update( |                                     db.collection(coll + "_banned_chat").update({ | ||||||
|                                       { |  | ||||||
|                                         connection_id: connection_id |                                         connection_id: connection_id | ||||||
|                                       }, |                                       }, { | ||||||
|                                       { |  | ||||||
|                                         connection_id: connection_id, |                                         connection_id: connection_id, | ||||||
|                                         by: docs[0].name, |                                         by: docs[0].name, | ||||||
|                                         reason: reason |                                         reason: reason | ||||||
|                                       }, |                                       }, { | ||||||
|                                       { |  | ||||||
|                                         upsert: true |                                         upsert: true | ||||||
|                                       }, |                                       }, | ||||||
|                                       function(err, results) { |                                       function (err, results) { | ||||||
|                                         io.to(coll).emit("chat", { |                                         io.to(coll).emit("chat", { | ||||||
|                                           from: "System", |                                           from: "System", | ||||||
|                                           msg: |                                           msg: ": " + | ||||||
|                                             ": " + |  | ||||||
|                                             docs[0].name + |                                             docs[0].name + | ||||||
|                                             " has banned " + |                                             " has banned " + | ||||||
|                                             splitData[1] + |                                             splitData[1] + | ||||||
|                                             " for: " + |                                             " for: " + | ||||||
|                                             reason, |                                             reason, | ||||||
|                                           icon: |                                           icon: "https://zoff.me/assets/images/favicon-32x32.png" | ||||||
|                                             "https://zoff.me/assets/images/favicon-32x32.png" |  | ||||||
|                                         }); |                                         }); | ||||||
|                                         return; |                                         return; | ||||||
|                                       } |                                       } | ||||||
| @@ -237,17 +237,16 @@ function chat(msg, guid, offline, socket) { | |||||||
|                                   } else { |                                   } else { | ||||||
|                                     socket.emit("chat", { |                                     socket.emit("chat", { | ||||||
|                                       from: "System", |                                       from: "System", | ||||||
|                                       msg: |                                       msg: ": I'm sorry but you can't ban yourself..", | ||||||
|                                         ": I'm sorry but you can't ban yourself..", |                                       icon: "https://zoff.me/assets/images/favicon-32x32.png" | ||||||
|                                       icon: |  | ||||||
|                                         "https://zoff.me/assets/images/favicon-32x32.png" |  | ||||||
|                                     }); |                                     }); | ||||||
|                                     return; |                                     return; | ||||||
|                                   } |                                   } | ||||||
|                                 } else if (data.startsWith("/unban")) { |                                 } else if (data.startsWith("/unban")) { | ||||||
|                                   db.collection(coll + "_banned_chat").remove( |                                   db.collection(coll + "_banned_chat").remove({ | ||||||
|                                     { connection_id: name[0].connection_id }, |                                       connection_id: name[0].connection_id | ||||||
|                                     function(err, results) { |                                     }, | ||||||
|  |                                     function (err, results) { | ||||||
|                                       if ( |                                       if ( | ||||||
|                                         results.hasOwnProperty("n") && |                                         results.hasOwnProperty("n") && | ||||||
|                                         results.n == 1 && |                                         results.n == 1 && | ||||||
| @@ -258,22 +257,18 @@ function chat(msg, guid, offline, socket) { | |||||||
|                                       ) { |                                       ) { | ||||||
|                                         io.to(coll).emit("chat", { |                                         io.to(coll).emit("chat", { | ||||||
|                                           from: "System", |                                           from: "System", | ||||||
|                                           msg: |                                           msg: ": " + | ||||||
|                                             ": " + |  | ||||||
|                                             docs[0].name + |                                             docs[0].name + | ||||||
|                                             " has unbanned " + |                                             " has unbanned " + | ||||||
|                                             splitData[1], |                                             splitData[1], | ||||||
|                                           icon: |                                           icon: "https://zoff.me/assets/images/favicon-32x32.png" | ||||||
|                                             "https://zoff.me/assets/images/favicon-32x32.png" |  | ||||||
|                                         }); |                                         }); | ||||||
|                                         return; |                                         return; | ||||||
|                                       } else { |                                       } else { | ||||||
|                                         socket.emit("chat", { |                                         socket.emit("chat", { | ||||||
|                                           from: "System", |                                           from: "System", | ||||||
|                                           msg: |                                           msg: ": Cannot find anyone with that username in this chat.", | ||||||
|                                             ": Cannot find anyone with that username in this chat.", |                                           icon: "https://zoff.me/assets/images/favicon-32x32.png" | ||||||
|                                           icon: |  | ||||||
|                                             "https://zoff.me/assets/images/favicon-32x32.png" |  | ||||||
|                                         }); |                                         }); | ||||||
|                                         return; |                                         return; | ||||||
|                                       } |                                       } | ||||||
| @@ -285,10 +280,8 @@ function chat(msg, guid, offline, socket) { | |||||||
|                                 ) { |                                 ) { | ||||||
|                                   socket.emit("chat", { |                                   socket.emit("chat", { | ||||||
|                                     from: "System", |                                     from: "System", | ||||||
|                                     msg: |                                     msg: ": You are doing that command wrong. its /ban USERNAME", | ||||||
|                                       ": You are doing that command wrong. its /ban USERNAME", |                                     icon: "https://zoff.me/assets/images/favicon-32x32.png" | ||||||
|                                     icon: |  | ||||||
|                                       "https://zoff.me/assets/images/favicon-32x32.png" |  | ||||||
|                                   }); |                                   }); | ||||||
|                                   return; |                                   return; | ||||||
|                                 } |                                 } | ||||||
| @@ -296,8 +289,7 @@ function chat(msg, guid, offline, socket) { | |||||||
|                                 socket.emit("chat", { |                                 socket.emit("chat", { | ||||||
|                                   from: "System", |                                   from: "System", | ||||||
|                                   msg: ": No user by that name.", |                                   msg: ": No user by that name.", | ||||||
|                                   icon: |                                   icon: "https://zoff.me/assets/images/favicon-32x32.png" | ||||||
|                                     "https://zoff.me/assets/images/favicon-32x32.png" |  | ||||||
|                                 }); |                                 }); | ||||||
|                                 return; |                                 return; | ||||||
|                               } |                               } | ||||||
| @@ -306,27 +298,24 @@ function chat(msg, guid, offline, socket) { | |||||||
|                         } else { |                         } else { | ||||||
|                           socket.emit("chat", { |                           socket.emit("chat", { | ||||||
|                             from: "System", |                             from: "System", | ||||||
|                             msg: |                             msg: ": You are not logged in as an admin to the channel, don't try any funnybusiness.", | ||||||
|                               ": You are not logged in as an admin to the channel, don't try any funnybusiness.", |                             icon: "https://zoff.me/assets/images/favicon-32x32.png" | ||||||
|                             icon: |  | ||||||
|                               "https://zoff.me/assets/images/favicon-32x32.png" |  | ||||||
|                           }); |                           }); | ||||||
|                           return; |                           return; | ||||||
|                         } |                         } | ||||||
|                       } else { |                       } else { | ||||||
|                         socket.emit("chat", { |                         socket.emit("chat", { | ||||||
|                           from: "System", |                           from: "System", | ||||||
|                           msg: |                           msg: ": You are doing that command wrong. its /ban USERNAME REASON or /unban USERNAME", | ||||||
|                             ": You are doing that command wrong. its /ban USERNAME REASON or /unban USERNAME", |                           icon: "https://zoff.me/assets/images/favicon-32x32.png" | ||||||
|                           icon: |  | ||||||
|                             "https://zoff.me/assets/images/favicon-32x32.png" |  | ||||||
|                         }); |                         }); | ||||||
|                         return; |                         return; | ||||||
|                       } |                       } | ||||||
|                     } else { |                     } else { | ||||||
|                       db.collection("registered_users").find( |                       db.collection("registered_users").find({ | ||||||
|                         { _id: docs[0].name }, |                           _id: docs[0].name | ||||||
|                         function(err, n) { |                         }, | ||||||
|  |                         function (err, n) { | ||||||
|                           var icon = false; |                           var icon = false; | ||||||
|                           if (n.length > 0 && n[0].icon) { |                           if (n.length > 0 && n[0].icon) { | ||||||
|                             icon = n[0].icon; |                             icon = n[0].icon; | ||||||
| @@ -399,7 +388,7 @@ function all_chat(msg, guid, offline, socket) { | |||||||
|     guid, |     guid, | ||||||
|     socket, |     socket, | ||||||
|     offline, |     offline, | ||||||
|     function() { |     function () { | ||||||
|       if ( |       if ( | ||||||
|         data !== "" && |         data !== "" && | ||||||
|         data !== undefined && |         data !== undefined && | ||||||
| @@ -407,17 +396,19 @@ function all_chat(msg, guid, offline, socket) { | |||||||
|         data.length < 151 && |         data.length < 151 && | ||||||
|         data.replace(/\s/g, "").length |         data.replace(/\s/g, "").length | ||||||
|       ) { |       ) { | ||||||
|         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) { | ||||||
|             db.collection("registered_users").find( |             db.collection("registered_users").find({ | ||||||
|               { _id: docs[0].name }, |                 _id: docs[0].name | ||||||
|               function(err, n) { |               }, | ||||||
|  |               function (err, n) { | ||||||
|                 var icon = false; |                 var icon = false; | ||||||
|                 if (n.length > 0 && n[0].icon) { |                 if (n.length > 0 && n[0].icon) { | ||||||
|                   icon = n[0].icon; |                   icon = n[0].icon; | ||||||
|                 } |                 } | ||||||
|                 db.collection("chat_logs").insert( |                 db.collection("chat_logs").insert({ | ||||||
|                   { |  | ||||||
|                     createdAt: new Date(), |                     createdAt: new Date(), | ||||||
|                     all: true, |                     all: true, | ||||||
|                     channel: coll, |                     channel: coll, | ||||||
| @@ -425,7 +416,7 @@ function all_chat(msg, guid, offline, socket) { | |||||||
|                     msg: ": " + data, |                     msg: ": " + data, | ||||||
|                     icon: icon |                     icon: icon | ||||||
|                   }, |                   }, | ||||||
|                   function(err, docs) {} |                   function (err, docs) {} | ||||||
|                 ); |                 ); | ||||||
|                 io.sockets.emit("chat.all", { |                 io.sockets.emit("chat.all", { | ||||||
|                   from: docs[0].name, |                   from: docs[0].name, | ||||||
| @@ -454,7 +445,7 @@ function all_chat(msg, guid, offline, socket) { | |||||||
| function checkIfChatEnabled(channel, socket, callback) { | function checkIfChatEnabled(channel, socket, callback) { | ||||||
|   if (channel == "" || channel == undefined) callback(); |   if (channel == "" || channel == undefined) callback(); | ||||||
|   else { |   else { | ||||||
|     db.collection(channel + "_settings").find(function(err, docs) { |     db.collection(channel + "_settings").find(function (err, docs) { | ||||||
|       if ( |       if ( | ||||||
|         docs.length > 0 && |         docs.length > 0 && | ||||||
|         (docs[0].hasOwnProperty("toggleChat") && !docs[0].toggleChat) |         (docs[0].hasOwnProperty("toggleChat") && !docs[0].toggleChat) | ||||||
| @@ -475,24 +466,34 @@ function checkIfChatEnabled(channel, socket, callback) { | |||||||
| function checkIfUserIsBanned(channel, socket, guid, callback, callback_error) { | function checkIfUserIsBanned(channel, socket, guid, callback, callback_error) { | ||||||
|   var connection_id = Functions.hash_pass( |   var connection_id = Functions.hash_pass( | ||||||
|     socket.handshake.headers["user-agent"] + |     socket.handshake.headers["user-agent"] + | ||||||
|       socket.handshake.address + |     socket.handshake.address + | ||||||
|       socket.handshake.headers["accept-language"] |     socket.handshake.headers["accept-language"] | ||||||
|   ); |   ); | ||||||
|   db.collection(channel + "_banned_chat").find( |   db.collection(channel + "_banned_chat").find({ | ||||||
|     { $or: [{ connection_id: connection_id }, { connection_id: guid }] }, |       $or: [{ | ||||||
|     function(err, docs) { |         connection_id: connection_id | ||||||
|  |       }, { | ||||||
|  |         connection_id: guid | ||||||
|  |       }] | ||||||
|  |     }, | ||||||
|  |     function (err, docs) { | ||||||
|       if (docs.length == 0) callback(); |       if (docs.length == 0) callback(); | ||||||
|       else { |       else { | ||||||
|         db.collection("user_names").findAndModify( |         db.collection("user_names").findAndModify({ | ||||||
|           { |             query: { | ||||||
|             query: { guid, guid }, |               guid, | ||||||
|             update: { $addToSet: { channels: channel } } |               guid | ||||||
|  |             }, | ||||||
|  |             update: { | ||||||
|  |               $addToSet: { | ||||||
|  |                 channels: channel | ||||||
|  |               } | ||||||
|  |             } | ||||||
|           }, |           }, | ||||||
|           function(e, d) { |           function (e, d) { | ||||||
|             socket.emit("chat", { |             socket.emit("chat", { | ||||||
|               from: "System", |               from: "System", | ||||||
|               msg: |               msg: ": You can't chat in this channel, you are banned. The reason is: " + | ||||||
|                 ": You can't chat in this channel, you are banned. The reason is: " + |  | ||||||
|                 docs[0].reason, |                 docs[0].reason, | ||||||
|               icon: "https://zoff.me/assets/images/favicon-32x32.png" |               icon: "https://zoff.me/assets/images/favicon-32x32.png" | ||||||
|             }); |             }); | ||||||
| @@ -506,7 +507,7 @@ function checkIfUserIsBanned(channel, socket, guid, callback, callback_error) { | |||||||
| } | } | ||||||
|  |  | ||||||
| function namechange(data, guid, socket, tried, callback) { | function namechange(data, guid, socket, tried, callback) { | ||||||
|   checkIfChatEnabled(data.channel, socket, function(enabled) { |   checkIfChatEnabled(data.channel, socket, function (enabled) { | ||||||
|     if (!enabled) { |     if (!enabled) { | ||||||
|       callback(false); |       callback(false); | ||||||
|       return; |       return; | ||||||
| @@ -515,11 +516,11 @@ function namechange(data, guid, socket, tried, callback) { | |||||||
|       data.channel, |       data.channel, | ||||||
|       socket, |       socket, | ||||||
|       guid, |       guid, | ||||||
|       function() { |       function () { | ||||||
|         var pw = ""; |         var pw = ""; | ||||||
|         var new_password; |         var new_password; | ||||||
|         var first = false; |         var first = false; | ||||||
|         Functions.getSessionChatPass(Functions.getSession(socket), function( |         Functions.getSessionChatPass(Functions.getSession(socket), function ( | ||||||
|           name, |           name, | ||||||
|           pass |           pass | ||||||
|         ) { |         ) { | ||||||
| @@ -561,9 +562,10 @@ function namechange(data, guid, socket, tried, callback) { | |||||||
|             return; |             return; | ||||||
|           } |           } | ||||||
|  |  | ||||||
|           db.collection("registered_users").find( |           db.collection("registered_users").find({ | ||||||
|             { _id: name.toLowerCase() }, |               _id: name.toLowerCase() | ||||||
|             function(err, docs) { |             }, | ||||||
|  |             function (err, docs) { | ||||||
|               var accepted_password = false; |               var accepted_password = false; | ||||||
|               var icon = false; |               var icon = false; | ||||||
|               if (docs.length == 0) { |               if (docs.length == 0) { | ||||||
| @@ -576,12 +578,17 @@ function namechange(data, guid, socket, tried, callback) { | |||||||
|                   Functions.getSession(socket), |                   Functions.getSession(socket), | ||||||
|                   name.toLowerCase(), |                   name.toLowerCase(), | ||||||
|                   data.password, |                   data.password, | ||||||
|                   function() { |                   function () { | ||||||
|                     db.collection("registered_users").update( |                     db.collection("registered_users").update({ | ||||||
|                       { _id: name.toLowerCase() }, |                         _id: name.toLowerCase() | ||||||
|                       { $set: { password: password } }, |                       }, { | ||||||
|                       { upsert: true }, |                         $set: { | ||||||
|                       function() {} |                           password: password | ||||||
|  |                         } | ||||||
|  |                       }, { | ||||||
|  |                         upsert: true | ||||||
|  |                       }, | ||||||
|  |                       function () {} | ||||||
|                     ); |                     ); | ||||||
|                   } |                   } | ||||||
|                 ); |                 ); | ||||||
| @@ -595,13 +602,16 @@ function namechange(data, guid, socket, tried, callback) { | |||||||
|                     Functions.getSession(socket), |                     Functions.getSession(socket), | ||||||
|                     name.toLowerCase(), |                     name.toLowerCase(), | ||||||
|                     data.new_password, |                     data.new_password, | ||||||
|                     function() { |                     function () { | ||||||
|                       db.collection("registered_users").update( |                       db.collection("registered_users").update({ | ||||||
|                         { _id: name.toLowerCase(), password: password }, |                           _id: name.toLowerCase(), | ||||||
|                         { |                           password: password | ||||||
|                           $set: { password: Functions.hash_pass(new_password) } |                         }, { | ||||||
|  |                           $set: { | ||||||
|  |                             password: Functions.hash_pass(new_password) | ||||||
|  |                           } | ||||||
|                         }, |                         }, | ||||||
|                         function() {} |                         function () {} | ||||||
|                       ); |                       ); | ||||||
|                     } |                     } | ||||||
|                   ); |                   ); | ||||||
| @@ -609,17 +619,19 @@ function namechange(data, guid, socket, tried, callback) { | |||||||
|                   Functions.setSessionChatPass( |                   Functions.setSessionChatPass( | ||||||
|                     Functions.getSession(socket), |                     Functions.getSession(socket), | ||||||
|                     name.toLowerCase(), |                     name.toLowerCase(), | ||||||
|                     fetched |                     fetched ? | ||||||
|                       ? data.password |                     data.password : | ||||||
|                       : Functions.hash_pass( |                     Functions.hash_pass( | ||||||
|                           Functions.decrypt_string(data.password) |                       Functions.decrypt_string(data.password) | ||||||
|                         ), |                     ), | ||||||
|                     function() {} |                     function () {} | ||||||
|                   ); |                   ); | ||||||
|                 } |                 } | ||||||
|               } |               } | ||||||
|               if (accepted_password) { |               if (accepted_password) { | ||||||
|                 db.collection("user_names").find({ guid: guid }, function( |                 db.collection("user_names").find({ | ||||||
|  |                   guid: guid | ||||||
|  |                 }, function ( | ||||||
|                   err, |                   err, | ||||||
|                   names |                   names | ||||||
|                 ) { |                 ) { | ||||||
| @@ -631,16 +643,20 @@ function namechange(data, guid, socket, tried, callback) { | |||||||
|                     if (names.length == 0) no_name = true; |                     if (names.length == 0) no_name = true; | ||||||
|                     if (!no_name) { |                     if (!no_name) { | ||||||
|                       var old_name = names[0].name; |                       var old_name = names[0].name; | ||||||
|                       db.collection("user_names").update( |                       db.collection("user_names").update({ | ||||||
|                         { _id: "all_names" }, |                           _id: "all_names" | ||||||
|                         { $pull: { names: old_name } }, |                         }, { | ||||||
|                         function() {} |                           $pull: { | ||||||
|  |                             names: old_name | ||||||
|  |                           } | ||||||
|  |                         }, | ||||||
|  |                         function () {} | ||||||
|                       ); |                       ); | ||||||
|                     } |                     } | ||||||
|                     var connection_id = Functions.hash_pass( |                     var connection_id = Functions.hash_pass( | ||||||
|                       socket.handshake.headers["user-agent"] + |                       socket.handshake.headers["user-agent"] + | ||||||
|                         socket.handshake.address + |                       socket.handshake.address + | ||||||
|                         socket.handshake.headers["accept-language"] |                       socket.handshake.headers["accept-language"] | ||||||
|                     ); |                     ); | ||||||
|                     var updateElement = { |                     var updateElement = { | ||||||
|                       $set: { |                       $set: { | ||||||
| @@ -650,17 +666,25 @@ function namechange(data, guid, socket, tried, callback) { | |||||||
|                       } |                       } | ||||||
|                     }; |                     }; | ||||||
|                     if (data.hasOwnProperty("channel") && data.channel != "") { |                     if (data.hasOwnProperty("channel") && data.channel != "") { | ||||||
|                       updateElement["$addToSet"] = { channels: data.channel }; |                       updateElement["$addToSet"] = { | ||||||
|  |                         channels: data.channel | ||||||
|  |                       }; | ||||||
|                     } |                     } | ||||||
|                     db.collection("user_names").update( |                     db.collection("user_names").update({ | ||||||
|                       { guid: guid }, |                         guid: guid | ||||||
|                       updateElement, |                       }, | ||||||
|                       { upsert: true }, |                       updateElement, { | ||||||
|                       function(err, docs) { |                         upsert: true | ||||||
|                         db.collection("user_names").update( |                       }, | ||||||
|                           { _id: "all_names" }, |                       function (err, docs) { | ||||||
|                           { $addToSet: { names: name } }, |                         db.collection("user_names").update({ | ||||||
|                           function(err, docs) { |                             _id: "all_names" | ||||||
|  |                           }, { | ||||||
|  |                             $addToSet: { | ||||||
|  |                               names: name | ||||||
|  |                             } | ||||||
|  |                           }, | ||||||
|  |                           function (err, docs) { | ||||||
|                             //socket.emit('name', {type: "name", accepted: true}); |                             //socket.emit('name', {type: "name", accepted: true}); | ||||||
|                             if (old_name != name && !first && !no_name) { |                             if (old_name != name && !first && !no_name) { | ||||||
|                               if ( |                               if ( | ||||||
| @@ -699,8 +723,11 @@ function namechange(data, guid, socket, tried, callback) { | |||||||
|               } else { |               } else { | ||||||
|                 Functions.removeSessionChatPass( |                 Functions.removeSessionChatPass( | ||||||
|                   Functions.getSession(socket), |                   Functions.getSession(socket), | ||||||
|                   function() { |                   function () { | ||||||
|                     socket.emit("name", { type: "name", accepted: false }); |                     socket.emit("name", { | ||||||
|  |                       type: "name", | ||||||
|  |                       accepted: false | ||||||
|  |                     }); | ||||||
|                   } |                   } | ||||||
|                 ); |                 ); | ||||||
|               } |               } | ||||||
| @@ -715,19 +742,27 @@ function namechange(data, guid, socket, tried, callback) { | |||||||
|  |  | ||||||
| function removename(guid, coll, socket) { | function removename(guid, coll, socket) { | ||||||
|   //coll = coll.replace(/ /g,''); |   //coll = coll.replace(/ /g,''); | ||||||
|   checkIfChatEnabled(coll, socket, function(enabled) { |   checkIfChatEnabled(coll, socket, function (enabled) { | ||||||
|     if (!enabled) return; |     if (!enabled) return; | ||||||
|     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) { | ||||||
|         var old_name = docs[0].name; |         var old_name = docs[0].name; | ||||||
|         Functions.removeSessionChatPass( |         Functions.removeSessionChatPass( | ||||||
|           Functions.getSession(socket), |           Functions.getSession(socket), | ||||||
|           function() { |           function () { | ||||||
|             db.collection("user_names").update( |             db.collection("user_names").update({ | ||||||
|               { _id: "all_names" }, |                 _id: "all_names" | ||||||
|               { $pull: { names: old_name } }, |               }, { | ||||||
|               function(err, updated) { |                 $pull: { | ||||||
|                 db.collection("user_names").remove({ guid: guid }, function( |                   names: old_name | ||||||
|  |                 } | ||||||
|  |               }, | ||||||
|  |               function (err, updated) { | ||||||
|  |                 db.collection("user_names").remove({ | ||||||
|  |                   guid: guid | ||||||
|  |                 }, function ( | ||||||
|                   err, |                   err, | ||||||
|                   removed |                   removed | ||||||
|                 ) { |                 ) { | ||||||
| @@ -753,16 +788,23 @@ function generate_name(guid, announce_payload, second, round, channel) { | |||||||
|     second ? second : guid, |     second ? second : guid, | ||||||
|     Math.floor(8 + round) |     Math.floor(8 + round) | ||||||
|   ); |   ); | ||||||
|   db.collection("registered_users").find({ _id: tmp_name }, function( |   db.collection("registered_users").find({ | ||||||
|  |     _id: tmp_name | ||||||
|  |   }, function ( | ||||||
|     err, |     err, | ||||||
|     docs |     docs | ||||||
|   ) { |   ) { | ||||||
|     if (docs.length == 0) { |     if (docs.length == 0) { | ||||||
|       db.collection("user_names").update( |       db.collection("user_names").update({ | ||||||
|         { _id: "all_names" }, |           _id: "all_names" | ||||||
|         { $addToSet: { names: tmp_name } }, |         }, { | ||||||
|         { upsert: true }, |           $addToSet: { | ||||||
|         function(err, updated) { |             names: tmp_name | ||||||
|  |           } | ||||||
|  |         }, { | ||||||
|  |           upsert: true | ||||||
|  |         }, | ||||||
|  |         function (err, updated) { | ||||||
|           if ( |           if ( | ||||||
|             updated.nModified == 1 || |             updated.nModified == 1 || | ||||||
|             (updated.hasOwnProperty("upserted") && |             (updated.hasOwnProperty("upserted") && | ||||||
| @@ -771,8 +813,8 @@ function generate_name(guid, announce_payload, second, round, channel) { | |||||||
|           ) { |           ) { | ||||||
|             var connection_id = Functions.hash_pass( |             var connection_id = Functions.hash_pass( | ||||||
|               announce_payload.socket.handshake.headers["user-agent"] + |               announce_payload.socket.handshake.headers["user-agent"] + | ||||||
|                 announce_payload.socket.handshake.address + |               announce_payload.socket.handshake.address + | ||||||
|                 announce_payload.socket.handshake.headers["accept-language"] |               announce_payload.socket.handshake.headers["accept-language"] | ||||||
|             ); |             ); | ||||||
|             var updateElement = { |             var updateElement = { | ||||||
|               $set: { |               $set: { | ||||||
| @@ -782,7 +824,9 @@ function generate_name(guid, announce_payload, second, round, channel) { | |||||||
|               } |               } | ||||||
|             }; |             }; | ||||||
|             if (channel != undefined && channel != "") { |             if (channel != undefined && channel != "") { | ||||||
|               updateElement["$addToSet"] = { channels: channel }; |               updateElement["$addToSet"] = { | ||||||
|  |                 channels: channel | ||||||
|  |               }; | ||||||
|             } |             } | ||||||
|             if ( |             if ( | ||||||
|               announce_payload.hasOwnProperty("channel") && |               announce_payload.hasOwnProperty("channel") && | ||||||
| @@ -792,11 +836,13 @@ function generate_name(guid, announce_payload, second, round, channel) { | |||||||
|                 channels: announce_payload.channel |                 channels: announce_payload.channel | ||||||
|               }; |               }; | ||||||
|             } |             } | ||||||
|             db.collection("user_names").update( |             db.collection("user_names").update({ | ||||||
|               { guid: guid }, |                 guid: guid | ||||||
|               updateElement, |               }, | ||||||
|               { upsert: true }, |               updateElement, { | ||||||
|               function(err, update) { |                 upsert: true | ||||||
|  |               }, | ||||||
|  |               function (err, update) { | ||||||
|                 name = tmp_name; |                 name = tmp_name; | ||||||
|                 if (announce_payload.announce) { |                 if (announce_payload.announce) { | ||||||
|                   io.to(announce_payload.channel).emit("chat", { |                   io.to(announce_payload.channel).emit("chat", { | ||||||
| @@ -843,7 +889,7 @@ function get_name(guid, announce_payload, first) { | |||||||
|   if (!announce_payload.announce && announce_payload.hasOwnProperty("socket")) { |   if (!announce_payload.announce && announce_payload.hasOwnProperty("socket")) { | ||||||
|     Functions.getSessionChatPass( |     Functions.getSessionChatPass( | ||||||
|       Functions.getSession(announce_payload.socket), |       Functions.getSession(announce_payload.socket), | ||||||
|       function(name, pass) { |       function (name, pass) { | ||||||
|         if (name == "" || pass == "") { |         if (name == "" || pass == "") { | ||||||
|           get_name_generate( |           get_name_generate( | ||||||
|             guid, |             guid, | ||||||
| @@ -853,9 +899,10 @@ function get_name(guid, announce_payload, first) { | |||||||
|           ); |           ); | ||||||
|           return; |           return; | ||||||
|         } |         } | ||||||
|         db.collection("registered_users").find( |         db.collection("registered_users").find({ | ||||||
|           { _id: name.toLowerCase() }, |             _id: name.toLowerCase() | ||||||
|           function(err, docs) { |           }, | ||||||
|  |           function (err, docs) { | ||||||
|             if ( |             if ( | ||||||
|               docs[0].password == |               docs[0].password == | ||||||
|               Functions.hash_pass(Functions.decrypt_string(pass)) |               Functions.hash_pass(Functions.decrypt_string(pass)) | ||||||
| @@ -868,15 +915,19 @@ function get_name(guid, announce_payload, first) { | |||||||
|                 Functions.getSession(announce_payload.socket), |                 Functions.getSession(announce_payload.socket), | ||||||
|                 name.toLowerCase(), |                 name.toLowerCase(), | ||||||
|                 pass, |                 pass, | ||||||
|                 function() {} |                 function () {} | ||||||
|               ); |               ); | ||||||
|               var connection_id = Functions.hash_pass( |               var connection_id = Functions.hash_pass( | ||||||
|                 announce_payload.socket.handshake.headers["user-agent"] + |                 announce_payload.socket.handshake.headers["user-agent"] + | ||||||
|                   announce_payload.socket.handshake.address + |                 announce_payload.socket.handshake.address + | ||||||
|                   announce_payload.socket.handshake.headers["accept-language"] |                 announce_payload.socket.handshake.headers["accept-language"] | ||||||
|               ); |               ); | ||||||
|               var updateElement = { |               var updateElement = { | ||||||
|                 $set: { name: name, icon: icon, connection_id: connection_id } |                 $set: { | ||||||
|  |                   name: name, | ||||||
|  |                   icon: icon, | ||||||
|  |                   connection_id: connection_id | ||||||
|  |                 } | ||||||
|               }; |               }; | ||||||
|               if ( |               if ( | ||||||
|                 announce_payload.hasOwnProperty("channel") && |                 announce_payload.hasOwnProperty("channel") && | ||||||
| @@ -885,15 +936,21 @@ function get_name(guid, announce_payload, first) { | |||||||
|                 updateElement["$addToSet"] = { |                 updateElement["$addToSet"] = { | ||||||
|                   channel: announce_payload.channel |                   channel: announce_payload.channel | ||||||
|                 }; |                 }; | ||||||
|               db.collection("user_names").update( |               db.collection("user_names").update({ | ||||||
|                 { guid: guid }, |                   guid: guid | ||||||
|                 updateElement, |                 }, | ||||||
|                 { upsert: true }, |                 updateElement, { | ||||||
|                 function(err, docs) { |                   upsert: true | ||||||
|                   db.collection("user_names").update( |                 }, | ||||||
|                     { _id: "all_names" }, |                 function (err, docs) { | ||||||
|                     { $addToSet: { names: name } }, |                   db.collection("user_names").update({ | ||||||
|                     function(err, docs) { |                       _id: "all_names" | ||||||
|  |                     }, { | ||||||
|  |                       $addToSet: { | ||||||
|  |                         names: name | ||||||
|  |                       } | ||||||
|  |                     }, | ||||||
|  |                     function (err, docs) { | ||||||
|                       name = name; |                       name = name; | ||||||
|                     } |                     } | ||||||
|                   ); |                   ); | ||||||
| @@ -910,7 +967,9 @@ function get_name(guid, announce_payload, first) { | |||||||
| } | } | ||||||
|  |  | ||||||
| function get_name_generate(guid, announce_payload, first, channel) { | function get_name_generate(guid, announce_payload, first, channel) { | ||||||
|   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) { | ||||||
|       generate_name(guid, announce_payload, undefined); |       generate_name(guid, announce_payload, undefined); | ||||||
|     } else { |     } else { | ||||||
| @@ -926,4 +985,4 @@ module.exports.all_chat = all_chat; | |||||||
| module.exports.namechange = namechange; | module.exports.namechange = namechange; | ||||||
| module.exports.removename = removename; | module.exports.removename = removename; | ||||||
| module.exports.generate_name = generate_name; | module.exports.generate_name = generate_name; | ||||||
| module.exports.get_name = get_name; | module.exports.get_name = get_name; | ||||||
| @@ -17,68 +17,113 @@ var connected_db = mongojs( | |||||||
| ); | ); | ||||||
| var ObjectId = mongojs.ObjectId; | var ObjectId = mongojs.ObjectId; | ||||||
|  |  | ||||||
| db.collection("chat_logs").createIndex( | db.collection("chat_logs").createIndex({ | ||||||
|   { createdAt: 1 }, |     createdAt: 1 | ||||||
|   { expireAfterSeconds: 600 }, |   }, { | ||||||
|   function() {} |     expireAfterSeconds: 600 | ||||||
|  |   }, | ||||||
|  |   function () {} | ||||||
| ); | ); | ||||||
| db.collection("timeout_api").createIndex( | db.collection("timeout_api").createIndex({ | ||||||
|   { createdAt: 1 }, |     createdAt: 1 | ||||||
|   { expireAfterSeconds: 120 }, |   }, { | ||||||
|   function() {} |     expireAfterSeconds: 120 | ||||||
|  |   }, | ||||||
|  |   function () {} | ||||||
| ); | ); | ||||||
| db.collection("api_links").createIndex( | db.collection("api_links").createIndex({ | ||||||
|   { createdAt: 1 }, |     createdAt: 1 | ||||||
|   { expireAfterSeconds: 86400 }, |   }, { | ||||||
|   function() {} |     expireAfterSeconds: 86400 | ||||||
|  |   }, | ||||||
|  |   function () {} | ||||||
| ); | ); | ||||||
| db.on("connected", function(err) { | db.on("connected", function (err) { | ||||||
|   console.log("connected"); |   console.log("connected"); | ||||||
| }); | }); | ||||||
|  |  | ||||||
| db.on("error", function(err) { | db.on("error", function (err) { | ||||||
|   console.log("\n" + new Date().toString() + "\n Database error: ", err); |   console.log("\n" + new Date().toString() + "\n Database error: ", err); | ||||||
| }); | }); | ||||||
|  |  | ||||||
| db.on("error", function(err) { | db.on("error", function (err) { | ||||||
|   console.log("\n" + new Date().toString() + "\n Database error: ", err); |   console.log("\n" + new Date().toString() + "\n Database error: ", err); | ||||||
| }); | }); | ||||||
|  |  | ||||||
| /* Resetting usernames, and connected users */ | /* Resetting usernames, and connected users */ | ||||||
| db.collection("unique_ids").update( | db.collection("unique_ids").update({ | ||||||
|   { _id: "unique_ids" }, |     _id: "unique_ids" | ||||||
|   { $set: { unique_ids: [] } }, |   }, { | ||||||
|   { multi: true, upsert: true }, |     $set: { | ||||||
|   function(err, docs) {} |       unique_ids: [] | ||||||
|  |     } | ||||||
|  |   }, { | ||||||
|  |     multi: true, | ||||||
|  |     upsert: true | ||||||
|  |   }, | ||||||
|  |   function (err, docs) {} | ||||||
| ); | ); | ||||||
| db.collection("user_names").remove( | db.collection("user_names").remove({ | ||||||
|   { guid: { $exists: true } }, |     guid: { | ||||||
|   { multi: true, upsert: true }, |       $exists: true | ||||||
|   function(err, docs) {} |     } | ||||||
|  |   }, { | ||||||
|  |     multi: true, | ||||||
|  |     upsert: true | ||||||
|  |   }, | ||||||
|  |   function (err, docs) {} | ||||||
| ); | ); | ||||||
| db.collection("user_names").update( | db.collection("user_names").update({ | ||||||
|   { _id: "all_names" }, |     _id: "all_names" | ||||||
|   { $set: { names: [] } }, |   }, { | ||||||
|   { multi: true, upsert: true }, |     $set: { | ||||||
|   function(err, docs) {} |       names: [] | ||||||
|  |     } | ||||||
|  |   }, { | ||||||
|  |     multi: true, | ||||||
|  |     upsert: true | ||||||
|  |   }, | ||||||
|  |   function (err, docs) {} | ||||||
| ); | ); | ||||||
| db.collection("connected_users").update( | db.collection("connected_users").update({ | ||||||
|   { users: { $exists: true } }, |     users: { | ||||||
|   { $set: { users: [] } }, |       $exists: true | ||||||
|   { multi: true, upsert: true }, |     } | ||||||
|   function(err, docs) {} |   }, { | ||||||
|  |     $set: { | ||||||
|  |       users: [] | ||||||
|  |     } | ||||||
|  |   }, { | ||||||
|  |     multi: true, | ||||||
|  |     upsert: true | ||||||
|  |   }, | ||||||
|  |   function (err, docs) {} | ||||||
| ); | ); | ||||||
| db.collection("connected_users").update( | db.collection("connected_users").update({ | ||||||
|   { _id: "total_users" }, |     _id: "total_users" | ||||||
|   { $set: { total_users: [] } }, |   }, { | ||||||
|   { multi: true, upsert: true }, |     $set: { | ||||||
|   function(err, docs) {} |       total_users: [] | ||||||
|  |     } | ||||||
|  |   }, { | ||||||
|  |     multi: true, | ||||||
|  |     upsert: true | ||||||
|  |   }, | ||||||
|  |   function (err, docs) {} | ||||||
| ); | ); | ||||||
| db.collection("frontpage_lists").update( | db.collection("frontpage_lists").update({ | ||||||
|   { viewers: { $ne: 0 } }, |     viewers: { | ||||||
|   { $set: { viewers: 0 } }, |       $ne: 0 | ||||||
|   { multi: true, upsert: true }, |     } | ||||||
|   function(err, docs) {} |   }, { | ||||||
|  |     $set: { | ||||||
|  |       viewers: 0 | ||||||
|  |     } | ||||||
|  |   }, { | ||||||
|  |     multi: true, | ||||||
|  |     upsert: true | ||||||
|  |   }, | ||||||
|  |   function (err, docs) {} | ||||||
| ); | ); | ||||||
|  |  | ||||||
| module.exports = db; | module.exports = db; | ||||||
| @@ -1,5 +1,6 @@ | |||||||
| var Functions = require(pathThumbnails + "/handlers/functions.js"); | var Functions = require(pathThumbnails + "/handlers/functions.js"); | ||||||
| var db = require(pathThumbnails + "/handlers/db.js"); | var db = require(pathThumbnails + "/handlers/db.js"); | ||||||
|  |  | ||||||
| function frontpage_lists(msg, socket) { | function frontpage_lists(msg, socket) { | ||||||
|   if ( |   if ( | ||||||
|     msg == undefined || |     msg == undefined || | ||||||
| @@ -17,11 +18,15 @@ function frontpage_lists(msg, socket) { | |||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   db.collection("frontpage_lists").find({ frontpage: true }, function( |   db.collection("frontpage_lists").find({ | ||||||
|  |     frontpage: true | ||||||
|  |   }, function ( | ||||||
|     err, |     err, | ||||||
|     docs |     docs | ||||||
|   ) { |   ) { | ||||||
|     db.collection("connected_users").find({ _id: "total_users" }, function( |     db.collection("connected_users").find({ | ||||||
|  |       _id: "total_users" | ||||||
|  |     }, function ( | ||||||
|       err, |       err, | ||||||
|       tot |       tot | ||||||
|     ) { |     ) { | ||||||
| @@ -44,16 +49,22 @@ function get_frontpage_lists(callback) { | |||||||
|     title: 1, |     title: 1, | ||||||
|     viewers: 1, |     viewers: 1, | ||||||
|     accessed: 1, |     accessed: 1, | ||||||
|     pinned: { $ifNull: ["$pinned", 0] }, |     pinned: { | ||||||
|  |       $ifNull: ["$pinned", 0] | ||||||
|  |     }, | ||||||
|     description: { |     description: { | ||||||
|       $ifNull: [ |       $ifNull: [{ | ||||||
|         { |  | ||||||
|           $cond: { |           $cond: { | ||||||
|             if: { |             if: { | ||||||
|               $or: [ |               $or: [{ | ||||||
|                 { $eq: ["$description", ""] }, |                   $eq: ["$description", ""] | ||||||
|                 { $eq: ["$description", null] }, |                 }, | ||||||
|                 { $eq: ["$description", undefined] } |                 { | ||||||
|  |                   $eq: ["$description", null] | ||||||
|  |                 }, | ||||||
|  |                 { | ||||||
|  |                   $eq: ["$description", undefined] | ||||||
|  |                 } | ||||||
|               ] |               ] | ||||||
|             }, |             }, | ||||||
|             then: "This list has no description", |             then: "This list has no description", | ||||||
| @@ -64,14 +75,18 @@ function get_frontpage_lists(callback) { | |||||||
|       ] |       ] | ||||||
|     }, |     }, | ||||||
|     thumbnail: { |     thumbnail: { | ||||||
|       $ifNull: [ |       $ifNull: [{ | ||||||
|         { |  | ||||||
|           $cond: { |           $cond: { | ||||||
|             if: { |             if: { | ||||||
|               $or: [ |               $or: [{ | ||||||
|                 { $eq: ["$thumbnail", ""] }, |                   $eq: ["$thumbnail", ""] | ||||||
|                 { $eq: ["$thumbnail", null] }, |                 }, | ||||||
|                 { $eq: ["$thumbnail", undefined] } |                 { | ||||||
|  |                   $eq: ["$thumbnail", null] | ||||||
|  |                 }, | ||||||
|  |                 { | ||||||
|  |                   $eq: ["$thumbnail", undefined] | ||||||
|  |                 } | ||||||
|               ] |               ] | ||||||
|             }, |             }, | ||||||
|             then: { |             then: { | ||||||
| @@ -80,16 +95,19 @@ function get_frontpage_lists(callback) { | |||||||
|             else: "$thumbnail" |             else: "$thumbnail" | ||||||
|           } |           } | ||||||
|         }, |         }, | ||||||
|         { $concat: ["https://img.youtube.com/vi/", "$id", "/mqdefault.jpg"] } |         { | ||||||
|  |           $concat: ["https://img.youtube.com/vi/", "$id", "/mqdefault.jpg"] | ||||||
|  |         } | ||||||
|       ] |       ] | ||||||
|     } |     } | ||||||
|   }; |   }; | ||||||
|   db.collection("frontpage_lists").aggregate( |   db.collection("frontpage_lists").aggregate( | ||||||
|     [ |     [{ | ||||||
|       { |  | ||||||
|         $match: { |         $match: { | ||||||
|           frontpage: true, |           frontpage: true, | ||||||
|           count: { $gt: 3 } |           count: { | ||||||
|  |             $gt: 3 | ||||||
|  |           } | ||||||
|         } |         } | ||||||
|       }, |       }, | ||||||
|       { |       { | ||||||
| @@ -111,7 +129,9 @@ function get_frontpage_lists(callback) { | |||||||
|  |  | ||||||
| function update_frontpage(coll, id, title, thumbnail, source, callback) { | function update_frontpage(coll, id, title, thumbnail, source, callback) { | ||||||
|   //coll = coll.replace(/ /g,''); |   //coll = coll.replace(/ /g,''); | ||||||
|   db.collection("frontpage_lists").find({ _id: coll }, function(e, doc) { |   db.collection("frontpage_lists").find({ | ||||||
|  |     _id: coll | ||||||
|  |   }, function (e, doc) { | ||||||
|     var updateObject = { |     var updateObject = { | ||||||
|       id: id, |       id: id, | ||||||
|       title: title, |       title: title, | ||||||
| @@ -120,20 +140,23 @@ function update_frontpage(coll, id, title, thumbnail, source, callback) { | |||||||
|     if ( |     if ( | ||||||
|       doc.length > 0 && |       doc.length > 0 && | ||||||
|       ((doc[0].thumbnail != "" && |       ((doc[0].thumbnail != "" && | ||||||
|         doc[0].thumbnail != undefined && |           doc[0].thumbnail != undefined && | ||||||
|         (doc[0].thumbnail.indexOf("https://i1.sndcdn.com") > -1 || |           (doc[0].thumbnail.indexOf("https://i1.sndcdn.com") > -1 || | ||||||
|           doc[0].thumbnail.indexOf("https://w1.sndcdn.com") > -1 || |             doc[0].thumbnail.indexOf("https://w1.sndcdn.com") > -1 || | ||||||
|           doc[0].thumbnail.indexOf("https://img.youtube.com") > -1)) || |             doc[0].thumbnail.indexOf("https://img.youtube.com") > -1)) || | ||||||
|         (doc[0].thumbnail == "" || doc[0].thumbnail == undefined)) |         (doc[0].thumbnail == "" || doc[0].thumbnail == undefined)) | ||||||
|     ) { |     ) { | ||||||
|       updateObject.thumbnail = thumbnail; |       updateObject.thumbnail = thumbnail; | ||||||
|       if (thumbnail == undefined) updateObject.thumbnail = ""; |       if (thumbnail == undefined) updateObject.thumbnail = ""; | ||||||
|     } |     } | ||||||
|     db.collection("frontpage_lists").update( |     db.collection("frontpage_lists").update({ | ||||||
|       { _id: coll }, |         _id: coll | ||||||
|       { $set: updateObject }, |       }, { | ||||||
|       { upsert: true }, |         $set: updateObject | ||||||
|       function(err, returnDocs) { |       }, { | ||||||
|  |         upsert: true | ||||||
|  |       }, | ||||||
|  |       function (err, returnDocs) { | ||||||
|         if (typeof callback == "function") callback(); |         if (typeof callback == "function") callback(); | ||||||
|       } |       } | ||||||
|     ); |     ); | ||||||
| @@ -142,4 +165,4 @@ function update_frontpage(coll, id, title, thumbnail, source, callback) { | |||||||
|  |  | ||||||
| module.exports.get_frontpage_lists = get_frontpage_lists; | module.exports.get_frontpage_lists = get_frontpage_lists; | ||||||
| module.exports.frontpage_lists = frontpage_lists; | module.exports.frontpage_lists = frontpage_lists; | ||||||
| module.exports.update_frontpage = update_frontpage; | module.exports.update_frontpage = update_frontpage; | ||||||
| @@ -18,7 +18,9 @@ var crypto = require("crypto"); | |||||||
| var db = require(pathThumbnails + "/handlers/db.js"); | var db = require(pathThumbnails + "/handlers/db.js"); | ||||||
| var uniqid = require("uniqid"); | var uniqid = require("uniqid"); | ||||||
| var Filter = require("bad-words"); | var Filter = require("bad-words"); | ||||||
| var filter = new Filter({ placeHolder: "x" }); | var filter = new Filter({ | ||||||
|  |   placeHolder: "x" | ||||||
|  | }); | ||||||
|  |  | ||||||
| var Chat = require(pathThumbnails + "/handlers/chat.js"); | var Chat = require(pathThumbnails + "/handlers/chat.js"); | ||||||
|  |  | ||||||
| @@ -42,10 +44,14 @@ function decodeChannelName(str) { | |||||||
| } | } | ||||||
|  |  | ||||||
| function remove_unique_id(short_id) { | function remove_unique_id(short_id) { | ||||||
|   db.collection("unique_ids").update( |   db.collection("unique_ids").update({ | ||||||
|     { _id: "unique_ids" }, |       _id: "unique_ids" | ||||||
|     { $pull: { unique_ids: short_id } }, |     }, { | ||||||
|     function(err, docs) {} |       $pull: { | ||||||
|  |         unique_ids: short_id | ||||||
|  |       } | ||||||
|  |     }, | ||||||
|  |     function (err, docs) {} | ||||||
|   ); |   ); | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -53,21 +59,31 @@ function remove_name_from_db(guid, channel) { | |||||||
|   // Use temporary, with caution. Can bottleneck in large quantity of users. |   // Use temporary, with caution. Can bottleneck in large quantity of users. | ||||||
|   // |   // | ||||||
|   // Find a way of indexing users in lists in a clever way, to avoid the search here |   // Find a way of indexing users in lists in a clever way, to avoid the search here | ||||||
|   db.collection("connected_users").find({ _id: "total_users" }, function( |   db.collection("connected_users").find({ | ||||||
|  |     _id: "total_users" | ||||||
|  |   }, function ( | ||||||
|     err, |     err, | ||||||
|     all_users |     all_users | ||||||
|   ) { |   ) { | ||||||
|     var hasOne = all_users[0].total_users.some(function(v) { |     var hasOne = all_users[0].total_users.some(function (v) { | ||||||
|       return v.indexOf(guid) >= 0; |       return v.indexOf(guid) >= 0; | ||||||
|     }); |     }); | ||||||
|     if (!hasOne) { |     if (!hasOne) { | ||||||
|       db.collection("user_names").find({ guid: guid }, function(err, user) { |       db.collection("user_names").find({ | ||||||
|  |         guid: guid | ||||||
|  |       }, function (err, user) { | ||||||
|         if (user.length == 1) { |         if (user.length == 1) { | ||||||
|           db.collection("user_names").update( |           db.collection("user_names").update({ | ||||||
|             { _id: "all_names" }, |               _id: "all_names" | ||||||
|             { $pull: { names: user[0].name } }, |             }, { | ||||||
|             function(err, updated) { |               $pull: { | ||||||
|               db.collection("user_names").remove({ guid: guid }, function( |                 names: user[0].name | ||||||
|  |               } | ||||||
|  |             }, | ||||||
|  |             function (err, updated) { | ||||||
|  |               db.collection("user_names").remove({ | ||||||
|  |                 guid: guid | ||||||
|  |               }, function ( | ||||||
|                 err, |                 err, | ||||||
|                 removed |                 removed | ||||||
|               ) {}); |               ) {}); | ||||||
| @@ -77,10 +93,14 @@ function remove_name_from_db(guid, channel) { | |||||||
|       }); |       }); | ||||||
|     } else { |     } else { | ||||||
|       if (channel == undefined || channel == "") return; |       if (channel == undefined || channel == "") return; | ||||||
|       db.collection("user_names").update( |       db.collection("user_names").update({ | ||||||
|         { guid: guid }, |           guid: guid | ||||||
|         { $pull: { channels: channel } }, |         }, { | ||||||
|         function(err, docs) { |           $pull: { | ||||||
|  |             channels: channel | ||||||
|  |           } | ||||||
|  |         }, | ||||||
|  |         function (err, docs) { | ||||||
|           //console.log("Pulled user from current channel"); |           //console.log("Pulled user from current channel"); | ||||||
|         } |         } | ||||||
|       ); |       ); | ||||||
| @@ -91,15 +111,15 @@ function remove_name_from_db(guid, channel) { | |||||||
| function isUrl(str) { | function isUrl(str) { | ||||||
|   var pattern = new RegExp( |   var pattern = new RegExp( | ||||||
|     "\\b(((ht|f)tp(s?)\\:\\/\\/|~\\/|\\/)|www.)" + |     "\\b(((ht|f)tp(s?)\\:\\/\\/|~\\/|\\/)|www.)" + | ||||||
|       "(\\w+:\\w+@)?(([-\\w]+\\.)+(com|org|net|gov" + |     "(\\w+:\\w+@)?(([-\\w]+\\.)+(com|org|net|gov" + | ||||||
|       "|mil|biz|info|mobi|name|aero|jobs|museum" + |     "|mil|biz|info|mobi|name|aero|jobs|museum" + | ||||||
|       "|travel|[a-z]{2}))(:[\\d]{1,5})?" + |     "|travel|[a-z]{2}))(:[\\d]{1,5})?" + | ||||||
|       "(((\\/([-\\w~!$+|.,=]|%[a-f\\d]{2})+)+|\\/)+|\\?|#)?" + |     "(((\\/([-\\w~!$+|.,=]|%[a-f\\d]{2})+)+|\\/)+|\\?|#)?" + | ||||||
|       "((\\?([-\\w~!$+|.,*:]|%[a-f\\d{2}])+=?" + |     "((\\?([-\\w~!$+|.,*:]|%[a-f\\d{2}])+=?" + | ||||||
|       "([-\\w~!$+|.,*:=]|%[a-f\\d]{2})*)" + |     "([-\\w~!$+|.,*:=]|%[a-f\\d]{2})*)" + | ||||||
|       "(&(?:[-\\w~!$+|.,*:]|%[a-f\\d{2}])+=?" + |     "(&(?:[-\\w~!$+|.,*:]|%[a-f\\d{2}])+=?" + | ||||||
|       "([-\\w~!$+|.,*:=]|%[a-f\\d]{2})*)*)*" + |     "([-\\w~!$+|.,*:=]|%[a-f\\d]{2})*)*)*" + | ||||||
|       "(#([-\\w~!$+|.,*:=]|%[a-f\\d]{2})*)?\\b" |     "(#([-\\w~!$+|.,*:=]|%[a-f\\d]{2})*)?\\b" | ||||||
|   ); |   ); | ||||||
|   if (!pattern.test(str)) { |   if (!pattern.test(str)) { | ||||||
|     return false; |     return false; | ||||||
| @@ -120,8 +140,8 @@ function getSession(socket) { | |||||||
|     // Returning "sessiong"-based on place of connection |     // Returning "sessiong"-based on place of connection | ||||||
|     return hash_pass( |     return hash_pass( | ||||||
|       socket.handshake.headers["user-agent"] + |       socket.handshake.headers["user-agent"] + | ||||||
|         socket.handshake.address + |       socket.handshake.address + | ||||||
|         socket.handshake.headers["accept-language"] |       socket.handshake.headers["accept-language"] | ||||||
|     ); |     ); | ||||||
|     //return "empty"; |     //return "empty"; | ||||||
|   } |   } | ||||||
| @@ -136,10 +156,15 @@ function remove_from_array(array, element) { | |||||||
|  |  | ||||||
| function generate_channel_name(res) { | function generate_channel_name(res) { | ||||||
|   var trying_id = uniqid.time().toLowerCase(); |   var trying_id = uniqid.time().toLowerCase(); | ||||||
|   db.collection("frontpage_lists").find( |   db.collection("frontpage_lists").find({ | ||||||
|     { frontpage: { $exists: true }, _id: trying_id }, |       frontpage: { | ||||||
|     { _id: 1 }, |         $exists: true | ||||||
|     function(err, docs) { |       }, | ||||||
|  |       _id: trying_id | ||||||
|  |     }, { | ||||||
|  |       _id: 1 | ||||||
|  |     }, | ||||||
|  |     function (err, docs) { | ||||||
|       if (docs.length == 0) { |       if (docs.length == 0) { | ||||||
|         res.send(trying_id); |         res.send(trying_id); | ||||||
|         return; |         return; | ||||||
| @@ -163,20 +188,31 @@ function check_inlist(coll, guid, socket, offline, callback, double_check) { | |||||||
|   } |   } | ||||||
|   //coll = coll.replace(/ /g,''); |   //coll = coll.replace(/ /g,''); | ||||||
|   if (!offline && coll != undefined) { |   if (!offline && coll != undefined) { | ||||||
|     db.collection("connected_users").update( |     db.collection("connected_users").update({ | ||||||
|       { _id: coll }, |         _id: coll | ||||||
|       { $addToSet: { users: guid } }, |       }, { | ||||||
|       { upsert: true }, |         $addToSet: { | ||||||
|       function(err, updated) { |           users: guid | ||||||
|  |         } | ||||||
|  |       }, { | ||||||
|  |         upsert: true | ||||||
|  |       }, | ||||||
|  |       function (err, updated) { | ||||||
|         if (updated.nModified > 0 || updated.upserted != undefined) { |         if (updated.nModified > 0 || updated.upserted != undefined) { | ||||||
|           db.collection("connected_users").find({ _id: coll }, function( |           db.collection("connected_users").find({ | ||||||
|  |             _id: coll | ||||||
|  |           }, function ( | ||||||
|             err, |             err, | ||||||
|             new_doc |             new_doc | ||||||
|           ) { |           ) { | ||||||
|             db.collection("frontpage_lists").update( |             db.collection("frontpage_lists").update({ | ||||||
|               { _id: coll }, |                 _id: coll | ||||||
|               { $set: { viewers: new_doc[0].users.length } }, |               }, { | ||||||
|               function() { |                 $set: { | ||||||
|  |                   viewers: new_doc[0].users.length | ||||||
|  |                 } | ||||||
|  |               }, | ||||||
|  |               function () { | ||||||
|                 if ( |                 if ( | ||||||
|                   new_doc[0].users == undefined || |                   new_doc[0].users == undefined || | ||||||
|                   new_doc[0].users.length == undefined |                   new_doc[0].users.length == undefined | ||||||
| @@ -185,23 +221,32 @@ function check_inlist(coll, guid, socket, offline, callback, double_check) { | |||||||
|                 } else { |                 } else { | ||||||
|                   io.to(coll).emit("viewers", new_doc[0].users.length); |                   io.to(coll).emit("viewers", new_doc[0].users.length); | ||||||
|                 } |                 } | ||||||
|                 Chat.namechange( |                 Chat.namechange({ | ||||||
|                   { initial: true, first: true, channel: coll }, |                     initial: true, | ||||||
|  |                     first: true, | ||||||
|  |                     channel: coll | ||||||
|  |                   }, | ||||||
|                   guid, |                   guid, | ||||||
|                   socket, |                   socket, | ||||||
|                   false, |                   false, | ||||||
|                   function(enabled) { |                   function (enabled) { | ||||||
|                     db.collection("user_names").find({ guid: guid }, function( |                     db.collection("user_names").find({ | ||||||
|  |                       guid: guid | ||||||
|  |                     }, function ( | ||||||
|                       err, |                       err, | ||||||
|                       docs |                       docs | ||||||
|                     ) { |                     ) { | ||||||
|                       if (docs.length == 1) { |                       if (docs.length == 1) { | ||||||
|                         var icon = ""; |                         var icon = ""; | ||||||
|                         if (docs[0].icon != undefined) icon = docs[0].icon; |                         if (docs[0].icon != undefined) icon = docs[0].icon; | ||||||
|                         db.collection("user_names").update( |                         db.collection("user_names").update({ | ||||||
|                           { guid: guid }, |                             guid: guid | ||||||
|                           { $addToSet: { channels: coll } }, |                           }, { | ||||||
|                           function(err, doc) {} |                             $addToSet: { | ||||||
|  |                               channels: coll | ||||||
|  |                             } | ||||||
|  |                           }, | ||||||
|  |                           function (err, doc) {} | ||||||
|                         ); |                         ); | ||||||
|                         if (enabled) { |                         if (enabled) { | ||||||
|                           socket.broadcast.to(coll).emit("chat", { |                           socket.broadcast.to(coll).emit("chat", { | ||||||
| @@ -222,10 +267,14 @@ function check_inlist(coll, guid, socket, offline, callback, double_check) { | |||||||
|                         }); |                         }); | ||||||
|                       } |                       } | ||||||
|                     }); |                     }); | ||||||
|                     db.collection("connected_users").update( |                     db.collection("connected_users").update({ | ||||||
|                       { _id: "total_users" }, |                         _id: "total_users" | ||||||
|                       { $addToSet: { total_users: guid + coll } }, |                       }, { | ||||||
|                       function(err, docs) { |                         $addToSet: { | ||||||
|  |                           total_users: guid + coll | ||||||
|  |                         } | ||||||
|  |                       }, | ||||||
|  |                       function (err, docs) { | ||||||
|                         if ( |                         if ( | ||||||
|                           callback != undefined && |                           callback != undefined && | ||||||
|                           typeof callback == "function" |                           typeof callback == "function" | ||||||
| @@ -239,7 +288,9 @@ function check_inlist(coll, guid, socket, offline, callback, double_check) { | |||||||
|             ); |             ); | ||||||
|           }); |           }); | ||||||
|         } else { |         } else { | ||||||
|           db.collection("connected_users").find({ _id: coll }, function( |           db.collection("connected_users").find({ | ||||||
|  |             _id: coll | ||||||
|  |           }, function ( | ||||||
|             err, |             err, | ||||||
|             new_doc |             new_doc | ||||||
|           ) { |           ) { | ||||||
| @@ -252,24 +303,36 @@ function check_inlist(coll, guid, socket, offline, callback, double_check) { | |||||||
|     ); |     ); | ||||||
|   } else { |   } else { | ||||||
|     if (offline) { |     if (offline) { | ||||||
|       db.collection("connected_users").update( |       db.collection("connected_users").update({ | ||||||
|         { _id: "offline_users" }, |           _id: "offline_users" | ||||||
|         { $addToSet: { users: guid } }, |         }, { | ||||||
|         function(err, docs) {} |           $addToSet: { | ||||||
|  |             users: guid | ||||||
|  |           } | ||||||
|  |         }, | ||||||
|  |         function (err, docs) {} | ||||||
|       ); |       ); | ||||||
|     } else { |     } else { | ||||||
|       db.collection("connected_users").update( |       db.collection("connected_users").update({ | ||||||
|         { _id: coll }, |           _id: coll | ||||||
|         { $addToSet: { users: guid } }, |         }, { | ||||||
|         function(err, docs) {} |           $addToSet: { | ||||||
|  |             users: guid | ||||||
|  |           } | ||||||
|  |         }, | ||||||
|  |         function (err, docs) {} | ||||||
|       ); |       ); | ||||||
|     } |     } | ||||||
|     // |     // | ||||||
|     if (coll != undefined && coll != "") { |     if (coll != undefined && coll != "") { | ||||||
|       db.collection("connected_users").update( |       db.collection("connected_users").update({ | ||||||
|         { _id: "total_users" }, |           _id: "total_users" | ||||||
|         { $addToSet: { total_users: guid + coll } }, |         }, { | ||||||
|         function(err, docs) {} |           $addToSet: { | ||||||
|  |             total_users: guid + coll | ||||||
|  |           } | ||||||
|  |         }, | ||||||
|  |         function (err, docs) {} | ||||||
|       ); |       ); | ||||||
|     } |     } | ||||||
|     if (callback != undefined && typeof callback == "function") callback(); |     if (callback != undefined && typeof callback == "function") callback(); | ||||||
| @@ -372,11 +435,16 @@ function setSessionAdminPass(id, adminpass, list, callback) { | |||||||
|  |  | ||||||
|     connected_db |     connected_db | ||||||
|       .collection(id) |       .collection(id) | ||||||
|       .update( |       .update({ | ||||||
|         { _id: list }, |           _id: list | ||||||
|         { $set: { adminpass: hash_pass(decrypt_string(adminpass), true) } }, |         }, { | ||||||
|         { upsert: true }, |           $set: { | ||||||
|         function(e, d) { |             adminpass: hash_pass(decrypt_string(adminpass), true) | ||||||
|  |           } | ||||||
|  |         }, { | ||||||
|  |           upsert: true | ||||||
|  |         }, | ||||||
|  |         function (e, d) { | ||||||
|           callback(); |           callback(); | ||||||
|           return; |           return; | ||||||
|         } |         } | ||||||
| @@ -392,11 +460,17 @@ function setSessionChatPass(id, name, pass, callback) { | |||||||
|     } |     } | ||||||
|     connected_db |     connected_db | ||||||
|       .collection(id) |       .collection(id) | ||||||
|       .update( |       .update({ | ||||||
|         { _id: "_chat_" }, |           _id: "_chat_" | ||||||
|         { $set: { password: pass, name: name } }, |         }, { | ||||||
|         { upsert: true }, |           $set: { | ||||||
|         function(e) { |             password: pass, | ||||||
|  |             name: name | ||||||
|  |           } | ||||||
|  |         }, { | ||||||
|  |           upsert: true | ||||||
|  |         }, | ||||||
|  |         function (e) { | ||||||
|           callback(); |           callback(); | ||||||
|           return; |           return; | ||||||
|         } |         } | ||||||
| @@ -414,7 +488,9 @@ function getSessionChatPass(id, callback) { | |||||||
|       return; |       return; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     connected_db.collection(id).find({ _id: "_chat_" }, function(e, d) { |     connected_db.collection(id).find({ | ||||||
|  |       _id: "_chat_" | ||||||
|  |     }, function (e, d) { | ||||||
|       if (d.length > 0) { |       if (d.length > 0) { | ||||||
|         var name = ""; |         var name = ""; | ||||||
|         var pass = ""; |         var pass = ""; | ||||||
| @@ -446,11 +522,15 @@ function setChromecastHost(id, other_id, list, callback) { | |||||||
|     } |     } | ||||||
|     connected_db |     connected_db | ||||||
|       .collection(id) |       .collection(id) | ||||||
|       .update( |       .update({ | ||||||
|         { _id: list }, |           _id: list | ||||||
|         { chromecast: true, id: other_id }, |         }, { | ||||||
|         { upsert: true }, |           chromecast: true, | ||||||
|         function(e, docs) { |           id: other_id | ||||||
|  |         }, { | ||||||
|  |           upsert: true | ||||||
|  |         }, | ||||||
|  |         function (e, docs) { | ||||||
|           callback(true); |           callback(true); | ||||||
|           return; |           return; | ||||||
|         } |         } | ||||||
| @@ -469,11 +549,16 @@ function setSessionUserPass(id, userpass, list, callback) { | |||||||
|  |  | ||||||
|     connected_db |     connected_db | ||||||
|       .collection(id) |       .collection(id) | ||||||
|       .update( |       .update({ | ||||||
|         { _id: list }, |           _id: list | ||||||
|         { $set: { userpass: userpass } }, |         }, { | ||||||
|         { upsert: true }, |           $set: { | ||||||
|         function(e, d) { |             userpass: userpass | ||||||
|  |           } | ||||||
|  |         }, { | ||||||
|  |           upsert: true | ||||||
|  |         }, | ||||||
|  |         function (e, d) { | ||||||
|           callback(); |           callback(); | ||||||
|           return; |           return; | ||||||
|         } |         } | ||||||
| @@ -489,7 +574,9 @@ function getSessionAdminUser(id, list, callback) { | |||||||
|       callback("", "", false); |       callback("", "", false); | ||||||
|       return; |       return; | ||||||
|     } |     } | ||||||
|     connected_db.collection(id).find({ _id: list }, function(e, d) { |     connected_db.collection(id).find({ | ||||||
|  |       _id: list | ||||||
|  |     }, function (e, d) { | ||||||
|       var userpass = ""; |       var userpass = ""; | ||||||
|       var adminpass = ""; |       var adminpass = ""; | ||||||
|       if (d.length > 0) { |       if (d.length > 0) { | ||||||
| @@ -514,7 +601,9 @@ function removeSessionChatPass(id, callback) { | |||||||
|     callback(); |     callback(); | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   connected_db.collection(id).remove({ _id: "_chat_" }, function() { |   connected_db.collection(id).remove({ | ||||||
|  |     _id: "_chat_" | ||||||
|  |   }, function () { | ||||||
|     callback(); |     callback(); | ||||||
|     return; |     return; | ||||||
|   }); |   }); | ||||||
| @@ -527,17 +616,27 @@ function removeSessionAdminPass(id, channel, callback) { | |||||||
|   } |   } | ||||||
|   connected_db |   connected_db | ||||||
|     .collection(id) |     .collection(id) | ||||||
|     .update({ _id: channel }, { $set: { adminpass: "" } }, function() { |     .update({ | ||||||
|  |       _id: channel | ||||||
|  |     }, { | ||||||
|  |       $set: { | ||||||
|  |         adminpass: "" | ||||||
|  |       } | ||||||
|  |     }, function () { | ||||||
|       callback(); |       callback(); | ||||||
|       return; |       return; | ||||||
|     }); |     }); | ||||||
| } | } | ||||||
|  |  | ||||||
| function remove_from_chat_channel(coll, guid) { | function remove_from_chat_channel(coll, guid) { | ||||||
|   db.collection("user_names").update( |   db.collection("user_names").update({ | ||||||
|     { guid: guid }, |       guid: guid | ||||||
|     { $pull: { channels: coll } }, |     }, { | ||||||
|     function(err, docs) {} |       $pull: { | ||||||
|  |         channels: coll | ||||||
|  |       } | ||||||
|  |     }, | ||||||
|  |     function (err, docs) {} | ||||||
|   ); |   ); | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -551,25 +650,44 @@ function left_channel(coll, guid, short_id, in_list, socket, change, caller) { | |||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   //coll = coll.replace(/ /g,''); |   //coll = coll.replace(/ /g,''); | ||||||
|   db.collection("connected_users").update( |   db.collection("connected_users").update({ | ||||||
|     { _id: coll }, |       _id: coll | ||||||
|     { $pull: { users: guid } }, |     }, { | ||||||
|     function(err, updated) { |       $pull: { | ||||||
|  |         users: guid | ||||||
|  |       } | ||||||
|  |     }, | ||||||
|  |     function (err, updated) { | ||||||
|       if (updated.nModified > 0) { |       if (updated.nModified > 0) { | ||||||
|         db.collection("connected_users").update( |         db.collection("connected_users").update({ | ||||||
|           { _id: "total_users" }, |             _id: "total_users" | ||||||
|           { $pull: { total_users: guid + coll } }, |           }, { | ||||||
|           function(err, updated) {} |             $pull: { | ||||||
|  |               total_users: guid + coll | ||||||
|  |             } | ||||||
|  |           }, | ||||||
|  |           function (err, updated) {} | ||||||
|         ); |         ); | ||||||
|         db.collection("connected_users").find({ _id: coll }, function( |         db.collection("connected_users").find({ | ||||||
|  |           _id: coll | ||||||
|  |         }, function ( | ||||||
|           err, |           err, | ||||||
|           new_doc |           new_doc | ||||||
|         ) { |         ) { | ||||||
|           db.collection("frontpage_lists").update( |           db.collection("frontpage_lists").update({ | ||||||
|             { _id: coll, viewers: { $gt: 0 } }, |               _id: coll, | ||||||
|             { $inc: { viewers: -1 } }, |               viewers: { | ||||||
|             function(err, doc) { |                 $gt: 0 | ||||||
|               db.collection("user_names").find({ guid: guid }, function( |               } | ||||||
|  |             }, { | ||||||
|  |               $inc: { | ||||||
|  |                 viewers: -1 | ||||||
|  |               } | ||||||
|  |             }, | ||||||
|  |             function (err, doc) { | ||||||
|  |               db.collection("user_names").find({ | ||||||
|  |                 guid: guid | ||||||
|  |               }, function ( | ||||||
|                 err, |                 err, | ||||||
|                 docs |                 docs | ||||||
|               ) { |               ) { | ||||||
| @@ -594,15 +712,23 @@ function left_channel(coll, guid, short_id, in_list, socket, change, caller) { | |||||||
|           ); |           ); | ||||||
|         }); |         }); | ||||||
|       } else { |       } else { | ||||||
|         db.collection("connected_users").update( |         db.collection("connected_users").update({ | ||||||
|           { _id: "offline_users" }, |             _id: "offline_users" | ||||||
|           { $pull: { users: guid } }, |           }, { | ||||||
|           function(err, updated) { |             $pull: { | ||||||
|  |               users: guid | ||||||
|  |             } | ||||||
|  |           }, | ||||||
|  |           function (err, updated) { | ||||||
|             //if(updated.nModified > 0) { |             //if(updated.nModified > 0) { | ||||||
|             db.collection("connected_users").update( |             db.collection("connected_users").update({ | ||||||
|               { _id: "total_users" }, |                 _id: "total_users" | ||||||
|               { $pull: { total_users: guid + coll } }, |               }, { | ||||||
|               function(err, updated) {} |                 $pull: { | ||||||
|  |                   total_users: guid + coll | ||||||
|  |                 } | ||||||
|  |               }, | ||||||
|  |               function (err, updated) {} | ||||||
|             ); |             ); | ||||||
|             if (!change) { |             if (!change) { | ||||||
|               remove_name_from_db(guid, coll); |               remove_name_from_db(guid, coll); | ||||||
| @@ -634,12 +760,11 @@ function checkTimeout( | |||||||
|     callback(); |     callback(); | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   db.collection("timeout_api").find( |   db.collection("timeout_api").find({ | ||||||
|     { |  | ||||||
|       type: type, |       type: type, | ||||||
|       guid: guid |       guid: guid | ||||||
|     }, |     }, | ||||||
|     function(err, docs) { |     function (err, docs) { | ||||||
|       if (docs.length > 0) { |       if (docs.length > 0) { | ||||||
|         var date = new Date(docs[0].createdAt); |         var date = new Date(docs[0].createdAt); | ||||||
|         date.setSeconds(date.getSeconds() + timeout); |         date.setSeconds(date.getSeconds() + timeout); | ||||||
| @@ -663,17 +788,19 @@ function checkTimeout( | |||||||
|         } |         } | ||||||
|       } |       } | ||||||
|       var now_date = new Date(); |       var now_date = new Date(); | ||||||
|       db.collection("timeout_api").update( |       db.collection("timeout_api").update({ | ||||||
|         { type: type, guid: guid }, |           type: type, | ||||||
|         { |           guid: guid | ||||||
|  |         }, { | ||||||
|           $set: { |           $set: { | ||||||
|             createdAt: now_date, |             createdAt: now_date, | ||||||
|             type: type, |             type: type, | ||||||
|             guid: guid |             guid: guid | ||||||
|           } |           } | ||||||
|  |         }, { | ||||||
|  |           upsert: true | ||||||
|         }, |         }, | ||||||
|         { upsert: true }, |         function (err, docs) { | ||||||
|         function(err, docs) { |  | ||||||
|           callback(); |           callback(); | ||||||
|           return; |           return; | ||||||
|         } |         } | ||||||
| @@ -707,4 +834,4 @@ module.exports.rndName = rndName; | |||||||
| module.exports.decrypt_string = decrypt_string; | module.exports.decrypt_string = decrypt_string; | ||||||
| module.exports.get_time = get_time; | module.exports.get_time = get_time; | ||||||
| module.exports.contains = contains; | module.exports.contains = contains; | ||||||
| module.exports.hash_pass = hash_pass; | module.exports.hash_pass = hash_pass; | ||||||
| @@ -11,7 +11,9 @@ var Frontpage = require(pathThumbnails + "/handlers/frontpage.js"); | |||||||
| var Search = require(pathThumbnails + "/handlers/search.js"); | var Search = require(pathThumbnails + "/handlers/search.js"); | ||||||
| var crypto = require("crypto"); | var crypto = require("crypto"); | ||||||
| var Filter = require("bad-words"); | var Filter = require("bad-words"); | ||||||
| var filter = new Filter({ placeHolder: "x" }); | var filter = new Filter({ | ||||||
|  |   placeHolder: "x" | ||||||
|  | }); | ||||||
| /*var filter = { | /*var filter = { | ||||||
|     clean: function(str) { |     clean: function(str) { | ||||||
|         return str; |         return str; | ||||||
| @@ -19,8 +21,8 @@ var filter = new Filter({ placeHolder: "x" }); | |||||||
| }*/ | }*/ | ||||||
| var db = require(pathThumbnails + "/handlers/db.js"); | 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 { | ||||||
|       var parsedCookies = cookie.parse(socket.handshake.headers.cookie); |       var parsedCookies = cookie.parse(socket.handshake.headers.cookie); | ||||||
|       socket.cookie_id = parsedCookies["_uI"]; |       socket.cookie_id = parsedCookies["_uI"]; | ||||||
| @@ -34,14 +36,14 @@ module.exports = function() { | |||||||
|     if (guid == "empty" || guid == null || guid == undefined) |     if (guid == "empty" || guid == null || guid == undefined) | ||||||
|       guid = Functions.hash_pass( |       guid = Functions.hash_pass( | ||||||
|         socket.handshake.headers["user-agent"] + |         socket.handshake.headers["user-agent"] + | ||||||
|           socket.handshake.address + |         socket.handshake.address + | ||||||
|           socket.handshake.headers["accept-language"] |         socket.handshake.headers["accept-language"] | ||||||
|       ); |       ); | ||||||
|  |  | ||||||
|     socket.guid = guid; |     socket.guid = guid; | ||||||
|     socket.on("close", function() {}); |     socket.on("close", function () {}); | ||||||
|  |  | ||||||
|     socket.on("pinging", function() { |     socket.on("pinging", function () { | ||||||
|       socket.emit("ok"); |       socket.emit("ok"); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
| @@ -51,13 +53,16 @@ module.exports = function() { | |||||||
|     var in_list = false; |     var in_list = false; | ||||||
|     var name = ""; |     var name = ""; | ||||||
|     var short_id; |     var short_id; | ||||||
|     Chat.get_name(guid, { announce: false, socket: socket }); |     Chat.get_name(guid, { | ||||||
|  |       announce: false, | ||||||
|  |       socket: socket | ||||||
|  |     }); | ||||||
|     var offline = false; |     var offline = false; | ||||||
|     var chromecast_object = false; |     var chromecast_object = false; | ||||||
|  |  | ||||||
|     socket.emit("guid", guid); |     socket.emit("guid", guid); | ||||||
|  |  | ||||||
|     socket.on("self_ping", function(msg) { |     socket.on("self_ping", function (msg) { | ||||||
|       var channel = msg.channel; |       var channel = msg.channel; | ||||||
|       if (channel.indexOf("?") > -1) { |       if (channel.indexOf("?") > -1) { | ||||||
|         channel = channel.substring(0, channel.indexOf("?")); |         channel = channel.substring(0, channel.indexOf("?")); | ||||||
| @@ -67,48 +72,68 @@ module.exports = function() { | |||||||
|       } |       } | ||||||
|       //channel = channel.replace(/ /g,''); |       //channel = channel.replace(/ /g,''); | ||||||
|       if (offline) { |       if (offline) { | ||||||
|         db.collection("connected_users").update( |         db.collection("connected_users").update({ | ||||||
|           { _id: "offline_users" }, |             _id: "offline_users" | ||||||
|           { $addToSet: { users: guid } }, |           }, { | ||||||
|           { upsert: true }, |             $addToSet: { | ||||||
|           function(err, docs) {} |               users: guid | ||||||
|  |             } | ||||||
|  |           }, { | ||||||
|  |             upsert: true | ||||||
|  |           }, | ||||||
|  |           function (err, docs) {} | ||||||
|         ); |         ); | ||||||
|       } else { |       } else { | ||||||
|         db.collection("connected_users").update( |         db.collection("connected_users").update({ | ||||||
|           { _id: channel }, |             _id: channel | ||||||
|           { $addToSet: { users: guid } }, |           }, { | ||||||
|           { upsert: true }, |             $addToSet: { | ||||||
|           function(err, docs) { |               users: guid | ||||||
|             db.collection("frontpage_lists").update( |             } | ||||||
|               { _id: channel }, |           }, { | ||||||
|               { $inc: { viewers: 1 } }, |             upsert: true | ||||||
|               { upsert: true }, |           }, | ||||||
|               function() {} |           function (err, docs) { | ||||||
|  |             db.collection("frontpage_lists").update({ | ||||||
|  |                 _id: channel | ||||||
|  |               }, { | ||||||
|  |                 $inc: { | ||||||
|  |                   viewers: 1 | ||||||
|  |                 } | ||||||
|  |               }, { | ||||||
|  |                 upsert: true | ||||||
|  |               }, | ||||||
|  |               function () {} | ||||||
|             ); |             ); | ||||||
|           } |           } | ||||||
|         ); |         ); | ||||||
|       } |       } | ||||||
|       if (channel != "" && channel != undefined) { |       if (channel != "" && channel != undefined) { | ||||||
|         db.collection("connected_users").update( |         db.collection("connected_users").update({ | ||||||
|           { _id: "total_users" }, |             _id: "total_users" | ||||||
|           { $addToSet: { total_users: guid + channel } }, |           }, { | ||||||
|           { upsert: true }, |             $addToSet: { | ||||||
|           function(err, docs) {} |               total_users: guid + channel | ||||||
|  |             } | ||||||
|  |           }, { | ||||||
|  |             upsert: true | ||||||
|  |           }, | ||||||
|  |           function (err, docs) {} | ||||||
|         ); |         ); | ||||||
|       } |       } | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     socket.on("logout", function() { |     socket.on("logout", function () { | ||||||
|       Functions.removeSessionAdminPass( |       Functions.removeSessionAdminPass( | ||||||
|         Functions.getSession(socket), |         Functions.getSession(socket), | ||||||
|         coll, |         coll, | ||||||
|         function() {} |         function () {} | ||||||
|       ); |       ); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     socket.on("next_song", function(obj) { |     socket.on("next_song", function (obj) { | ||||||
|       if (obj == undefined || !obj.hasOwnProperty("channel")) return; |       if (obj == undefined || !obj.hasOwnProperty("channel")) return; | ||||||
|       db.collection(obj.channel + "_settings").find(function(e, docs) { |       db.collection(obj.channel + "_settings").find(function (e, docs) { | ||||||
|         if (docs.length == 0) return; |         if (docs.length == 0) return; | ||||||
|         var pass = ""; |         var pass = ""; | ||||||
|         if (obj.hasOwnProperty("pass")) { |         if (obj.hasOwnProperty("pass")) { | ||||||
| @@ -128,7 +153,7 @@ module.exports = function() { | |||||||
|       }); |       }); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     socket.on("chromecast", function(msg) { |     socket.on("chromecast", function (msg) { | ||||||
|       try { |       try { | ||||||
|         if ( |         if ( | ||||||
|           typeof msg == "object" && |           typeof msg == "object" && | ||||||
| @@ -143,7 +168,9 @@ module.exports = function() { | |||||||
|           if (msg.hasOwnProperty("channel")) { |           if (msg.hasOwnProperty("channel")) { | ||||||
|             msg.channel = Functions.encodeChannelName(msg.channel); |             msg.channel = Functions.encodeChannelName(msg.channel); | ||||||
|           } |           } | ||||||
|           db.collection("connected_users").find({ _id: msg.channel }, function( |           db.collection("connected_users").find({ | ||||||
|  |             _id: msg.channel | ||||||
|  |           }, function ( | ||||||
|             err, |             err, | ||||||
|             connected_users_channel |             connected_users_channel | ||||||
|           ) { |           ) { | ||||||
| @@ -161,7 +188,7 @@ module.exports = function() { | |||||||
|                 socket.cookie_id, |                 socket.cookie_id, | ||||||
|                 msg.socket_id, |                 msg.socket_id, | ||||||
|                 msg.channel, |                 msg.channel, | ||||||
|                 function(results) {} |                 function (results) {} | ||||||
|               ); |               ); | ||||||
|               //socket.cookie_id = msg.guid; |               //socket.cookie_id = msg.guid; | ||||||
|               guid = msg.guid; |               guid = msg.guid; | ||||||
| @@ -179,14 +206,14 @@ module.exports = function() { | |||||||
|       } |       } | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     socket.on("get_id", function() { |     socket.on("get_id", function () { | ||||||
|       socket.emit("id_chromecast", { |       socket.emit("id_chromecast", { | ||||||
|         cookie_id: Functions.getSession(socket), |         cookie_id: Functions.getSession(socket), | ||||||
|         guid: guid |         guid: guid | ||||||
|       }); |       }); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     socket.on("error_video", function(msg) { |     socket.on("error_video", function (msg) { | ||||||
|       try { |       try { | ||||||
|         msg.channel = Functions.encodeChannelName(msg.channel); |         msg.channel = Functions.encodeChannelName(msg.channel); | ||||||
|         var _list = msg.channel; //.replace(/ /g,''); |         var _list = msg.channel; //.replace(/ /g,''); | ||||||
| @@ -208,17 +235,26 @@ module.exports = function() { | |||||||
|       Search.check_error_video(msg, coll); |       Search.check_error_video(msg, coll); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     socket.on("get_spread", function() { |     socket.on("get_spread", function () { | ||||||
|       db.collection("connected_users").find({ _id: "total_users" }, function( |       db.collection("connected_users").find({ | ||||||
|  |         _id: "total_users" | ||||||
|  |       }, function ( | ||||||
|         err, |         err, | ||||||
|         tot |         tot | ||||||
|       ) { |       ) { | ||||||
|         db.collection("connected_users").find( |         db.collection("connected_users").find({ | ||||||
|           { _id: "offline_users" }, |             _id: "offline_users" | ||||||
|           function(err, off) { |           }, | ||||||
|             db.collection("connected_users").find( |           function (err, off) { | ||||||
|               { _id: { $ne: "total_users" }, _id: { $ne: "offline_users" } }, |             db.collection("connected_users").find({ | ||||||
|               function(err, users_list) { |                 _id: { | ||||||
|  |                   $ne: "total_users" | ||||||
|  |                 }, | ||||||
|  |                 _id: { | ||||||
|  |                   $ne: "offline_users" | ||||||
|  |                 } | ||||||
|  |               }, | ||||||
|  |               function (err, users_list) { | ||||||
|                 if (tot.length > 0 && off.length == 0) { |                 if (tot.length > 0 && off.length == 0) { | ||||||
|                   socket.emit("spread_listeners", { |                   socket.emit("spread_listeners", { | ||||||
|                     offline: 0, |                     offline: 0, | ||||||
| @@ -239,7 +275,7 @@ module.exports = function() { | |||||||
|       }); |       }); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     socket.on("suggest_thumbnail", function(msg) { |     socket.on("suggest_thumbnail", function (msg) { | ||||||
|       if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) { |       if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) { | ||||||
|         var _list = msg.channel.substring(0, msg.channel.indexOf("?")); |         var _list = msg.channel.substring(0, msg.channel.indexOf("?")); | ||||||
|         msg.channel = _list; |         msg.channel = _list; | ||||||
| @@ -250,7 +286,7 @@ module.exports = function() { | |||||||
|       Suggestions.thumbnail(msg, coll, guid, offline, socket); |       Suggestions.thumbnail(msg, coll, guid, offline, socket); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     socket.on("suggest_description", function(msg) { |     socket.on("suggest_description", function (msg) { | ||||||
|       if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) { |       if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) { | ||||||
|         var _list = msg.channel.substring(0, msg.channel.indexOf("?")); |         var _list = msg.channel.substring(0, msg.channel.indexOf("?")); | ||||||
|         msg.channel = _list; |         msg.channel = _list; | ||||||
| @@ -261,7 +297,7 @@ module.exports = function() { | |||||||
|       Suggestions.description(msg, coll, guid, offline, socket); |       Suggestions.description(msg, coll, guid, offline, socket); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     socket.on("suggest_rules", function(msg) { |     socket.on("suggest_rules", function (msg) { | ||||||
|       if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) { |       if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) { | ||||||
|         var _list = msg.channel.substring(0, msg.channel.indexOf("?")); |         var _list = msg.channel.substring(0, msg.channel.indexOf("?")); | ||||||
|         msg.channel = _list; |         msg.channel = _list; | ||||||
| @@ -272,7 +308,7 @@ module.exports = function() { | |||||||
|       Suggestions.rules(msg, coll, guid, offline, socket); |       Suggestions.rules(msg, coll, guid, offline, socket); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     socket.on("namechange", function(msg) { |     socket.on("namechange", function (msg) { | ||||||
|       if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) { |       if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) { | ||||||
|         var _list = msg.channel.substring(0, msg.channel.indexOf("?")); |         var _list = msg.channel.substring(0, msg.channel.indexOf("?")); | ||||||
|         msg.channel = _list; |         msg.channel = _list; | ||||||
| @@ -283,7 +319,7 @@ module.exports = function() { | |||||||
|       Chat.namechange(msg, guid, socket); |       Chat.namechange(msg, guid, socket); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     socket.on("removename", function(msg) { |     socket.on("removename", function (msg) { | ||||||
|       if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) { |       if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) { | ||||||
|         var _list = msg.channel.substring(0, msg.channel.indexOf("?")); |         var _list = msg.channel.substring(0, msg.channel.indexOf("?")); | ||||||
|         msg.channel = _list; |         msg.channel = _list; | ||||||
| @@ -304,7 +340,7 @@ module.exports = function() { | |||||||
|       Chat.removename(guid, msg.channel, socket); |       Chat.removename(guid, msg.channel, socket); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     socket.on("offline", function(msg) { |     socket.on("offline", function (msg) { | ||||||
|       if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) { |       if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) { | ||||||
|         var _list = msg.channel.substring(0, msg.channel.indexOf("?")); |         var _list = msg.channel.substring(0, msg.channel.indexOf("?")); | ||||||
|         msg.channel = _list; |         msg.channel = _list; | ||||||
| @@ -340,41 +376,66 @@ module.exports = function() { | |||||||
|         if (coll !== undefined) { |         if (coll !== undefined) { | ||||||
|           coll = Functions.removeEmojis(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({ | ||||||
|             { |               query: { | ||||||
|               query: { _id: coll }, |                 _id: coll | ||||||
|               update: { $pull: { users: guid } }, |               }, | ||||||
|  |               update: { | ||||||
|  |                 $pull: { | ||||||
|  |                   users: guid | ||||||
|  |                 } | ||||||
|  |               }, | ||||||
|               upsert: true |               upsert: true | ||||||
|             }, |             }, | ||||||
|             function(err, updated, d) { |             function (err, updated, d) { | ||||||
|               if (d.n == 1) { |               if (d.n == 1) { | ||||||
|                 var num = 0; |                 var num = 0; | ||||||
|                 if (updated && updated.users) { |                 if (updated && updated.users) { | ||||||
|                   num = updated.users.length; |                   num = updated.users.length; | ||||||
|                 } |                 } | ||||||
|                 io.to(coll).emit("viewers", num); |                 io.to(coll).emit("viewers", num); | ||||||
|                 db.collection("frontpage_lists").update( |                 db.collection("frontpage_lists").update({ | ||||||
|                   { _id: coll, viewers: { $gt: 0 } }, |                     _id: coll, | ||||||
|                   { $inc: { viewers: -1 } }, |                     viewers: { | ||||||
|                   function(err, docs) {} |                       $gt: 0 | ||||||
|  |                     } | ||||||
|  |                   }, { | ||||||
|  |                     $inc: { | ||||||
|  |                       viewers: -1 | ||||||
|  |                     } | ||||||
|  |                   }, | ||||||
|  |                   function (err, docs) {} | ||||||
|                 ); |                 ); | ||||||
|                 db.collection("connected_users").update( |                 db.collection("connected_users").update({ | ||||||
|                   { _id: "total_users" }, |                     _id: "total_users" | ||||||
|                   { $pull: { total_users: guid + coll } }, |                   }, { | ||||||
|                   function(err, docs) { |                     $pull: { | ||||||
|                     db.collection("connected_users").update( |                       total_users: guid + coll | ||||||
|                       { _id: "offline_users" }, |                     } | ||||||
|                       { $addToSet: { users: guid } }, |                   }, | ||||||
|                       { upsert: true }, |                   function (err, docs) { | ||||||
|                       function(err, docs) { |                     db.collection("connected_users").update({ | ||||||
|  |                         _id: "offline_users" | ||||||
|  |                       }, { | ||||||
|  |                         $addToSet: { | ||||||
|  |                           users: guid | ||||||
|  |                         } | ||||||
|  |                       }, { | ||||||
|  |                         upsert: true | ||||||
|  |                       }, | ||||||
|  |                       function (err, docs) { | ||||||
|                         if ( |                         if ( | ||||||
|                           docs.nModified == 1 && |                           docs.nModified == 1 && | ||||||
|                           (coll != undefined && coll != "") |                           (coll != undefined && coll != "") | ||||||
|                         ) { |                         ) { | ||||||
|                           db.collection("connected_users").update( |                           db.collection("connected_users").update({ | ||||||
|                             { _id: "total_users" }, |                               _id: "total_users" | ||||||
|                             { $addToSet: { total_users: guid + coll } }, |                             }, { | ||||||
|                             function(err, docs) {} |                               $addToSet: { | ||||||
|  |                                 total_users: guid + coll | ||||||
|  |                               } | ||||||
|  |                             }, | ||||||
|  |                             function (err, docs) {} | ||||||
|                           ); |                           ); | ||||||
|                         } |                         } | ||||||
|                       } |                       } | ||||||
| @@ -390,10 +451,14 @@ module.exports = function() { | |||||||
|         Functions.remove_unique_id(short_id); |         Functions.remove_unique_id(short_id); | ||||||
|       } else { |       } else { | ||||||
|         offline = false; |         offline = false; | ||||||
|         db.collection("connected_users").update( |         db.collection("connected_users").update({ | ||||||
|           { _id: "offline_users" }, |             _id: "offline_users" | ||||||
|           { $pull: { users: guid } }, |           }, { | ||||||
|           function(err, docs) { |             $pull: { | ||||||
|  |               users: guid | ||||||
|  |             } | ||||||
|  |           }, | ||||||
|  |           function (err, docs) { | ||||||
|             Functions.check_inlist( |             Functions.check_inlist( | ||||||
|               coll, |               coll, | ||||||
|               guid, |               guid, | ||||||
| @@ -407,7 +472,7 @@ module.exports = function() { | |||||||
|       } |       } | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     socket.on("get_history", function(msg) { |     socket.on("get_history", function (msg) { | ||||||
|       if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) { |       if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) { | ||||||
|         var _list = msg.channel.substring(0, msg.channel.indexOf("?")); |         var _list = msg.channel.substring(0, msg.channel.indexOf("?")); | ||||||
|         msg.channel = _list; |         msg.channel = _list; | ||||||
| @@ -441,7 +506,7 @@ module.exports = function() { | |||||||
|       Chat.get_history(msg.channel, msg.all, socket); |       Chat.get_history(msg.channel, msg.all, socket); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     socket.on("chat", function(msg) { |     socket.on("chat", function (msg) { | ||||||
|       if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) { |       if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) { | ||||||
|         var _list = msg.channel.substring(0, msg.channel.indexOf("?")); |         var _list = msg.channel.substring(0, msg.channel.indexOf("?")); | ||||||
|         msg.channel = _list; |         msg.channel = _list; | ||||||
| @@ -452,7 +517,7 @@ module.exports = function() { | |||||||
|       Chat.chat(msg, guid, offline, socket); |       Chat.chat(msg, guid, offline, socket); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     socket.on("all,chat", function(data) { |     socket.on("all,chat", function (data) { | ||||||
|       if (data.hasOwnProperty("channel") && data.channel.indexOf("?") > -1) { |       if (data.hasOwnProperty("channel") && data.channel.indexOf("?") > -1) { | ||||||
|         var _list = data.channel.substring(0, data.channel.indexOf("?")); |         var _list = data.channel.substring(0, data.channel.indexOf("?")); | ||||||
|         data.channel = _list; |         data.channel = _list; | ||||||
| @@ -463,7 +528,7 @@ module.exports = function() { | |||||||
|       Chat.all_chat(data, guid, offline, socket); |       Chat.all_chat(data, guid, offline, socket); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     socket.on("frontpage_lists", function(msg) { |     socket.on("frontpage_lists", function (msg) { | ||||||
|       if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) { |       if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) { | ||||||
|         var _list = msg.channel.substring(0, msg.channel.indexOf("?")); |         var _list = msg.channel.substring(0, msg.channel.indexOf("?")); | ||||||
|         msg.channel = _list; |         msg.channel = _list; | ||||||
| @@ -474,7 +539,7 @@ module.exports = function() { | |||||||
|       Frontpage.frontpage_lists(msg, socket); |       Frontpage.frontpage_lists(msg, socket); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     socket.on("import_zoff", function(msg) { |     socket.on("import_zoff", function (msg) { | ||||||
|       if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) { |       if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) { | ||||||
|         var _list = msg.channel.substring(0, msg.channel.indexOf("?")); |         var _list = msg.channel.substring(0, msg.channel.indexOf("?")); | ||||||
|         msg.channel = _list; |         msg.channel = _list; | ||||||
| @@ -485,11 +550,11 @@ module.exports = function() { | |||||||
|       ListChange.addFromOtherList(msg, guid, offline, socket); |       ListChange.addFromOtherList(msg, guid, offline, socket); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     socket.on("now_playing", function(list, fn) { |     socket.on("now_playing", function (list, fn) { | ||||||
|       List.now_playing(list, fn, socket); |       List.now_playing(list, fn, socket); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     socket.on("id", function(arr) { |     socket.on("id", function (arr) { | ||||||
|       if (arr.hasOwnProperty("channel") && arr.channel.indexOf("?") > -1) { |       if (arr.hasOwnProperty("channel") && arr.channel.indexOf("?") > -1) { | ||||||
|         var _list = arr.channel.substring(0, arr.channel.indexOf("?")); |         var _list = arr.channel.substring(0, arr.channel.indexOf("?")); | ||||||
|         arr.channel = _list; |         arr.channel = _list; | ||||||
| @@ -504,7 +569,7 @@ module.exports = function() { | |||||||
|         }); |         }); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     socket.on("join_silent", function(msg) { |     socket.on("join_silent", function (msg) { | ||||||
|       if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) { |       if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) { | ||||||
|         var _list = msg.channel.substring(0, msg.channel.indexOf("?")); |         var _list = msg.channel.substring(0, msg.channel.indexOf("?")); | ||||||
|         msg.channel = _list; |         msg.channel = _list; | ||||||
| @@ -517,7 +582,7 @@ module.exports = function() { | |||||||
|       List.join_silent(msg, socket); |       List.join_silent(msg, socket); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     socket.on("list", function(msg) { |     socket.on("list", function (msg) { | ||||||
|       if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) { |       if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) { | ||||||
|         var _list = msg.channel.substring(0, msg.channel.indexOf("?")); |         var _list = msg.channel.substring(0, msg.channel.indexOf("?")); | ||||||
|         msg.channel = _list; |         msg.channel = _list; | ||||||
| @@ -548,7 +613,7 @@ module.exports = function() { | |||||||
|       Functions.get_short_id(socket); |       Functions.get_short_id(socket); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     socket.on("end", function(obj) { |     socket.on("end", function (obj) { | ||||||
|       if (obj.hasOwnProperty("channel") && obj.channel.indexOf("?") > -1) { |       if (obj.hasOwnProperty("channel") && obj.channel.indexOf("?") > -1) { | ||||||
|         var _list = obj.channel.substring(0, obj.channel.indexOf("?")); |         var _list = obj.channel.substring(0, obj.channel.indexOf("?")); | ||||||
|         obj.channel = _list; |         obj.channel = _list; | ||||||
| @@ -570,7 +635,7 @@ module.exports = function() { | |||||||
|       List.end(obj, coll, guid, offline, socket); |       List.end(obj, coll, guid, offline, socket); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     socket.on("addPlaylist", function(arr) { |     socket.on("addPlaylist", function (arr) { | ||||||
|       if (arr.hasOwnProperty("channel") && arr.channel.indexOf("?") > -1) { |       if (arr.hasOwnProperty("channel") && arr.channel.indexOf("?") > -1) { | ||||||
|         var _list = arr.channel.substring(0, arr.channel.indexOf("?")); |         var _list = arr.channel.substring(0, arr.channel.indexOf("?")); | ||||||
|         arr.channel = _list; |         arr.channel = _list; | ||||||
| @@ -581,7 +646,7 @@ module.exports = function() { | |||||||
|       ListChange.addPlaylist(arr, guid, offline, socket); |       ListChange.addPlaylist(arr, guid, offline, socket); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     socket.on("add", function(arr) { |     socket.on("add", function (arr) { | ||||||
|       if (arr.hasOwnProperty("list") && arr.list.indexOf("?") > -1) { |       if (arr.hasOwnProperty("list") && arr.list.indexOf("?") > -1) { | ||||||
|         var _list = arr.list.substring(0, arr.list.indexOf("?")); |         var _list = arr.list.substring(0, arr.list.indexOf("?")); | ||||||
|         arr.list = _list; |         arr.list = _list; | ||||||
| @@ -610,7 +675,7 @@ module.exports = function() { | |||||||
|       ListChange.add_function(arr, coll, guid, offline, socket); |       ListChange.add_function(arr, coll, guid, offline, socket); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     socket.on("delete_all", function(msg) { |     socket.on("delete_all", function (msg) { | ||||||
|       try { |       try { | ||||||
|         if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) { |         if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) { | ||||||
|           var _list = msg.channel.substring(0, msg.channel.indexOf("?")); |           var _list = msg.channel.substring(0, msg.channel.indexOf("?")); | ||||||
| @@ -632,7 +697,7 @@ module.exports = function() { | |||||||
|       ListChange.delete_all(msg, coll, guid, offline, socket); |       ListChange.delete_all(msg, coll, guid, offline, socket); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     socket.on("vote", function(msg) { |     socket.on("vote", function (msg) { | ||||||
|       if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) { |       if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) { | ||||||
|         var _list = msg.channel.substring(0, msg.channel.indexOf("?")); |         var _list = msg.channel.substring(0, msg.channel.indexOf("?")); | ||||||
|         msg.channel = _list; |         msg.channel = _list; | ||||||
| @@ -655,7 +720,7 @@ module.exports = function() { | |||||||
|       ListChange.voteUndecided(msg, coll, guid, offline, socket); |       ListChange.voteUndecided(msg, coll, guid, offline, socket); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     socket.on("password", function(inp) { |     socket.on("password", function (inp) { | ||||||
|       if (inp.hasOwnProperty("channel") && inp.channel.indexOf("?") > -1) { |       if (inp.hasOwnProperty("channel") && inp.channel.indexOf("?") > -1) { | ||||||
|         var _list = inp.channel.substring(0, inp.channel.indexOf("?")); |         var _list = inp.channel.substring(0, inp.channel.indexOf("?")); | ||||||
|         inp.channel = _list; |         inp.channel = _list; | ||||||
| @@ -667,7 +732,7 @@ module.exports = function() { | |||||||
|       ListSettings.password(inp, coll, guid, offline, socket); |       ListSettings.password(inp, coll, guid, offline, socket); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     socket.on("skip", function(list) { |     socket.on("skip", function (list) { | ||||||
|       if (list.hasOwnProperty("channel") && list.channel.indexOf("?") > -1) { |       if (list.hasOwnProperty("channel") && list.channel.indexOf("?") > -1) { | ||||||
|         var _list = list.channel.substring(0, list.channel.indexOf("?")); |         var _list = list.channel.substring(0, list.channel.indexOf("?")); | ||||||
|         list.channel = _list; |         list.channel = _list; | ||||||
| @@ -680,7 +745,7 @@ module.exports = function() { | |||||||
|       List.skip(list, guid, coll, offline, socket); |       List.skip(list, guid, coll, offline, socket); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     socket.on("conf", function(conf) { |     socket.on("conf", function (conf) { | ||||||
|       if (conf.hasOwnProperty("channel") && conf.channel.indexOf("?") > -1) { |       if (conf.hasOwnProperty("channel") && conf.channel.indexOf("?") > -1) { | ||||||
|         var _list = conf.channel.substring(0, conf.channel.indexOf("?")); |         var _list = conf.channel.substring(0, conf.channel.indexOf("?")); | ||||||
|         conf.channel = _list; |         conf.channel = _list; | ||||||
| @@ -694,7 +759,7 @@ module.exports = function() { | |||||||
|       ListSettings.conf_function(conf, coll, guid, offline, socket); |       ListSettings.conf_function(conf, coll, guid, offline, socket); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     socket.on("shuffle", function(msg) { |     socket.on("shuffle", function (msg) { | ||||||
|       if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) { |       if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) { | ||||||
|         var _list = msg.channel.substring(0, msg.channel.indexOf("?")); |         var _list = msg.channel.substring(0, msg.channel.indexOf("?")); | ||||||
|         msg.channel = _list; |         msg.channel = _list; | ||||||
| @@ -716,7 +781,7 @@ module.exports = function() { | |||||||
|       ListChange.shuffle(msg, coll, guid, offline, socket); |       ListChange.shuffle(msg, coll, guid, offline, socket); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     socket.on("change_channel", function(obj) { |     socket.on("change_channel", function (obj) { | ||||||
|       if (obj == undefined && coll != undefined) { |       if (obj == undefined && coll != undefined) { | ||||||
|         obj = {}; |         obj = {}; | ||||||
|         obj.channel = coll; |         obj.channel = coll; | ||||||
| @@ -762,7 +827,7 @@ module.exports = function() { | |||||||
|       in_list = false; |       in_list = false; | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     socket.on("disconnect", function() { |     socket.on("disconnect", function () { | ||||||
|       Functions.left_channel( |       Functions.left_channel( | ||||||
|         coll, |         coll, | ||||||
|         guid, |         guid, | ||||||
| @@ -774,7 +839,7 @@ module.exports = function() { | |||||||
|       ); |       ); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     socket.on("disconnected", function() { |     socket.on("disconnected", function () { | ||||||
|       Functions.left_channel( |       Functions.left_channel( | ||||||
|         coll, |         coll, | ||||||
|         guid, |         guid, | ||||||
| @@ -786,7 +851,7 @@ module.exports = function() { | |||||||
|       ); |       ); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     socket.on("left_channel", function(msg) { |     socket.on("left_channel", function (msg) { | ||||||
|       if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) { |       if (msg.hasOwnProperty("channel") && msg.channel.indexOf("?") > -1) { | ||||||
|         var _list = msg.channel.substring(0, msg.channel.indexOf("?")); |         var _list = msg.channel.substring(0, msg.channel.indexOf("?")); | ||||||
|         msg.channel = _list; |         msg.channel = _list; | ||||||
| @@ -814,7 +879,7 @@ module.exports = function() { | |||||||
|       } |       } | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     socket.on("reconnect_failed", function() { |     socket.on("reconnect_failed", function () { | ||||||
|       Functions.left_channel( |       Functions.left_channel( | ||||||
|         coll, |         coll, | ||||||
|         guid, |         guid, | ||||||
| @@ -826,7 +891,7 @@ module.exports = function() { | |||||||
|       ); |       ); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     socket.on("connect_timeout", function() { |     socket.on("connect_timeout", function () { | ||||||
|       Functions.left_channel( |       Functions.left_channel( | ||||||
|         coll, |         coll, | ||||||
|         guid, |         guid, | ||||||
| @@ -838,7 +903,7 @@ module.exports = function() { | |||||||
|       ); |       ); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     socket.on("error", function() { |     socket.on("error", function () { | ||||||
|       Functions.left_channel( |       Functions.left_channel( | ||||||
|         coll, |         coll, | ||||||
|         guid, |         guid, | ||||||
| @@ -850,7 +915,7 @@ module.exports = function() { | |||||||
|       ); |       ); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     socket.on("pos", function(obj) { |     socket.on("pos", function (obj) { | ||||||
|       if ( |       if ( | ||||||
|         obj != undefined && |         obj != undefined && | ||||||
|         obj.hasOwnProperty("channel") && |         obj.hasOwnProperty("channel") && | ||||||
| @@ -893,11 +958,11 @@ module.exports = function() { | |||||||
|         return; |         return; | ||||||
|       } |       } | ||||||
|       if (coll == undefined) return; |       if (coll == undefined) return; | ||||||
|       db.collection(coll + "_settings").find(function(err, docs) { |       db.collection(coll + "_settings").find(function (err, docs) { | ||||||
|         Functions.getSessionAdminUser( |         Functions.getSessionAdminUser( | ||||||
|           Functions.getSession(socket), |           Functions.getSession(socket), | ||||||
|           coll, |           coll, | ||||||
|           function(userpass, adminpass) { |           function (userpass, adminpass) { | ||||||
|             if (userpass != "" || obj.pass == undefined) { |             if (userpass != "" || obj.pass == undefined) { | ||||||
|               obj.pass = userpass; |               obj.pass = userpass; | ||||||
|             } else { |             } else { | ||||||
| @@ -943,4 +1008,4 @@ setTimeout(send_ping, 25000); | |||||||
| }); | }); | ||||||
| }); | }); | ||||||
| }); | }); | ||||||
| }*/ | }*/ | ||||||
| @@ -4,15 +4,7 @@ var Functions = require(pathThumbnails + "/handlers/functions.js"); | |||||||
| var Frontpage = require(pathThumbnails + "/handlers/frontpage.js"); | var Frontpage = require(pathThumbnails + "/handlers/frontpage.js"); | ||||||
| var projects = require(pathThumbnails + "/handlers/aggregates.js"); | var projects = require(pathThumbnails + "/handlers/aggregates.js"); | ||||||
| var crypto = require("crypto"); | var crypto = require("crypto"); | ||||||
| var Filter = require("bad-words"); |  | ||||||
| var Search = require(pathThumbnails + "/handlers/search.js"); | var Search = require(pathThumbnails + "/handlers/search.js"); | ||||||
| var filter = new Filter({ placeHolder: "x" }); |  | ||||||
| /*var filter = { |  | ||||||
|     clean: function(str) { |  | ||||||
|         return str; |  | ||||||
|     } |  | ||||||
| }*/ |  | ||||||
| var request = require("request"); |  | ||||||
| var db = require(pathThumbnails + "/handlers/db.js"); | var db = require(pathThumbnails + "/handlers/db.js"); | ||||||
|  |  | ||||||
| function now_playing(list, fn, socket) { | function now_playing(list, fn, socket) { | ||||||
| @@ -20,7 +12,9 @@ function now_playing(list, fn, socket) { | |||||||
|     socket.emit("update_required"); |     socket.emit("update_required"); | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   db.collection(list).find({ now_playing: true }, function(err, docs) { |   db.collection(list).find({ | ||||||
|  |     now_playing: true | ||||||
|  |   }, function (err, docs) { | ||||||
|     if (docs.length === 0) { |     if (docs.length === 0) { | ||||||
|       fn("No song currently playing"); |       fn("No song currently playing"); | ||||||
|       return; |       return; | ||||||
| @@ -32,44 +26,44 @@ function now_playing(list, fn, socket) { | |||||||
| } | } | ||||||
|  |  | ||||||
| function join_silent(msg, socket) { | function join_silent(msg, socket) { | ||||||
|     if (typeof msg === "object" && msg !== undefined && msg !== null) { |   if (typeof msg === "object" && msg !== undefined && msg !== null) { | ||||||
|       var channelName = msg.channel; |     var channelName = msg.channel; | ||||||
|       var tryingPassword = false; |     var tryingPassword = false; | ||||||
|       var password = ""; |     var password = ""; | ||||||
|       if(msg.password != "") { |     if (msg.password != "") { | ||||||
|         tryingPassword = true; |       tryingPassword = true; | ||||||
|         password = Functions.decrypt_string(msg.password); |       password = Functions.decrypt_string(msg.password); | ||||||
|         password = crypto |       password = crypto | ||||||
|                  .createHash("sha256") |         .createHash("sha256") | ||||||
|                  .update(password) |         .update(password) | ||||||
|                  .digest("base64"); |         .digest("base64"); | ||||||
|       } |  | ||||||
|  |  | ||||||
|       channelName = channelName.toLowerCase(); //.replace(/ /g,''); |  | ||||||
|       channelName = Functions.removeEmojis(channelName).toLowerCase(); |  | ||||||
|       db.collection(channelName + "_settings").find(function(err, docs) { |  | ||||||
|         if(docs.length == 0) { |  | ||||||
|           socket.emit("join_silent_declined", ""); |  | ||||||
|           return; |  | ||||||
|         } |  | ||||||
|         if(docs[0].userpass == "" || docs[0].userpass == undefined || docs[0].userpass == password) { |  | ||||||
|           socket.join(channelName); |  | ||||||
|           socket.emit("join_silent_accepted", ""); |  | ||||||
|  |  | ||||||
|           send_play(channelName, socket); |  | ||||||
|         } else { |  | ||||||
|           socket.emit("join_silent_declined", ""); |  | ||||||
|         } |  | ||||||
|       }); |  | ||||||
|     } else { |  | ||||||
|         return; |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     channelName = channelName.toLowerCase(); //.replace(/ /g,''); | ||||||
|  |     channelName = Functions.removeEmojis(channelName).toLowerCase(); | ||||||
|  |     db.collection(channelName + "_settings").find(function (err, docs) { | ||||||
|  |       if (docs.length == 0) { | ||||||
|  |         socket.emit("join_silent_declined", ""); | ||||||
|  |         return; | ||||||
|  |       } | ||||||
|  |       if (docs[0].userpass == "" || docs[0].userpass == undefined || docs[0].userpass == password) { | ||||||
|  |         socket.join(channelName); | ||||||
|  |         socket.emit("join_silent_accepted", ""); | ||||||
|  |  | ||||||
|  |         send_play(channelName, socket); | ||||||
|  |       } else { | ||||||
|  |         socket.emit("join_silent_declined", ""); | ||||||
|  |       } | ||||||
|  |     }); | ||||||
|  |   } else { | ||||||
|  |     return; | ||||||
|  |   } | ||||||
| } | } | ||||||
|  |  | ||||||
| function list(msg, guid, coll, offline, socket) { | function list(msg, guid, coll, offline, socket) { | ||||||
|   var socketid = socket.zoff_id; |   var socketid = socket.zoff_id; | ||||||
|   if (typeof msg === "object" && msg !== undefined && msg !== null) { |   if (typeof msg === "object" && msg !== undefined && msg !== null) { | ||||||
|     Functions.getSessionAdminUser(Functions.getSession(socket), coll, function( |     Functions.getSessionAdminUser(Functions.getSession(socket), coll, function ( | ||||||
|       userpass, |       userpass, | ||||||
|       adminpass, |       adminpass, | ||||||
|       gotten |       gotten | ||||||
| @@ -111,12 +105,14 @@ function list(msg, guid, coll, offline, socket) { | |||||||
|       coll = Functions.removeEmojis(coll).toLowerCase(); |       coll = Functions.removeEmojis(coll).toLowerCase(); | ||||||
|       //coll = filter.clean(coll); |       //coll = filter.clean(coll); | ||||||
|       var pass = msg.pass; |       var pass = msg.pass; | ||||||
|       db.collection("frontpage_lists").find({ _id: coll }, function( |       db.collection("frontpage_lists").find({ | ||||||
|  |         _id: coll | ||||||
|  |       }, function ( | ||||||
|         err, |         err, | ||||||
|         frontpage_lists |         frontpage_lists | ||||||
|       ) { |       ) { | ||||||
|         if (frontpage_lists.length == 1) { |         if (frontpage_lists.length == 1) { | ||||||
|           db.collection(coll + "_settings").find(function(err, docs) { |           db.collection(coll + "_settings").find(function (err, docs) { | ||||||
|             if ( |             if ( | ||||||
|               docs.length == 0 || |               docs.length == 0 || | ||||||
|               (docs.length > 0 && |               (docs.length > 0 && | ||||||
| @@ -134,16 +130,18 @@ function list(msg, guid, coll, offline, socket) { | |||||||
|                   Functions.getSession(socket), |                   Functions.getSession(socket), | ||||||
|                   msg.pass, |                   msg.pass, | ||||||
|                   coll, |                   coll, | ||||||
|                   function() {} |                   function () {} | ||||||
|                 ); |                 ); | ||||||
|                 socket.emit("auth_accepted", { value: true }); |                 socket.emit("auth_accepted", { | ||||||
|  |                   value: true | ||||||
|  |                 }); | ||||||
|               } |               } | ||||||
|               if (docs.length > 0 && docs[0].userpass != pass) { |               if (docs.length > 0 && docs[0].userpass != pass) { | ||||||
|                 Functions.setSessionUserPass( |                 Functions.setSessionUserPass( | ||||||
|                   Functions.getSession(socket), |                   Functions.getSession(socket), | ||||||
|                   "", |                   "", | ||||||
|                   coll, |                   coll, | ||||||
|                   function() {} |                   function () {} | ||||||
|                 ); |                 ); | ||||||
|               } |               } | ||||||
|               if ( |               if ( | ||||||
| @@ -177,11 +175,13 @@ function list(msg, guid, coll, offline, socket) { | |||||||
|             } |             } | ||||||
|           }); |           }); | ||||||
|         } else { |         } else { | ||||||
|           db.createCollection(coll, function(err, docs) { |           db.createCollection(coll, function (err, docs) { | ||||||
|             db.collection(coll).createIndex( |             db.collection(coll).createIndex({ | ||||||
|               { id: 1 }, |                 id: 1 | ||||||
|               { unique: true }, |               }, { | ||||||
|               function(e, d) { |                 unique: true | ||||||
|  |               }, | ||||||
|  |               function (e, d) { | ||||||
|                 var configs = { |                 var configs = { | ||||||
|                   addsongs: false, |                   addsongs: false, | ||||||
|                   adminpass: "", |                   adminpass: "", | ||||||
| @@ -202,21 +202,20 @@ function list(msg, guid, coll, offline, socket) { | |||||||
|                   id: "config", |                   id: "config", | ||||||
|                   toggleChat: true |                   toggleChat: true | ||||||
|                 }; |                 }; | ||||||
|                 db.collection(coll + "_settings").insert(configs, function( |                 db.collection(coll + "_settings").insert(configs, function ( | ||||||
|                   err, |                   err, | ||||||
|                   docs |                   docs | ||||||
|                 ) { |                 ) { | ||||||
|                   socket.join(coll); |                   socket.join(coll); | ||||||
|                   send_list(coll, socket, true, false, true); |                   send_list(coll, socket, true, false, true); | ||||||
|                   db.collection("frontpage_lists").insert( |                   db.collection("frontpage_lists").insert({ | ||||||
|                     { |  | ||||||
|                       _id: coll, |                       _id: coll, | ||||||
|                       count: 0, |                       count: 0, | ||||||
|                       frontpage: true, |                       frontpage: true, | ||||||
|                       accessed: Functions.get_time(), |                       accessed: Functions.get_time(), | ||||||
|                       viewers: 1 |                       viewers: 1 | ||||||
|                     }, |                     }, | ||||||
|                     function(e, d) {} |                     function (e, d) {} | ||||||
|                   ); |                   ); | ||||||
|                   Functions.check_inlist( |                   Functions.check_inlist( | ||||||
|                     coll, |                     coll, | ||||||
| @@ -283,9 +282,8 @@ function skip(list, guid, coll, offline, socket, callback) { | |||||||
|         }, |         }, | ||||||
|         userpass: { |         userpass: { | ||||||
|           expected: "string", |           expected: "string", | ||||||
|           got: list.hasOwnProperty("userpass") |           got: list.hasOwnProperty("userpass") ? | ||||||
|             ? typeof list.userpass |             typeof list.userpass : undefined | ||||||
|             : undefined |  | ||||||
|         }, |         }, | ||||||
|         id: { |         id: { | ||||||
|           expected: "string", |           expected: "string", | ||||||
| @@ -296,7 +294,7 @@ function skip(list, guid, coll, offline, socket, callback) { | |||||||
|       return; |       return; | ||||||
|     } |     } | ||||||
|     list.id = list.id + ""; |     list.id = list.id + ""; | ||||||
|     Functions.getSessionAdminUser(Functions.getSession(socket), coll, function( |     Functions.getSessionAdminUser(Functions.getSession(socket), coll, function ( | ||||||
|       userpass, |       userpass, | ||||||
|       adminpass |       adminpass | ||||||
|     ) { |     ) { | ||||||
| @@ -318,7 +316,7 @@ function skip(list, guid, coll, offline, socket, callback) { | |||||||
|           .digest("base64"); |           .digest("base64"); | ||||||
|       } |       } | ||||||
|  |  | ||||||
|       db.collection(coll + "_settings").find(function(_err, docs) { |       db.collection(coll + "_settings").find(function (_err, docs) { | ||||||
|         if ( |         if ( | ||||||
|           docs.length > 0 && |           docs.length > 0 && | ||||||
|           (docs[0].userpass == undefined || |           (docs[0].userpass == undefined || | ||||||
| @@ -343,14 +341,14 @@ function skip(list, guid, coll, offline, socket, callback) { | |||||||
|             video_id, |             video_id, | ||||||
|             coll, |             coll, | ||||||
|             err == "5" || |             err == "5" || | ||||||
|               err == "100" || |             err == "100" || | ||||||
|               err == "101" || |             err == "101" || | ||||||
|               err == "150" || |             err == "150" || | ||||||
|               err == 5 || |             err == 5 || | ||||||
|               err == 100 || |             err == 100 || | ||||||
|               err == 101 || |             err == 101 || | ||||||
|               err == 150, |             err == 150, | ||||||
|             function(trueError) { |             function (trueError) { | ||||||
|               var error = false; |               var error = false; | ||||||
|               if (!trueError) { |               if (!trueError) { | ||||||
|                 adminpass = list.pass; |                 adminpass = list.pass; | ||||||
| @@ -370,21 +368,23 @@ function skip(list, guid, coll, offline, socket, callback) { | |||||||
|                   (docs[0].adminpass == hash && docs[0].adminpass !== "") || |                   (docs[0].adminpass == hash && docs[0].adminpass !== "") || | ||||||
|                   error |                   error | ||||||
|                 ) { |                 ) { | ||||||
|                   db.collection("frontpage_lists").find({ _id: coll }, function( |                   db.collection("frontpage_lists").find({ | ||||||
|  |                     _id: coll | ||||||
|  |                   }, function ( | ||||||
|                     err, |                     err, | ||||||
|                     frontpage_viewers |                     frontpage_viewers | ||||||
|                   ) { |                   ) { | ||||||
|                     if ( |                     if ( | ||||||
|                       error || |                       error || | ||||||
|                       ((strictSkip && |                       ((strictSkip && | ||||||
|                         ((docs[0].adminpass == hash && |                           ((docs[0].adminpass == hash && | ||||||
|                           docs[0].adminpass !== "") || |                               docs[0].adminpass !== "") || | ||||||
|                           docs[0].skips.length + 1 >= strictSkipNumber)) || |                             docs[0].skips.length + 1 >= strictSkipNumber)) || | ||||||
|                         (!strictSkip && |                         (!strictSkip && | ||||||
|                           ((frontpage_viewers[0].viewers / 2 <= |                           ((frontpage_viewers[0].viewers / 2 <= | ||||||
|                             docs[0].skips.length + 1 && |                               docs[0].skips.length + 1 && | ||||||
|                             !Functions.contains(docs[0].skips, guid) && |                               !Functions.contains(docs[0].skips, guid) && | ||||||
|                             frontpage_viewers[0].viewers != 2) || |                               frontpage_viewers[0].viewers != 2) || | ||||||
|                             (frontpage_viewers[0].viewers == 2 && |                             (frontpage_viewers[0].viewers == 2 && | ||||||
|                               docs[0].skips.length + 1 == 2 && |                               docs[0].skips.length + 1 == 2 && | ||||||
|                               !Functions.contains(docs[0].skips, guid)) || |                               !Functions.contains(docs[0].skips, guid)) || | ||||||
| @@ -400,16 +400,18 @@ function skip(list, guid, coll, offline, socket, callback) { | |||||||
|                         error, |                         error, | ||||||
|                         true, |                         true, | ||||||
|                         socket, |                         socket, | ||||||
|                         function() { |                         function () { | ||||||
|                           change_song(coll, error, video_id, docs); |                           change_song(coll, error, video_id, docs); | ||||||
|                           socket.emit("toast", "skip"); |                           socket.emit("toast", "skip"); | ||||||
|                           db.collection("user_names").find( |                           db.collection("user_names").find({ | ||||||
|                             { guid: guid }, |                               guid: guid | ||||||
|                             function(err, docs) { |                             }, | ||||||
|  |                             function (err, docs) { | ||||||
|                               if (docs.length == 1) { |                               if (docs.length == 1) { | ||||||
|                                 db.collection("registered_users").find( |                                 db.collection("registered_users").find({ | ||||||
|                                   { _id: docs[0].name }, |                                     _id: docs[0].name | ||||||
|                                   function(err, n) { |                                   }, | ||||||
|  |                                   function (err, n) { | ||||||
|                                     var icon = false; |                                     var icon = false; | ||||||
|                                     if (n.length > 0 && n[0].icon) { |                                     if (n.length > 0 && n[0].icon) { | ||||||
|                                       icon = n[0].icon; |                                       icon = n[0].icon; | ||||||
| @@ -428,10 +430,14 @@ function skip(list, guid, coll, offline, socket, callback) { | |||||||
|                         "The channel is skipping too often, please wait " |                         "The channel is skipping too often, please wait " | ||||||
|                       ); |                       ); | ||||||
|                     } else if (!Functions.contains(docs[0].skips, guid)) { |                     } else if (!Functions.contains(docs[0].skips, guid)) { | ||||||
|                       db.collection(coll + "_settings").update( |                       db.collection(coll + "_settings").update({ | ||||||
|                         { id: "config" }, |                           id: "config" | ||||||
|                         { $push: { skips: guid } }, |                         }, { | ||||||
|                         function(err, d) { |                           $push: { | ||||||
|  |                             skips: guid | ||||||
|  |                           } | ||||||
|  |                         }, | ||||||
|  |                         function (err, d) { | ||||||
|                           if ( |                           if ( | ||||||
|                             frontpage_viewers[0].viewers == 2 && |                             frontpage_viewers[0].viewers == 2 && | ||||||
|                             !strictSkip |                             !strictSkip | ||||||
| @@ -450,13 +456,15 @@ function skip(list, guid, coll, offline, socket, callback) { | |||||||
|                             "toast", |                             "toast", | ||||||
|                             to_skip + " more are needed to skip!" |                             to_skip + " more are needed to skip!" | ||||||
|                           ); |                           ); | ||||||
|                           db.collection("user_names").find( |                           db.collection("user_names").find({ | ||||||
|                             { guid: guid }, |                               guid: guid | ||||||
|                             function(err, docs) { |                             }, | ||||||
|  |                             function (err, docs) { | ||||||
|                               if (docs.length == 1) { |                               if (docs.length == 1) { | ||||||
|                                 db.collection("registered_users").find( |                                 db.collection("registered_users").find({ | ||||||
|                                   { _id: docs[0].name }, |                                     _id: docs[0].name | ||||||
|                                   function(err, n) { |                                   }, | ||||||
|  |                                   function (err, n) { | ||||||
|                                     var icon = false; |                                     var icon = false; | ||||||
|                                     if (n.length > 0 && n[0].icon) { |                                     if (n.length > 0 && n[0].icon) { | ||||||
|                                       icon = n[0].icon; |                                       icon = n[0].icon; | ||||||
| @@ -503,8 +511,7 @@ function change_song(coll, error, id, conf, callback, socket) { | |||||||
|   var startTime = conf[0].startTime; |   var startTime = conf[0].startTime; | ||||||
|   if (conf !== null && conf.length !== 0) { |   if (conf !== null && conf.length !== 0) { | ||||||
|     db.collection(coll).aggregate( |     db.collection(coll).aggregate( | ||||||
|       [ |       [{ | ||||||
|         { |  | ||||||
|           $match: { |           $match: { | ||||||
|             views: { |             views: { | ||||||
|               $exists: false |               $exists: false | ||||||
| @@ -526,7 +533,7 @@ function change_song(coll, error, id, conf, callback, socket) { | |||||||
|           $limit: 2 |           $limit: 2 | ||||||
|         } |         } | ||||||
|       ], |       ], | ||||||
|       function(err, now_playing_doc) { |       function (err, now_playing_doc) { | ||||||
|         if (now_playing_doc.length == 0) { |         if (now_playing_doc.length == 0) { | ||||||
|           console.log("empty list", coll, callback, id, conf); |           console.log("empty list", coll, callback, id, conf); | ||||||
|         } |         } | ||||||
| @@ -535,7 +542,10 @@ function change_song(coll, error, id, conf, callback, socket) { | |||||||
|           ((id && id == now_playing_doc[0].id) || !id) |           ((id && id == now_playing_doc[0].id) || !id) | ||||||
|         ) { |         ) { | ||||||
|           if (error) { |           if (error) { | ||||||
|             db.collection(coll).remove({ now_playing: true, id: id }, function( |             db.collection(coll).remove({ | ||||||
|  |               now_playing: true, | ||||||
|  |               id: id | ||||||
|  |             }, function ( | ||||||
|               err, |               err, | ||||||
|               docs |               docs | ||||||
|             ) { |             ) { | ||||||
| @@ -551,19 +561,30 @@ function change_song(coll, error, id, conf, callback, socket) { | |||||||
|                 }); |                 }); | ||||||
|               } |               } | ||||||
|               if (docs.deletedCount == 1) { |               if (docs.deletedCount == 1) { | ||||||
|                 db.collection("frontpage_lists").update( |                 db.collection("frontpage_lists").update({ | ||||||
|                   { _id: coll, count: { $gt: 0 } }, |                     _id: coll, | ||||||
|                   { |                     count: { | ||||||
|                     $inc: { count: -1 }, |                       $gt: 0 | ||||||
|                     $set: { accessed: Functions.get_time() } |                     } | ||||||
|  |                   }, { | ||||||
|  |                     $inc: { | ||||||
|  |                       count: -1 | ||||||
|  |                     }, | ||||||
|  |                     $set: { | ||||||
|  |                       accessed: Functions.get_time() | ||||||
|  |                     } | ||||||
|  |                   }, { | ||||||
|  |                     upsert: true | ||||||
|                   }, |                   }, | ||||||
|                   { upsert: true }, |                   function (err, docs) {} | ||||||
|                   function(err, docs) {} |  | ||||||
|                 ); |                 ); | ||||||
|               } |               } | ||||||
|             }); |             }); | ||||||
|           } else if (conf[0].removeplay === true) { |           } else if (conf[0].removeplay === true) { | ||||||
|             db.collection(coll).remove({ now_playing: true, id: id }, function( |             db.collection(coll).remove({ | ||||||
|  |               now_playing: true, | ||||||
|  |               id: id | ||||||
|  |             }, function ( | ||||||
|               err, |               err, | ||||||
|               docs |               docs | ||||||
|             ) { |             ) { | ||||||
| @@ -579,14 +600,22 @@ function change_song(coll, error, id, conf, callback, socket) { | |||||||
|                 }); |                 }); | ||||||
|               } |               } | ||||||
|               if (docs.deletedCount == 1) { |               if (docs.deletedCount == 1) { | ||||||
|                 db.collection("frontpage_lists").update( |                 db.collection("frontpage_lists").update({ | ||||||
|                   { _id: coll, count: { $gt: 0 } }, |                     _id: coll, | ||||||
|                   { |                     count: { | ||||||
|                     $inc: { count: -1 }, |                       $gt: 0 | ||||||
|                     $set: { accessed: Functions.get_time() } |                     } | ||||||
|  |                   }, { | ||||||
|  |                     $inc: { | ||||||
|  |                       count: -1 | ||||||
|  |                     }, | ||||||
|  |                     $set: { | ||||||
|  |                       accessed: Functions.get_time() | ||||||
|  |                     } | ||||||
|  |                   }, { | ||||||
|  |                     upsert: true | ||||||
|                   }, |                   }, | ||||||
|                   { upsert: true }, |                   function (err, docs) {} | ||||||
|                   function(err, docs) {} |  | ||||||
|                 ); |                 ); | ||||||
|               } |               } | ||||||
|             }); |             }); | ||||||
| @@ -596,17 +625,19 @@ function change_song(coll, error, id, conf, callback, socket) { | |||||||
|                 conf[0].skipped_time != Functions.get_time()) || |                 conf[0].skipped_time != Functions.get_time()) || | ||||||
|               conf[0].skipped_time == undefined |               conf[0].skipped_time == undefined | ||||||
|             ) { |             ) { | ||||||
|               db.collection(coll).update( |               db.collection(coll).update({ | ||||||
|                 { now_playing: true, id: id }, |                   now_playing: true, | ||||||
|                 { |                   id: id | ||||||
|  |                 }, { | ||||||
|                   $set: { |                   $set: { | ||||||
|                     now_playing: false, |                     now_playing: false, | ||||||
|                     votes: 0, |                     votes: 0, | ||||||
|                     guids: [] |                     guids: [] | ||||||
|                   } |                   } | ||||||
|  |                 }, { | ||||||
|  |                   multi: true | ||||||
|                 }, |                 }, | ||||||
|                 { multi: true }, |                 function (err, docs) { | ||||||
|                 function(err, docs) { |  | ||||||
|                   var next_song; |                   var next_song; | ||||||
|                   if (now_playing_doc.length == 2) |                   if (now_playing_doc.length == 2) | ||||||
|                     next_song = now_playing_doc[1].id; |                     next_song = now_playing_doc[1].id; | ||||||
| @@ -629,10 +660,14 @@ function change_song(coll, error, id, conf, callback, socket) { | |||||||
|             now_playing_doc.length > 1 && |             now_playing_doc.length > 1 && | ||||||
|             now_playing_doc[1].id == id |             now_playing_doc[1].id == id | ||||||
|           ) { |           ) { | ||||||
|             db.collection(coll).update( |             db.collection(coll).update({ | ||||||
|               { id: now_playing_doc[0].id }, |                 id: now_playing_doc[0].id | ||||||
|               { $set: { now_playing: false } }, |               }, { | ||||||
|               function(e, d) { |                 $set: { | ||||||
|  |                   now_playing: false | ||||||
|  |                 } | ||||||
|  |               }, | ||||||
|  |               function (e, d) { | ||||||
|                 change_song(coll, error, id, conf, callback, socket, error); |                 change_song(coll, error, id, conf, callback, socket, error); | ||||||
|               } |               } | ||||||
|             ); |             ); | ||||||
| @@ -649,8 +684,7 @@ function change_song(coll, error, id, conf, callback, socket) { | |||||||
| function change_song_post(coll, next_song, conf, callback, socket, removed) { | function change_song_post(coll, next_song, conf, callback, socket, removed) { | ||||||
|   //coll = coll.replace(/ /g,''); |   //coll = coll.replace(/ /g,''); | ||||||
|   db.collection(coll).aggregate( |   db.collection(coll).aggregate( | ||||||
|     [ |     [{ | ||||||
|       { |  | ||||||
|         $match: { |         $match: { | ||||||
|           now_playing: false, |           now_playing: false, | ||||||
|           type: { |           type: { | ||||||
| @@ -669,7 +703,7 @@ function change_song_post(coll, next_song, conf, callback, socket, removed) { | |||||||
|         $limit: 2 |         $limit: 2 | ||||||
|       } |       } | ||||||
|     ], |     ], | ||||||
|     function(err, docs) { |     function (err, docs) { | ||||||
|       if (docs !== null && docs.length > 0) { |       if (docs !== null && docs.length > 0) { | ||||||
|         var id = docs[0].id; |         var id = docs[0].id; | ||||||
|         if (next_song && next_song != id) { |         if (next_song && next_song != id) { | ||||||
| @@ -679,9 +713,10 @@ function change_song_post(coll, next_song, conf, callback, socket, removed) { | |||||||
|             return; |             return; | ||||||
|           } |           } | ||||||
|         } |         } | ||||||
|         db.collection(coll).update( |         db.collection(coll).update({ | ||||||
|           { id: id, now_playing: false }, |             id: id, | ||||||
|           { |             now_playing: false | ||||||
|  |           }, { | ||||||
|             $set: { |             $set: { | ||||||
|               now_playing: true, |               now_playing: true, | ||||||
|               votes: 0, |               votes: 0, | ||||||
| @@ -689,7 +724,7 @@ function change_song_post(coll, next_song, conf, callback, socket, removed) { | |||||||
|               added: Functions.get_time() |               added: Functions.get_time() | ||||||
|             } |             } | ||||||
|           }, |           }, | ||||||
|           function(err, returnDocs) { |           function (err, returnDocs) { | ||||||
|             if ( |             if ( | ||||||
|               (returnDocs.hasOwnProperty("nModified") && |               (returnDocs.hasOwnProperty("nModified") && | ||||||
|                 returnDocs.nModified == 0) || |                 returnDocs.nModified == 0) || | ||||||
| @@ -699,15 +734,15 @@ function change_song_post(coll, next_song, conf, callback, socket, removed) { | |||||||
|               callback(); |               callback(); | ||||||
|               return; |               return; | ||||||
|             } |             } | ||||||
|             db.collection(coll + "_settings").update( |             db.collection(coll + "_settings").update({ | ||||||
|               { id: "config" }, |                 id: "config" | ||||||
|               { |               }, { | ||||||
|                 $set: { |                 $set: { | ||||||
|                   startTime: Functions.get_time(), |                   startTime: Functions.get_time(), | ||||||
|                   skips: [] |                   skips: [] | ||||||
|                 } |                 } | ||||||
|               }, |               }, | ||||||
|               function(err, returnDocs) { |               function (err, returnDocs) { | ||||||
|                 //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", { |                   io.to(coll).emit("channel", { | ||||||
| @@ -756,8 +791,7 @@ function change_song_post(coll, next_song, conf, callback, socket, removed) { | |||||||
| function send_list(coll, socket, send, list_send, configs, shuffled) { | function send_list(coll, socket, send, list_send, configs, shuffled) { | ||||||
|   //coll = coll.replace(/ /g,''); |   //coll = coll.replace(/ /g,''); | ||||||
|   db.collection(coll + "_settings").aggregate( |   db.collection(coll + "_settings").aggregate( | ||||||
|     [ |     [{ | ||||||
|       { |  | ||||||
|         $match: { |         $match: { | ||||||
|           id: "config" |           id: "config" | ||||||
|         } |         } | ||||||
| @@ -766,7 +800,7 @@ function send_list(coll, socket, send, list_send, configs, shuffled) { | |||||||
|         $project: projects.toShowConfig |         $project: projects.toShowConfig | ||||||
|       } |       } | ||||||
|     ], |     ], | ||||||
|     function(err, _conf) { |     function (err, _conf) { | ||||||
|       var conf = _conf; |       var conf = _conf; | ||||||
|       if (conf.length == 0) { |       if (conf.length == 0) { | ||||||
|         var conf = { |         var conf = { | ||||||
| @@ -789,38 +823,50 @@ function send_list(coll, socket, send, list_send, configs, shuffled) { | |||||||
|           toggleChat: true, |           toggleChat: true, | ||||||
|           userpass: "" |           userpass: "" | ||||||
|         }; |         }; | ||||||
|         db.collection(coll + "_settings").update( |         db.collection(coll + "_settings").update({ | ||||||
|           { id: "config" }, |             id: "config" | ||||||
|           conf, |           }, | ||||||
|           { upsert: true }, |           conf, { | ||||||
|           function(err, docs) { |             upsert: true | ||||||
|  |           }, | ||||||
|  |           function (err, docs) { | ||||||
|             send_list(coll, socket, send, list_send, configs, shuffled); |             send_list(coll, socket, send, list_send, configs, shuffled); | ||||||
|           } |           } | ||||||
|         ); |         ); | ||||||
|       } else { |       } else { | ||||||
|         db.collection(coll).aggregate( |         db.collection(coll).aggregate( | ||||||
|           [ |           [{ | ||||||
|             { |               $match: { | ||||||
|               $match: { type: { $ne: "suggested" } } |                 type: { | ||||||
|  |                   $ne: "suggested" | ||||||
|  |                 } | ||||||
|  |               } | ||||||
|             }, |             }, | ||||||
|             { |             { | ||||||
|               $project: projects.project_object |               $project: projects.project_object | ||||||
|             }, |             }, | ||||||
|             { $sort: { now_playing: -1, votes: -1, added: 1 } } |             { | ||||||
|  |               $sort: { | ||||||
|  |                 now_playing: -1, | ||||||
|  |                 votes: -1, | ||||||
|  |                 added: 1 | ||||||
|  |               } | ||||||
|  |             } | ||||||
|           ], |           ], | ||||||
|           function( |           function ( | ||||||
|             err, |             err, | ||||||
|             docs //db.collection(coll).find({type: {$ne: "suggested"}}, function(err, docs) |             docs //db.collection(coll).find({type: {$ne: "suggested"}}, function(err, docs) | ||||||
|           ) { |           ) { | ||||||
|             if (docs.length > 0) { |             if (docs.length > 0) { | ||||||
|               db.collection(coll).find({ now_playing: true }, function( |               db.collection(coll).find({ | ||||||
|  |                 now_playing: true | ||||||
|  |               }, function ( | ||||||
|                 err, |                 err, | ||||||
|                 np_docs |                 np_docs | ||||||
|               ) { |               ) { | ||||||
|                 if (np_docs.length == 0) { |                 if (np_docs.length == 0) { | ||||||
|                   db.collection(coll).aggregate( |                   db.collection(coll).aggregate( | ||||||
|                     [ |                     [{ | ||||||
|                       { |  | ||||||
|                         $match: { |                         $match: { | ||||||
|                           views: { |                           views: { | ||||||
|                             $exists: false |                             $exists: false | ||||||
| @@ -842,11 +888,12 @@ function send_list(coll, socket, send, list_send, configs, shuffled) { | |||||||
|                         $limit: 1 |                         $limit: 1 | ||||||
|                       } |                       } | ||||||
|                     ], |                     ], | ||||||
|                     function(err, now_playing_doc) { |                     function (err, now_playing_doc) { | ||||||
|                       if (now_playing_doc[0].now_playing == false) { |                       if (now_playing_doc[0].now_playing == false) { | ||||||
|                         db.collection(coll).update( |                         db.collection(coll).update({ | ||||||
|                           { id: now_playing_doc[0].id, now_playing: false }, |                             id: now_playing_doc[0].id, | ||||||
|                           { |                             now_playing: false | ||||||
|  |                           }, { | ||||||
|                             $set: { |                             $set: { | ||||||
|                               now_playing: true, |                               now_playing: true, | ||||||
|                               votes: 0, |                               votes: 0, | ||||||
| @@ -854,16 +901,16 @@ function send_list(coll, socket, send, list_send, configs, shuffled) { | |||||||
|                               added: Functions.get_time() |                               added: Functions.get_time() | ||||||
|                             } |                             } | ||||||
|                           }, |                           }, | ||||||
|                           function(err, returnDocs) { |                           function (err, returnDocs) { | ||||||
|                             db.collection(coll + "_settings").update( |                             db.collection(coll + "_settings").update({ | ||||||
|                               { id: "config" }, |                                 id: "config" | ||||||
|                               { |                               }, { | ||||||
|                                 $set: { |                                 $set: { | ||||||
|                                   startTime: Functions.get_time(), |                                   startTime: Functions.get_time(), | ||||||
|                                   skips: [] |                                   skips: [] | ||||||
|                                 } |                                 } | ||||||
|                               }, |                               }, | ||||||
|                               function(err, returnDocs) { |                               function (err, returnDocs) { | ||||||
|                                 Frontpage.update_frontpage( |                                 Frontpage.update_frontpage( | ||||||
|                                   coll, |                                   coll, | ||||||
|                                   now_playing_doc[0].id, |                                   now_playing_doc[0].id, | ||||||
| @@ -888,8 +935,7 @@ function send_list(coll, socket, send, list_send, configs, shuffled) { | |||||||
|                   ); |                   ); | ||||||
|                 } else if (np_docs.length > 1) { |                 } else if (np_docs.length > 1) { | ||||||
|                   db.collection(coll).aggregate( |                   db.collection(coll).aggregate( | ||||||
|                     [ |                     [{ | ||||||
|                       { |  | ||||||
|                         $match: { |                         $match: { | ||||||
|                           now_playing: true |                           now_playing: true | ||||||
|                         } |                         } | ||||||
| @@ -903,13 +949,21 @@ function send_list(coll, socket, send, list_send, configs, shuffled) { | |||||||
|                         } |                         } | ||||||
|                       } |                       } | ||||||
|                     ], |                     ], | ||||||
|                     function(e, docs) { |                     function (e, docs) { | ||||||
|                       var real_now_playing = docs[docs.length - 1]; |                       var real_now_playing = docs[docs.length - 1]; | ||||||
|                       db.collection(coll).update( |                       db.collection(coll).update({ | ||||||
|                         { now_playing: true, id: { $ne: real_now_playing.id } }, |                           now_playing: true, | ||||||
|                         { $set: { now_playing: false } }, |                           id: { | ||||||
|                         { multi: true }, |                             $ne: real_now_playing.id | ||||||
|                         function(e, d) { |                           } | ||||||
|  |                         }, { | ||||||
|  |                           $set: { | ||||||
|  |                             now_playing: false | ||||||
|  |                           } | ||||||
|  |                         }, { | ||||||
|  |                           multi: true | ||||||
|  |                         }, | ||||||
|  |                         function (e, d) { | ||||||
|                           send_list( |                           send_list( | ||||||
|                             coll, |                             coll, | ||||||
|                             socket, |                             socket, | ||||||
| @@ -932,7 +986,7 @@ function send_list(coll, socket, send, list_send, configs, shuffled) { | |||||||
|                       false, |                       false, | ||||||
|                       np_docs[0].id, |                       np_docs[0].id, | ||||||
|                       conf, |                       conf, | ||||||
|                       function() { |                       function () { | ||||||
|                         send_list( |                         send_list( | ||||||
|                           coll, |                           coll, | ||||||
|                           socket, |                           socket, | ||||||
| @@ -1013,11 +1067,13 @@ function send_list(coll, socket, send, list_send, configs, shuffled) { | |||||||
|               desc: "", |               desc: "", | ||||||
|               userpass: "" |               userpass: "" | ||||||
|             }; |             }; | ||||||
|             db.collection(coll + "_settings").update( |             db.collection(coll + "_settings").update({ | ||||||
|               { id: "config" }, |                 id: "config" | ||||||
|               conf, |               }, | ||||||
|               { upsert: true }, |               conf, { | ||||||
|               function(err, docs) { |                 upsert: true | ||||||
|  |               }, | ||||||
|  |               function (err, docs) { | ||||||
|                 io.to(coll).emit("conf", conf); |                 io.to(coll).emit("conf", conf); | ||||||
|               } |               } | ||||||
|             ); |             ); | ||||||
| @@ -1028,8 +1084,12 @@ function send_list(coll, socket, send, list_send, configs, shuffled) { | |||||||
|   ); |   ); | ||||||
|   if (socket) { |   if (socket) { | ||||||
|     db.collection(coll) |     db.collection(coll) | ||||||
|       .find({ type: "suggested" }) |       .find({ | ||||||
|       .sort({ added: 1 }, function(err, sugg) { |         type: "suggested" | ||||||
|  |       }) | ||||||
|  |       .sort({ | ||||||
|  |         added: 1 | ||||||
|  |       }, function (err, sugg) { | ||||||
|         socket.emit("suggested", sugg); |         socket.emit("suggested", sugg); | ||||||
|       }); |       }); | ||||||
|   } |   } | ||||||
| @@ -1068,14 +1128,14 @@ function end(obj, coll, guid, offline, socket) { | |||||||
|     } |     } | ||||||
|     obj.id = obj.id + ""; |     obj.id = obj.id + ""; | ||||||
|     id = id + ""; |     id = id + ""; | ||||||
|     var callback_function = function() { |     var callback_function = function () { | ||||||
|       for (var i = 0; i < arguments.length; i++) { |       for (var i = 0; i < arguments.length; i++) { | ||||||
|         if (typeof arguments[i] == "function") { |         if (typeof arguments[i] == "function") { | ||||||
|           arguments[i](); |           arguments[i](); | ||||||
|         } |         } | ||||||
|       } |       } | ||||||
|     }; |     }; | ||||||
|     db.collection(coll + "_settings").find(function(err, docs) { |     db.collection(coll + "_settings").find(function (err, docs) { | ||||||
|       var authentication_needed = false; |       var authentication_needed = false; | ||||||
|       if ( |       if ( | ||||||
|         docs.length > 0 && |         docs.length > 0 && | ||||||
| @@ -1084,7 +1144,7 @@ function end(obj, coll, guid, offline, socket) { | |||||||
|         callback_function = Functions.getSessionAdminUser; |         callback_function = Functions.getSessionAdminUser; | ||||||
|         authentication_needed = true; |         authentication_needed = true; | ||||||
|       } |       } | ||||||
|       callback_function(Functions.getSession(socket), coll, function(userpass) { |       callback_function(Functions.getSession(socket), coll, function (userpass) { | ||||||
|         if (userpass != "" || obj.pass == undefined) { |         if (userpass != "" || obj.pass == undefined) { | ||||||
|           obj.pass = userpass; |           obj.pass = userpass; | ||||||
|         } else { |         } else { | ||||||
| @@ -1107,7 +1167,9 @@ function end(obj, coll, guid, offline, socket) { | |||||||
|             undefined, |             undefined, | ||||||
|             "place 13" |             "place 13" | ||||||
|           ); |           ); | ||||||
|           db.collection(coll).find({ now_playing: true }, function(err, np) { |           db.collection(coll).find({ | ||||||
|  |             now_playing: true | ||||||
|  |           }, function (err, np) { | ||||||
|             if (err !== null) console.log(err); |             if (err !== null) console.log(err); | ||||||
|             if ( |             if ( | ||||||
|               np !== null && |               np !== null && | ||||||
| @@ -1142,8 +1204,10 @@ function end(obj, coll, guid, offline, socket) { | |||||||
|  |  | ||||||
| function send_play(coll, socket, broadcast) { | function send_play(coll, socket, broadcast) { | ||||||
|   //coll = coll.replace(/ /g,''); |   //coll = coll.replace(/ /g,''); | ||||||
|   db.collection(coll).find({ now_playing: true }, function(err, np) { |   db.collection(coll).find({ | ||||||
|     db.collection(coll + "_settings").find(function(err, conf) { |     now_playing: true | ||||||
|  |   }, function (err, np) { | ||||||
|  |     db.collection(coll + "_settings").find(function (err, conf) { | ||||||
|       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) { | ||||||
| @@ -1155,7 +1219,11 @@ function send_play(coll, socket, broadcast) { | |||||||
|           else conf[0].userpass = false; |           else conf[0].userpass = false; | ||||||
|           if (!np.hasOwnProperty("start")) np.start = 0; |           if (!np.hasOwnProperty("start")) np.start = 0; | ||||||
|           if (!np.hasOwnProperty("end")) np.end = np.duration; |           if (!np.hasOwnProperty("end")) np.end = np.duration; | ||||||
|           toSend = { np: np, conf: conf, time: Functions.get_time() }; |           toSend = { | ||||||
|  |             np: np, | ||||||
|  |             conf: conf, | ||||||
|  |             time: Functions.get_time() | ||||||
|  |           }; | ||||||
|           if (socket === undefined) { |           if (socket === undefined) { | ||||||
|             io.to(coll).emit("np", toSend); |             io.to(coll).emit("np", toSend); | ||||||
|             // |             // | ||||||
| @@ -1200,25 +1268,35 @@ function sendColor(coll, socket, url, ajax, res) { | |||||||
|   //var url = 'https://img.youtube.com/vi/'+id+'/mqdefault.jpg'; |   //var url = 'https://img.youtube.com/vi/'+id+'/mqdefault.jpg'; | ||||||
|  |  | ||||||
|   Jimp.read(url) |   Jimp.read(url) | ||||||
|     .then(function(image) { |     .then(function (image) { | ||||||
|       var c = ColorThief.getColor(image); |       var c = ColorThief.getColor(image); | ||||||
|       if (ajax) { |       if (ajax) { | ||||||
|         res.header({ "Content-Type": "application/json" }); |         res.header({ | ||||||
|  |           "Content-Type": "application/json" | ||||||
|  |         }); | ||||||
|         res.status(200).send(c); |         res.status(200).send(c); | ||||||
|         return; |         return; | ||||||
|       } else { |       } else { | ||||||
|         if (socket) { |         if (socket) { | ||||||
|           socket.emit("color", { color: c, only: true }); |           socket.emit("color", { | ||||||
|  |             color: c, | ||||||
|  |             only: true | ||||||
|  |           }); | ||||||
|         } else { |         } else { | ||||||
|           io.to(coll).emit("color", { color: c, only: false }); |           io.to(coll).emit("color", { | ||||||
|  |             color: c, | ||||||
|  |             only: false | ||||||
|  |           }); | ||||||
|         } |         } | ||||||
|       } |       } | ||||||
|     }) |     }) | ||||||
|     .catch(function(err) { |     .catch(function (err) { | ||||||
|       console.log("Crashed on fetching image, url is " + url); |       console.log("Crashed on fetching image, url is " + url); | ||||||
|       console.log("Is ajax: " + ajax); |       console.log("Is ajax: " + ajax); | ||||||
|       if (ajax) { |       if (ajax) { | ||||||
|         res.header({ "Content-Type": "application/json" }); |         res.header({ | ||||||
|  |           "Content-Type": "application/json" | ||||||
|  |         }); | ||||||
|         res.status(404); |         res.status(404); | ||||||
|         return; |         return; | ||||||
|       } |       } | ||||||
| @@ -1228,8 +1306,7 @@ function sendColor(coll, socket, url, ajax, res) { | |||||||
| function getNextSong(coll, socket, callback) { | function getNextSong(coll, socket, callback) { | ||||||
|   //coll = coll.replace(/ /g,''); |   //coll = coll.replace(/ /g,''); | ||||||
|   db.collection(coll).aggregate( |   db.collection(coll).aggregate( | ||||||
|     [ |     [{ | ||||||
|       { |  | ||||||
|         $match: { |         $match: { | ||||||
|           views: { |           views: { | ||||||
|             $exists: false |             $exists: false | ||||||
| @@ -1251,7 +1328,7 @@ function getNextSong(coll, socket, callback) { | |||||||
|         $limit: 1 |         $limit: 1 | ||||||
|       } |       } | ||||||
|     ], |     ], | ||||||
|     function(err, doc) { |     function (err, doc) { | ||||||
|       if (doc.length == 1) { |       if (doc.length == 1) { | ||||||
|         var thumbnail = ""; |         var thumbnail = ""; | ||||||
|         var source = "youtube"; |         var source = "youtube"; | ||||||
| @@ -1290,4 +1367,4 @@ module.exports.change_song_post = change_song_post; | |||||||
| module.exports.send_list = send_list; | module.exports.send_list = send_list; | ||||||
| module.exports.end = end; | module.exports.end = end; | ||||||
| module.exports.send_play = send_play; | module.exports.send_play = send_play; | ||||||
| module.exports.getNextSong = getNextSong; | module.exports.getNextSong = getNextSong; | ||||||
| @@ -4,13 +4,6 @@ var Frontpage = require(pathThumbnails + "/handlers/frontpage.js"); | |||||||
| var Search = require(pathThumbnails + "/handlers/search.js"); | var Search = require(pathThumbnails + "/handlers/search.js"); | ||||||
| var Chat = require(pathThumbnails + "/handlers/chat.js"); | var Chat = require(pathThumbnails + "/handlers/chat.js"); | ||||||
| var crypto = require("crypto"); | var crypto = require("crypto"); | ||||||
| var Filter = require("bad-words"); |  | ||||||
| var filter = new Filter({ placeHolder: "x" }); |  | ||||||
| /*var filter = { |  | ||||||
| clean: function(str) { |  | ||||||
| return str; |  | ||||||
| } |  | ||||||
| }*/ |  | ||||||
| var db = require(pathThumbnails + "/handlers/db.js"); | var db = require(pathThumbnails + "/handlers/db.js"); | ||||||
|  |  | ||||||
| function addFromOtherList(arr, guid, offline, socket) { | function addFromOtherList(arr, guid, offline, socket) { | ||||||
| @@ -29,9 +22,8 @@ function addFromOtherList(arr, guid, offline, socket) { | |||||||
|         }, |         }, | ||||||
|         new_channel: { |         new_channel: { | ||||||
|           expected: "string", |           expected: "string", | ||||||
|           got: arr.hasOwnProperty("new_channel") |           got: arr.hasOwnProperty("new_channel") ? | ||||||
|             ? typeof arr.new_channel |             typeof arr.new_channel : undefined | ||||||
|             : undefined |  | ||||||
|         } |         } | ||||||
|       }; |       }; | ||||||
|       socket.emit("update_required", result); |       socket.emit("update_required", result); | ||||||
| @@ -39,7 +31,9 @@ function addFromOtherList(arr, guid, offline, socket) { | |||||||
|     } |     } | ||||||
|     var channel = arr.channel; //.replace(/ /g,'').toLowerCase(); |     var channel = arr.channel; //.replace(/ /g,'').toLowerCase(); | ||||||
|     var new_channel = Functions.encodeChannelName(arr.new_channel); //.replace(/ /g, '').toLowerCase(); |     var new_channel = Functions.encodeChannelName(arr.new_channel); //.replace(/ /g, '').toLowerCase(); | ||||||
|     db.collection("frontpage_lists").find({ _id: new_channel }, function( |     db.collection("frontpage_lists").find({ | ||||||
|  |       _id: new_channel | ||||||
|  |     }, function ( | ||||||
|       err, |       err, | ||||||
|       fp |       fp | ||||||
|     ) { |     ) { | ||||||
| @@ -50,7 +44,7 @@ function addFromOtherList(arr, guid, offline, socket) { | |||||||
|       Functions.getSessionAdminUser( |       Functions.getSessionAdminUser( | ||||||
|         Functions.getSession(socket), |         Functions.getSession(socket), | ||||||
|         channel, |         channel, | ||||||
|         function(userpass, adminpass) { |         function (userpass, adminpass) { | ||||||
|           if (userpass != "" || arr.userpass == undefined) { |           if (userpass != "" || arr.userpass == undefined) { | ||||||
|             arr.userpass = userpass; |             arr.userpass = userpass; | ||||||
|           } else { |           } else { | ||||||
| @@ -69,7 +63,7 @@ function addFromOtherList(arr, guid, offline, socket) { | |||||||
|           Functions.getSessionAdminUser( |           Functions.getSessionAdminUser( | ||||||
|             Functions.getSession(socket), |             Functions.getSession(socket), | ||||||
|             new_channel, |             new_channel, | ||||||
|             function(userpass) { |             function (userpass) { | ||||||
|               var otheruser = ""; |               var otheruser = ""; | ||||||
|               if (userpass != "") { |               if (userpass != "") { | ||||||
|                 otheruser = userpass; |                 otheruser = userpass; | ||||||
| @@ -80,17 +74,23 @@ function addFromOtherList(arr, guid, offline, socket) { | |||||||
|                   .digest("base64"); |                   .digest("base64"); | ||||||
|               } |               } | ||||||
|  |  | ||||||
|               db.collection(channel).find({ now_playing: true }, function( |               db.collection(channel).find({ | ||||||
|  |                 now_playing: true | ||||||
|  |               }, function ( | ||||||
|                 e, |                 e, | ||||||
|                 np |                 np | ||||||
|               ) { |               ) { | ||||||
|                 var project_object = { |                 var project_object = { | ||||||
|                   id: 1, |                   id: 1, | ||||||
|                   added: 1, |                   added: 1, | ||||||
|                   guids: { $literal: [] }, |                   guids: { | ||||||
|  |                     $literal: [] | ||||||
|  |                   }, | ||||||
|                   now_playing: 1, |                   now_playing: 1, | ||||||
|                   title: 1, |                   title: 1, | ||||||
|                   votes: { $literal: 0 }, |                   votes: { | ||||||
|  |                     $literal: 0 | ||||||
|  |                   }, | ||||||
|                   start: 1, |                   start: 1, | ||||||
|                   duration: 1, |                   duration: 1, | ||||||
|                   end: 1, |                   end: 1, | ||||||
| @@ -101,21 +101,25 @@ function addFromOtherList(arr, guid, offline, socket) { | |||||||
|                 }; |                 }; | ||||||
|                 var to_set_np = true; |                 var to_set_np = true; | ||||||
|                 if (np.length > 0) { |                 if (np.length > 0) { | ||||||
|                   project_object.now_playing = { $literal: false }; |                   project_object.now_playing = { | ||||||
|  |                     $literal: false | ||||||
|  |                   }; | ||||||
|                   to_set_np = false; |                   to_set_np = false; | ||||||
|                 } |                 } | ||||||
|                 db.collection(new_channel + "_settings").find( |                 db.collection(new_channel + "_settings").find({ | ||||||
|                   { id: "config" }, |                     id: "config" | ||||||
|                   function(e, this_conf) { |                   }, | ||||||
|  |                   function (e, this_conf) { | ||||||
|                     if ( |                     if ( | ||||||
|                       this_conf.length > 0 && |                       this_conf.length > 0 && | ||||||
|                       (this_conf[0].userpass == "" || |                       (this_conf[0].userpass == "" || | ||||||
|                         !this_conf[0].userpass || |                         !this_conf[0].userpass || | ||||||
|                         this_conf[0].userpass == otheruser) |                         this_conf[0].userpass == otheruser) | ||||||
|                     ) { |                     ) { | ||||||
|                       db.collection(channel + "_settings").find( |                       db.collection(channel + "_settings").find({ | ||||||
|                         { id: "config" }, |                           id: "config" | ||||||
|                         function(e, this_conf) { |                         }, | ||||||
|  |                         function (e, this_conf) { | ||||||
|                           var hash = arr.adminpass; |                           var hash = arr.adminpass; | ||||||
|                           if (this_conf.length == 0) { |                           if (this_conf.length == 0) { | ||||||
|                             socket.emit("toast", "nolist"); |                             socket.emit("toast", "nolist"); | ||||||
| @@ -128,8 +132,8 @@ function addFromOtherList(arr, guid, offline, socket) { | |||||||
|                           ) { |                           ) { | ||||||
|                             var connection_id = Functions.hash_pass( |                             var connection_id = Functions.hash_pass( | ||||||
|                               socket.handshake.headers["user-agent"] + |                               socket.handshake.headers["user-agent"] + | ||||||
|                                 socket.handshake.address + |                               socket.handshake.address + | ||||||
|                                 socket.handshake.headers["accept-language"] |                               socket.handshake.headers["accept-language"] | ||||||
|                             ); |                             ); | ||||||
|                             Functions.checkTimeout( |                             Functions.checkTimeout( | ||||||
|                               "add_playlist", |                               "add_playlist", | ||||||
| @@ -139,7 +143,7 @@ function addFromOtherList(arr, guid, offline, socket) { | |||||||
|                               this_conf[0].adminpass, |                               this_conf[0].adminpass, | ||||||
|                               hash, |                               hash, | ||||||
|                               socket, |                               socket, | ||||||
|                               function() { |                               function () { | ||||||
|                                 if ( |                                 if ( | ||||||
|                                   (this_conf[0].addsongs === true && |                                   (this_conf[0].addsongs === true && | ||||||
|                                     (hash == this_conf[0].adminpass || |                                     (hash == this_conf[0].adminpass || | ||||||
| @@ -147,15 +151,16 @@ function addFromOtherList(arr, guid, offline, socket) { | |||||||
|                                   this_conf[0].addsongs === false |                                   this_conf[0].addsongs === false | ||||||
|                                 ) { |                                 ) { | ||||||
|                                   db.collection(new_channel).aggregate( |                                   db.collection(new_channel).aggregate( | ||||||
|                                     [ |                                     [{ | ||||||
|                                       { |                                         $match: { | ||||||
|                                         $match: { type: "video" } |                                           type: "video" | ||||||
|  |                                         } | ||||||
|                                       }, |                                       }, | ||||||
|                                       { |                                       { | ||||||
|                                         $project: project_object |                                         $project: project_object | ||||||
|                                       } |                                       } | ||||||
|                                     ], |                                     ], | ||||||
|                                     function(e, docs) { |                                     function (e, docs) { | ||||||
|                                       var path = require("path"); |                                       var path = require("path"); | ||||||
|                                       var mongo_config = require(path.join( |                                       var mongo_config = require(path.join( | ||||||
|                                         path.join(__dirname, "../config/"), |                                         path.join(__dirname, "../config/"), | ||||||
| @@ -171,29 +176,31 @@ function addFromOtherList(arr, guid, offline, socket) { | |||||||
|                                         "/"; |                                         "/"; | ||||||
|                                       MongoClient.connect( |                                       MongoClient.connect( | ||||||
|                                         url, |                                         url, | ||||||
|                                         function(err, _db) { |                                         function (err, _db) { | ||||||
|                                           var dbo = _db.db(mongo_config.config); |                                           var dbo = _db.db(mongo_config.config); | ||||||
|                                           dbo |                                           dbo | ||||||
|                                             .collection(channel) |                                             .collection(channel) | ||||||
|                                             .insertMany( |                                             .insertMany( | ||||||
|                                               docs, |                                               docs, { | ||||||
|                                               { ordered: false }, |                                                 ordered: false | ||||||
|                                               function(err, res) { |                                               }, | ||||||
|                                                 db.collection(channel).count( |                                               function (err, res) { | ||||||
|                                                   { |                                                 db.collection(channel).count({ | ||||||
|                                                     type: { $ne: "suggested" } |                                                     type: { | ||||||
|  |                                                       $ne: "suggested" | ||||||
|  |                                                     } | ||||||
|                                                   }, |                                                   }, | ||||||
|                                                   function(err, count) { |                                                   function (err, count) { | ||||||
|                                                     db.collection( |                                                     db.collection( | ||||||
|                                                       channel + "_settings" |                                                       channel + "_settings" | ||||||
|                                                     ).update( |                                                     ).update({ | ||||||
|                                                       { id: "config" }, |                                                         id: "config" | ||||||
|                                                       { |                                                       }, { | ||||||
|                                                         $set: { |                                                         $set: { | ||||||
|                                                           startTime: Functions.get_time() |                                                           startTime: Functions.get_time() | ||||||
|                                                         } |                                                         } | ||||||
|                                                       }, |                                                       }, | ||||||
|                                                       function(e, d) { |                                                       function (e, d) { | ||||||
|                                                         if (to_set_np) { |                                                         if (to_set_np) { | ||||||
|                                                           var to_change = { |                                                           var to_change = { | ||||||
|                                                             _id: channel, |                                                             _id: channel, | ||||||
| @@ -203,11 +210,10 @@ function addFromOtherList(arr, guid, offline, socket) { | |||||||
|                                                           }; |                                                           }; | ||||||
|                                                           db.collection( |                                                           db.collection( | ||||||
|                                                             new_channel |                                                             new_channel | ||||||
|                                                           ).find( |                                                           ).find({ | ||||||
|                                                             { |  | ||||||
|                                                               now_playing: true |                                                               now_playing: true | ||||||
|                                                             }, |                                                             }, | ||||||
|                                                             function( |                                                             function ( | ||||||
|                                                               e, |                                                               e, | ||||||
|                                                               np_docs |                                                               np_docs | ||||||
|                                                             ) { |                                                             ) { | ||||||
| @@ -217,36 +223,35 @@ function addFromOtherList(arr, guid, offline, socket) { | |||||||
|                                                                 np_docs[0].title; |                                                                 np_docs[0].title; | ||||||
|                                                               db.collection( |                                                               db.collection( | ||||||
|                                                                 "frontpage_lists" |                                                                 "frontpage_lists" | ||||||
|                                                               ).find( |                                                               ).find({ | ||||||
|                                                                 { |  | ||||||
|                                                                   _id: new_channel |                                                                   _id: new_channel | ||||||
|                                                                 }, |                                                                 }, | ||||||
|                                                                 function( |                                                                 function ( | ||||||
|                                                                   e, |                                                                   e, | ||||||
|                                                                   doc |                                                                   doc | ||||||
|                                                                 ) { |                                                                 ) { | ||||||
|                                                                   if ( |                                                                   if ( | ||||||
|                                                                     doc.length > |                                                                     doc.length > | ||||||
|                                                                       0 && |                                                                     0 && | ||||||
|                                                                     ((doc[0] |                                                                     ((doc[0] | ||||||
|                                                                       .thumbnail != |                                                                         .thumbnail != | ||||||
|                                                                       "" && |                                                                         "" && | ||||||
|                                                                       doc[0] |                                                                         doc[0] | ||||||
|                                                                         .thumbnail != |                                                                         .thumbnail != | ||||||
|                                                                         undefined && |                                                                         undefined && | ||||||
|                                                                       (doc[0].thumbnail.indexOf( |                                                                         (doc[0].thumbnail.indexOf( | ||||||
|                                                                         "https://i1.sndcdn.com" |                                                                             "https://i1.sndcdn.com" | ||||||
|                                                                       ) > -1 || |                                                                           ) > -1 || | ||||||
|                                                                         doc[0].thumbnail.indexOf( |                                                                           doc[0].thumbnail.indexOf( | ||||||
|                                                                           "https://w1.sndcdn.com" |                                                                             "https://w1.sndcdn.com" | ||||||
|                                                                         ) > |                                                                           ) > | ||||||
|                                                                           -1)) || |                                                                           -1)) || | ||||||
|                                                                       (doc[0] |                                                                       (doc[0] | ||||||
|                                                                         .thumbnail == |                                                                         .thumbnail == | ||||||
|                                                                         "" || |                                                                         "" || | ||||||
|                                                                         doc[0] |                                                                         doc[0] | ||||||
|                                                                           .thumbnail == |                                                                         .thumbnail == | ||||||
|                                                                           undefined)) |                                                                         undefined)) | ||||||
|                                                                   ) { |                                                                   ) { | ||||||
|                                                                     to_change.thumbnail = |                                                                     to_change.thumbnail = | ||||||
|                                                                       np_docs[0].thumbnail; |                                                                       np_docs[0].thumbnail; | ||||||
| @@ -254,14 +259,12 @@ function addFromOtherList(arr, guid, offline, socket) { | |||||||
|  |  | ||||||
|                                                                   db.collection( |                                                                   db.collection( | ||||||
|                                                                     "frontpage_lists" |                                                                     "frontpage_lists" | ||||||
|                                                                   ).update( |                                                                   ).update({ | ||||||
|                                                                     { |  | ||||||
|                                                                       _id: channel |                                                                       _id: channel | ||||||
|                                                                     }, |                                                                     }, { | ||||||
|                                                                     { |  | ||||||
|                                                                       $set: to_change |                                                                       $set: to_change | ||||||
|                                                                     }, |                                                                     }, | ||||||
|                                                                     function( |                                                                     function ( | ||||||
|                                                                       e, |                                                                       e, | ||||||
|                                                                       d |                                                                       d | ||||||
|                                                                     ) { |                                                                     ) { | ||||||
| @@ -290,14 +293,14 @@ function addFromOtherList(arr, guid, offline, socket) { | |||||||
|                                                         } else { |                                                         } else { | ||||||
|                                                           db.collection( |                                                           db.collection( | ||||||
|                                                             "frontpage_lists" |                                                             "frontpage_lists" | ||||||
|                                                           ).update( |                                                           ).update({ | ||||||
|                                                             { _id: channel }, |                                                               _id: channel | ||||||
|                                                             { |                                                             }, { | ||||||
|                                                               $set: { |                                                               $set: { | ||||||
|                                                                 count: count |                                                                 count: count | ||||||
|                                                               } |                                                               } | ||||||
|                                                             }, |                                                             }, | ||||||
|                                                             function(e, d) { |                                                             function (e, d) { | ||||||
|                                                               List.send_list( |                                                               List.send_list( | ||||||
|                                                                 channel, |                                                                 channel, | ||||||
|                                                                 undefined, |                                                                 undefined, | ||||||
| @@ -382,7 +385,9 @@ function addPlaylist(arr, guid, offline, socket) { | |||||||
|       socket.emit("toast", "Empty list.."); |       socket.emit("toast", "Empty list.."); | ||||||
|       return; |       return; | ||||||
|     } |     } | ||||||
|     db.collection("frontpage_lists").find({ _id: channel }, function(err, fp) { |     db.collection("frontpage_lists").find({ | ||||||
|  |       _id: channel | ||||||
|  |     }, function (err, fp) { | ||||||
|       if (fp.length == 0) { |       if (fp.length == 0) { | ||||||
|         socket.emit("toast", "nolist"); |         socket.emit("toast", "nolist"); | ||||||
|         return; |         return; | ||||||
| @@ -391,7 +396,7 @@ function addPlaylist(arr, guid, offline, socket) { | |||||||
|       Functions.getSessionAdminUser( |       Functions.getSessionAdminUser( | ||||||
|         Functions.getSession(socket), |         Functions.getSession(socket), | ||||||
|         channel, |         channel, | ||||||
|         function(userpass, adminpass) { |         function (userpass, adminpass) { | ||||||
|           if (userpass != "" || arr.userpass == undefined) { |           if (userpass != "" || arr.userpass == undefined) { | ||||||
|             arr.userpass = userpass; |             arr.userpass = userpass; | ||||||
|           } else { |           } else { | ||||||
| @@ -407,12 +412,15 @@ function addPlaylist(arr, guid, offline, socket) { | |||||||
|               Functions.hash_pass(Functions.decrypt_string(arr.adminpass), true) |               Functions.hash_pass(Functions.decrypt_string(arr.adminpass), true) | ||||||
|             ); |             ); | ||||||
|           } |           } | ||||||
|           db.collection(channel).find({ now_playing: true }, function(e, np) { |           db.collection(channel).find({ | ||||||
|  |             now_playing: true | ||||||
|  |           }, function (e, np) { | ||||||
|             var now_playing = false; |             var now_playing = false; | ||||||
|             if (np.length == 0) now_playing = true; |             if (np.length == 0) now_playing = true; | ||||||
|             db.collection(channel + "_settings").find( |             db.collection(channel + "_settings").find({ | ||||||
|               { id: "config" }, |                 id: "config" | ||||||
|               function(e, conf) { |               }, | ||||||
|  |               function (e, conf) { | ||||||
|                 if (arr.length == 0 || arr.songs.length == 0) { |                 if (arr.length == 0 || arr.songs.length == 0) { | ||||||
|                   socket.emit("toast", "Empty list.."); |                   socket.emit("toast", "Empty list.."); | ||||||
|                   return; |                   return; | ||||||
| @@ -432,8 +440,8 @@ function addPlaylist(arr, guid, offline, socket) { | |||||||
|                     ) { |                     ) { | ||||||
|                       var connection_id = Functions.hash_pass( |                       var connection_id = Functions.hash_pass( | ||||||
|                         socket.handshake.headers["user-agent"] + |                         socket.handshake.headers["user-agent"] + | ||||||
|                           socket.handshake.address + |                         socket.handshake.address + | ||||||
|                           socket.handshake.headers["accept-language"] |                         socket.handshake.headers["accept-language"] | ||||||
|                       ); |                       ); | ||||||
|                       Functions.checkTimeout( |                       Functions.checkTimeout( | ||||||
|                         "add_playlist", |                         "add_playlist", | ||||||
| @@ -443,7 +451,7 @@ function addPlaylist(arr, guid, offline, socket) { | |||||||
|                         conf[0].adminpass, |                         conf[0].adminpass, | ||||||
|                         hash, |                         hash, | ||||||
|                         socket, |                         socket, | ||||||
|                         function() { |                         function () { | ||||||
|                           var path = require("path"); |                           var path = require("path"); | ||||||
|                           var mongo_config = require(path.join( |                           var mongo_config = require(path.join( | ||||||
|                             path.join(__dirname, "../config/"), |                             path.join(__dirname, "../config/"), | ||||||
| @@ -458,7 +466,7 @@ function addPlaylist(arr, guid, offline, socket) { | |||||||
|                             "/"; |                             "/"; | ||||||
|                           MongoClient.connect( |                           MongoClient.connect( | ||||||
|                             url, |                             url, | ||||||
|                             function(err, _db) { |                             function (err, _db) { | ||||||
|                               var dbo = _db.db(mongo_config.config); |                               var dbo = _db.db(mongo_config.config); | ||||||
|                               var number_elements = arr.songs.length + 1; |                               var number_elements = arr.songs.length + 1; | ||||||
|                               var time = Functions.get_time() - number_elements; |                               var time = Functions.get_time() - number_elements; | ||||||
| @@ -516,26 +524,29 @@ function addPlaylist(arr, guid, offline, socket) { | |||||||
|                                   } |                                   } | ||||||
|                                 } else if (this_element.source == "youtube") |                                 } else if (this_element.source == "youtube") | ||||||
|                                   this_element.thumbnail = |                                   this_element.thumbnail = | ||||||
|                                     "https://img.youtube.com/vi/" + |                                   "https://img.youtube.com/vi/" + | ||||||
|                                     this_element.id + |                                   this_element.id + | ||||||
|                                     "/mqdefault.jpg"; |                                   "/mqdefault.jpg"; | ||||||
|                                 if (now_playing) { |                                 if (now_playing) { | ||||||
|                                   now_playing = false; |                                   now_playing = false; | ||||||
|                                 } |                                 } | ||||||
|                                 bulk.insert(this_element); |                                 bulk.insert(this_element); | ||||||
|                               } |                               } | ||||||
|                               bulk.execute(function(err, results) { |                               bulk.execute(function (err, results) { | ||||||
|                                 db.collection(channel).count( |                                 db.collection(channel).count({ | ||||||
|                                   { type: { $ne: "suggested" } }, |                                     type: { | ||||||
|                                   function(err, count) { |                                       $ne: "suggested" | ||||||
|                                     db.collection(channel + "_settings").update( |                                     } | ||||||
|                                       { id: "config" }, |                                   }, | ||||||
|                                       { |                                   function (err, count) { | ||||||
|  |                                     db.collection(channel + "_settings").update({ | ||||||
|  |                                         id: "config" | ||||||
|  |                                       }, { | ||||||
|                                         $set: { |                                         $set: { | ||||||
|                                           startTime: Functions.get_time() |                                           startTime: Functions.get_time() | ||||||
|                                         } |                                         } | ||||||
|                                       }, |                                       }, | ||||||
|                                       function(e, d) { |                                       function (e, d) { | ||||||
|                                         if (to_set_np) { |                                         if (to_set_np) { | ||||||
|                                           var to_change = { |                                           var to_change = { | ||||||
|                                             _id: channel, |                                             _id: channel, | ||||||
| @@ -543,32 +554,35 @@ function addPlaylist(arr, guid, offline, socket) { | |||||||
|                                             frontpage: true, |                                             frontpage: true, | ||||||
|                                             accessed: Functions.get_time() |                                             accessed: Functions.get_time() | ||||||
|                                           }; |                                           }; | ||||||
|                                           db.collection(channel).find( |                                           db.collection(channel).find({ | ||||||
|                                             { now_playing: true }, |                                               now_playing: true | ||||||
|                                             function(e, np_docs) { |                                             }, | ||||||
|  |                                             function (e, np_docs) { | ||||||
|                                               to_change.id = np_docs[0].id; |                                               to_change.id = np_docs[0].id; | ||||||
|                                               to_change.title = |                                               to_change.title = | ||||||
|                                                 np_docs[0].title; |                                                 np_docs[0].title; | ||||||
|                                               db.collection( |                                               db.collection( | ||||||
|                                                 "frontpage_lists" |                                                 "frontpage_lists" | ||||||
|                                               ).find({ _id: channel }, function( |                                               ).find({ | ||||||
|  |                                                 _id: channel | ||||||
|  |                                               }, function ( | ||||||
|                                                 e, |                                                 e, | ||||||
|                                                 doc |                                                 doc | ||||||
|                                               ) { |                                               ) { | ||||||
|                                                 if ( |                                                 if ( | ||||||
|                                                   doc.length > 0 && |                                                   doc.length > 0 && | ||||||
|                                                   ((doc[0].thumbnail != "" && |                                                   ((doc[0].thumbnail != "" && | ||||||
|                                                     doc[0].thumbnail != |                                                       doc[0].thumbnail != | ||||||
|                                                       undefined && |                                                       undefined && | ||||||
|                                                     (doc[0].thumbnail.indexOf( |                                                       (doc[0].thumbnail.indexOf( | ||||||
|                                                       "https://i1.sndcdn.com" |                                                           "https://i1.sndcdn.com" | ||||||
|                                                     ) > -1 || |                                                         ) > -1 || | ||||||
|                                                       doc[0].thumbnail.indexOf( |                                                         doc[0].thumbnail.indexOf( | ||||||
|                                                         "https://w1.sndcdn.com" |                                                           "https://w1.sndcdn.com" | ||||||
|                                                       ) > -1)) || |                                                         ) > -1)) || | ||||||
|                                                     (doc[0].thumbnail == "" || |                                                     (doc[0].thumbnail == "" || | ||||||
|                                                       doc[0].thumbnail == |                                                       doc[0].thumbnail == | ||||||
|                                                         undefined)) |                                                       undefined)) | ||||||
|                                                 ) { |                                                 ) { | ||||||
|                                                   to_change.thumbnail = |                                                   to_change.thumbnail = | ||||||
|                                                     np_docs[0].thumbnail; |                                                     np_docs[0].thumbnail; | ||||||
| @@ -576,10 +590,12 @@ function addPlaylist(arr, guid, offline, socket) { | |||||||
|  |  | ||||||
|                                                 db.collection( |                                                 db.collection( | ||||||
|                                                   "frontpage_lists" |                                                   "frontpage_lists" | ||||||
|                                                 ).update( |                                                 ).update({ | ||||||
|                                                   { _id: channel }, |                                                     _id: channel | ||||||
|                                                   { $set: to_change }, |                                                   }, { | ||||||
|                                                   function(e, d) { |                                                     $set: to_change | ||||||
|  |                                                   }, | ||||||
|  |                                                   function (e, d) { | ||||||
|                                                     List.send_list( |                                                     List.send_list( | ||||||
|                                                       channel, |                                                       channel, | ||||||
|                                                       undefined, |                                                       undefined, | ||||||
| @@ -604,10 +620,14 @@ function addPlaylist(arr, guid, offline, socket) { | |||||||
|                                         } else { |                                         } else { | ||||||
|                                           db.collection( |                                           db.collection( | ||||||
|                                             "frontpage_lists" |                                             "frontpage_lists" | ||||||
|                                           ).update( |                                           ).update({ | ||||||
|                                             { _id: channel }, |                                               _id: channel | ||||||
|                                             { $set: { count: count } }, |                                             }, { | ||||||
|                                             function(e, d) { |                                               $set: { | ||||||
|  |                                                 count: count | ||||||
|  |                                               } | ||||||
|  |                                             }, | ||||||
|  |                                             function (e, d) { | ||||||
|                                               List.send_list( |                                               List.send_list( | ||||||
|                                                 channel, |                                                 channel, | ||||||
|                                                 undefined, |                                                 undefined, | ||||||
| @@ -753,9 +773,8 @@ function add_function(arr, coll, guid, offline, socket) { | |||||||
|         }, |         }, | ||||||
|         adminpass: { |         adminpass: { | ||||||
|           expected: "string", |           expected: "string", | ||||||
|           got: arr.hasOwnProperty("adminpass") |           got: arr.hasOwnProperty("adminpass") ? | ||||||
|             ? typeof arr.adminpass |             typeof arr.adminpass : undefined | ||||||
|             : undefined |  | ||||||
|         }, |         }, | ||||||
|         source: { |         source: { | ||||||
|           expected: "string (youtube or soundcloud)", |           expected: "string (youtube or soundcloud)", | ||||||
| @@ -763,9 +782,8 @@ function add_function(arr, coll, guid, offline, socket) { | |||||||
|         }, |         }, | ||||||
|         thumbnail: { |         thumbnail: { | ||||||
|           expected: "url if source == soundcloud", |           expected: "url if source == soundcloud", | ||||||
|           got: arr.hasOwnProperty("thumbnail") |           got: arr.hasOwnProperty("thumbnail") ? | ||||||
|             ? typeof arr.thumbnail |             typeof arr.thumbnail : undefined | ||||||
|             : undefined |  | ||||||
|         } |         } | ||||||
|       }; |       }; | ||||||
|       socket.emit("update_required", result); |       socket.emit("update_required", result); | ||||||
| @@ -774,7 +792,7 @@ function add_function(arr, coll, guid, offline, socket) { | |||||||
|     if (arr.hasOwnProperty("offsiteAdd") && arr.offsiteAdd) { |     if (arr.hasOwnProperty("offsiteAdd") && arr.offsiteAdd) { | ||||||
|       coll = arr.list; |       coll = arr.list; | ||||||
|     } |     } | ||||||
|     Functions.getSessionAdminUser(Functions.getSession(socket), coll, function( |     Functions.getSessionAdminUser(Functions.getSession(socket), coll, function ( | ||||||
|       userpass, |       userpass, | ||||||
|       adminpass |       adminpass | ||||||
|     ) { |     ) { | ||||||
| @@ -793,7 +811,7 @@ function add_function(arr, coll, guid, offline, socket) { | |||||||
|           .update(Functions.decrypt_string(arr.pass)) |           .update(Functions.decrypt_string(arr.pass)) | ||||||
|           .digest("base64"); |           .digest("base64"); | ||||||
|       } |       } | ||||||
|       db.collection(coll + "_settings").find(function(err, docs) { |       db.collection(coll + "_settings").find(function (err, docs) { | ||||||
|         if ( |         if ( | ||||||
|           docs.length > 0 && |           docs.length > 0 && | ||||||
|           (docs[0].userpass == undefined || |           (docs[0].userpass == undefined || | ||||||
| @@ -820,22 +838,28 @@ function add_function(arr, coll, guid, offline, socket) { | |||||||
|           var source = arr.source; |           var source = arr.source; | ||||||
|           var tags = arr.tags; |           var tags = arr.tags; | ||||||
|           conf = docs; |           conf = docs; | ||||||
|           Chat.getUserNameByGuid(guid, function(username) { |           Chat.getUserNameByGuid(guid, function (username) { | ||||||
|             if ( |             if ( | ||||||
|               docs !== null && |               docs !== null && | ||||||
|               docs.length !== 0 && |               docs.length !== 0 && | ||||||
|               ((docs[0].addsongs === true && |               ((docs[0].addsongs === true && | ||||||
|                 (hash == docs[0].adminpass || docs[0].adminpass === "")) || |                   (hash == docs[0].adminpass || docs[0].adminpass === "")) || | ||||||
|                 docs[0].addsongs === false) |                 docs[0].addsongs === false) | ||||||
|             ) { |             ) { | ||||||
|               db.collection(coll).find( |               db.collection(coll).find({ | ||||||
|                 { id: id, type: { $ne: "suggested" } }, |                   id: id, | ||||||
|                 function(err, docs) { |                   type: { | ||||||
|  |                     $ne: "suggested" | ||||||
|  |                   } | ||||||
|  |                 }, | ||||||
|  |                 function (err, docs) { | ||||||
|                   if (docs !== null && docs.length === 0) { |                   if (docs !== null && docs.length === 0) { | ||||||
|                     var guids = [guid]; |                     var guids = [guid]; | ||||||
|                     var added = Functions.get_time(); |                     var added = Functions.get_time(); | ||||||
|                     var votes = 1; |                     var votes = 1; | ||||||
|                     db.collection(coll).find({ now_playing: true }, function( |                     db.collection(coll).find({ | ||||||
|  |                       now_playing: true | ||||||
|  |                     }, function ( | ||||||
|                       err, |                       err, | ||||||
|                       docs |                       docs | ||||||
|                     ) { |                     ) { | ||||||
| @@ -871,26 +895,31 @@ function add_function(arr, coll, guid, offline, socket) { | |||||||
|                         } |                         } | ||||||
|                       } else if (source == "youtube") |                       } else if (source == "youtube") | ||||||
|                         new_song.thumbnail = |                         new_song.thumbnail = | ||||||
|                           "https://img.youtube.com/vi/" + |                         "https://img.youtube.com/vi/" + | ||||||
|                           new_song.id + |                         new_song.id + | ||||||
|                           "/mqdefault.jpg"; |                         "/mqdefault.jpg"; | ||||||
|                       db.collection(coll).update( |                       db.collection(coll).update({ | ||||||
|                         { id: id }, |                           id: id | ||||||
|                         new_song, |                         }, | ||||||
|                         { upsert: true }, |                         new_song, { | ||||||
|                         function(err, docs) { |                           upsert: true | ||||||
|  |                         }, | ||||||
|  |                         function (err, docs) { | ||||||
|                           new_song._id = "asd"; |                           new_song._id = "asd"; | ||||||
|                           if (np) { |                           if (np) { | ||||||
|                             List.send_list(coll, undefined, false, true, false); |                             List.send_list(coll, undefined, false, true, false); | ||||||
|                             db.collection(coll + "_settings").update( |                             db.collection(coll + "_settings").update({ | ||||||
|                               { id: "config" }, |                               id: "config" | ||||||
|                               { $set: { startTime: Functions.get_time() } } |                             }, { | ||||||
|                             ); |                               $set: { | ||||||
|  |                                 startTime: Functions.get_time() | ||||||
|  |                               } | ||||||
|  |                             }); | ||||||
|                             List.send_play(coll, undefined); |                             List.send_play(coll, undefined); | ||||||
|                             var thumbnail = |                             var thumbnail = | ||||||
|                               arr.thumbnail != undefined |                               arr.thumbnail != undefined ? | ||||||
|                                 ? arr.thumbnail |                               arr.thumbnail : | ||||||
|                                 : undefined; |                               undefined; | ||||||
|                             Frontpage.update_frontpage( |                             Frontpage.update_frontpage( | ||||||
|                               coll, |                               coll, | ||||||
|                               id, |                               id, | ||||||
| @@ -912,14 +941,19 @@ function add_function(arr, coll, guid, offline, socket) { | |||||||
|                             else if (source == "soundcloud") |                             else if (source == "soundcloud") | ||||||
|                               Search.get_genres_soundcloud(new_song, coll); |                               Search.get_genres_soundcloud(new_song, coll); | ||||||
|                           } |                           } | ||||||
|                           db.collection("frontpage_lists").update( |                           db.collection("frontpage_lists").update({ | ||||||
|                             { _id: coll }, |                               _id: coll | ||||||
|                             { |                             }, { | ||||||
|                               $inc: { count: 1 }, |                               $inc: { | ||||||
|                               $set: { accessed: Functions.get_time() } |                                 count: 1 | ||||||
|  |                               }, | ||||||
|  |                               $set: { | ||||||
|  |                                 accessed: Functions.get_time() | ||||||
|  |                               } | ||||||
|  |                             }, { | ||||||
|  |                               upsert: true | ||||||
|                             }, |                             }, | ||||||
|                             { upsert: true }, |                             function (err, docs) {} | ||||||
|                             function(err, docs) {} |  | ||||||
|                           ); |                           ); | ||||||
|                           List.getNextSong(coll, undefined); |                           List.getNextSong(coll, undefined); | ||||||
|                         } |                         } | ||||||
| @@ -932,7 +966,9 @@ function add_function(arr, coll, guid, offline, socket) { | |||||||
|                 } |                 } | ||||||
|               ); |               ); | ||||||
|             } else { |             } else { | ||||||
|               db.collection(coll).find({ id: id }, function(err, docs) { |               db.collection(coll).find({ | ||||||
|  |                 id: id | ||||||
|  |               }, function (err, docs) { | ||||||
|                 if (docs.length === 0) { |                 if (docs.length === 0) { | ||||||
|                   var suggestedAdd = { |                   var suggestedAdd = { | ||||||
|                     added: Functions.get_time(), |                     added: Functions.get_time(), | ||||||
| @@ -955,11 +991,14 @@ function add_function(arr, coll, guid, offline, socket) { | |||||||
|                   } else { |                   } else { | ||||||
|                     suggestedAdd.source = "youtube"; |                     suggestedAdd.source = "youtube"; | ||||||
|                   } |                   } | ||||||
|                   db.collection(coll).update( |                   db.collection(coll).update({ | ||||||
|                     { id: id }, |                       id: id | ||||||
|                     { $set: suggestedAdd }, |                     }, { | ||||||
|                     { upsert: true }, |                       $set: suggestedAdd | ||||||
|                     function(err, docs) { |                     }, { | ||||||
|  |                       upsert: true | ||||||
|  |                     }, | ||||||
|  |                     function (err, docs) { | ||||||
|                       socket.emit("toast", "suggested"); |                       socket.emit("toast", "suggested"); | ||||||
|                       var toSend = suggestedAdd; |                       var toSend = suggestedAdd; | ||||||
|                       toSend.guids = []; |                       toSend.guids = []; | ||||||
| @@ -1035,9 +1074,8 @@ function voteUndecided(msg, coll, guid, offline, socket) { | |||||||
|         }, |         }, | ||||||
|         adminpass: { |         adminpass: { | ||||||
|           expected: "adminpass", |           expected: "adminpass", | ||||||
|           got: msg.hasOwnProperty("adminpass") |           got: msg.hasOwnProperty("adminpass") ? | ||||||
|             ? typeof msg.adminpass |             typeof msg.adminpass : undefined | ||||||
|             : undefined |  | ||||||
|         }, |         }, | ||||||
|         pass: { |         pass: { | ||||||
|           expected: "string", |           expected: "string", | ||||||
| @@ -1050,7 +1088,7 @@ function voteUndecided(msg, coll, guid, offline, socket) { | |||||||
|     coll = msg.channel.toLowerCase(); //.replace(/ /g,''); |     coll = msg.channel.toLowerCase(); //.replace(/ /g,''); | ||||||
|     coll = Functions.removeEmojis(coll).toLowerCase(); |     coll = Functions.removeEmojis(coll).toLowerCase(); | ||||||
|     //coll = filter.clean(coll); |     //coll = filter.clean(coll); | ||||||
|     Functions.getSessionAdminUser(Functions.getSession(socket), coll, function( |     Functions.getSessionAdminUser(Functions.getSession(socket), coll, function ( | ||||||
|       userpass, |       userpass, | ||||||
|       adminpass |       adminpass | ||||||
|     ) { |     ) { | ||||||
| @@ -1070,7 +1108,9 @@ function voteUndecided(msg, coll, guid, offline, socket) { | |||||||
|           .digest("base64"); |           .digest("base64"); | ||||||
|       } |       } | ||||||
|  |  | ||||||
|       db.collection(coll + "_settings").find({ id: "config" }, function( |       db.collection(coll + "_settings").find({ | ||||||
|  |         id: "config" | ||||||
|  |       }, function ( | ||||||
|         err, |         err, | ||||||
|         docs |         docs | ||||||
|       ) { |       ) { | ||||||
| @@ -1098,7 +1138,7 @@ function voteUndecided(msg, coll, guid, offline, socket) { | |||||||
|               docs !== null && |               docs !== null && | ||||||
|               docs.length !== 0 && |               docs.length !== 0 && | ||||||
|               ((docs[0].vote === true && |               ((docs[0].vote === true && | ||||||
|                 (hash == docs[0].adminpass || docs[0].adminpass === "")) || |                   (hash == docs[0].adminpass || docs[0].adminpass === "")) || | ||||||
|                 docs[0].vote === false) |                 docs[0].vote === false) | ||||||
|             ) { |             ) { | ||||||
|               vote(coll, id, guid, socket); |               vote(coll, id, guid, socket); | ||||||
| @@ -1145,7 +1185,7 @@ function shuffle(msg, coll, guid, offline, socket) { | |||||||
|   coll = msg.channel.toLowerCase(); //.replace(/ /g,''); |   coll = msg.channel.toLowerCase(); //.replace(/ /g,''); | ||||||
|   coll = Functions.removeEmojis(coll).toLowerCase(); |   coll = Functions.removeEmojis(coll).toLowerCase(); | ||||||
|   //coll = filter.clean(coll); |   //coll = filter.clean(coll); | ||||||
|   Functions.getSessionAdminUser(Functions.getSession(socket), coll, function( |   Functions.getSessionAdminUser(Functions.getSession(socket), coll, function ( | ||||||
|     userpass, |     userpass, | ||||||
|     adminpass |     adminpass | ||||||
|   ) { |   ) { | ||||||
| @@ -1174,7 +1214,7 @@ function shuffle(msg, coll, guid, offline, socket) { | |||||||
|       "foo", |       "foo", | ||||||
|       "bar", |       "bar", | ||||||
|       socket, |       socket, | ||||||
|       function() { |       function () { | ||||||
|         Functions.check_inlist( |         Functions.check_inlist( | ||||||
|           coll, |           coll, | ||||||
|           guid, |           guid, | ||||||
| @@ -1184,7 +1224,7 @@ function shuffle(msg, coll, guid, offline, socket) { | |||||||
|           "place 7" |           "place 7" | ||||||
|         ); |         ); | ||||||
|         var hash = msg.adminpass; |         var hash = msg.adminpass; | ||||||
|         db.collection(coll + "_settings").find(function(err, docs) { |         db.collection(coll + "_settings").find(function (err, docs) { | ||||||
|           if ( |           if ( | ||||||
|             docs.length > 0 && |             docs.length > 0 && | ||||||
|             (docs[0].userpass == undefined || |             (docs[0].userpass == undefined || | ||||||
| @@ -1198,8 +1238,10 @@ function shuffle(msg, coll, guid, offline, socket) { | |||||||
|                 docs[0].shuffle === false) |                 docs[0].shuffle === false) | ||||||
|             ) { |             ) { | ||||||
|               db.collection(coll) |               db.collection(coll) | ||||||
|                 .find({ now_playing: false }) |                 .find({ | ||||||
|                 .forEach(function(err, docs) { |                   now_playing: false | ||||||
|  |                 }) | ||||||
|  |                 .forEach(function (err, docs) { | ||||||
|                   if (!docs) { |                   if (!docs) { | ||||||
|                     List.send_list(coll, undefined, false, true, false, true); |                     List.send_list(coll, undefined, false, true, false, true); | ||||||
|                     socket.emit("toast", "shuffled"); |                     socket.emit("toast", "shuffled"); | ||||||
| @@ -1207,10 +1249,13 @@ function shuffle(msg, coll, guid, offline, socket) { | |||||||
|                     return; |                     return; | ||||||
|                   } else { |                   } else { | ||||||
|                     num = Math.floor(Math.random() * 1000000); |                     num = Math.floor(Math.random() * 1000000); | ||||||
|                     db.collection(coll).update( |                     db.collection(coll).update({ | ||||||
|                       { id: docs.id }, |                       id: docs.id | ||||||
|                       { $set: { added: num } } |                     }, { | ||||||
|                     ); |                       $set: { | ||||||
|  |                         added: num | ||||||
|  |                       } | ||||||
|  |                     }); | ||||||
|                   } |                   } | ||||||
|                 }); |                 }); | ||||||
|             } else socket.emit("toast", "wrongpass"); |             } else socket.emit("toast", "wrongpass"); | ||||||
| @@ -1219,7 +1264,7 @@ function shuffle(msg, coll, guid, offline, socket) { | |||||||
|           } |           } | ||||||
|         }); |         }); | ||||||
|  |  | ||||||
|         var complete = function(tot, curr) { |         var complete = function (tot, curr) { | ||||||
|           if (tot == curr) { |           if (tot == curr) { | ||||||
|             List.send_list(coll, undefined, false, true, false); |             List.send_list(coll, undefined, false, true, false); | ||||||
|             List.getNextSong(coll, undefined); |             List.getNextSong(coll, undefined); | ||||||
| @@ -1236,33 +1281,45 @@ function del(params, socket, socketid) { | |||||||
|     //coll = coll.replace(/_/g, "").replace(/ /g,''); |     //coll = coll.replace(/_/g, "").replace(/ /g,''); | ||||||
|  |  | ||||||
|     //coll = filter.clean(coll); |     //coll = filter.clean(coll); | ||||||
|     db.collection(coll + "_settings").find(function(err, docs) { |     db.collection(coll + "_settings").find(function (err, docs) { | ||||||
|       if ( |       if ( | ||||||
|         docs !== null && |         docs !== null && | ||||||
|         docs.length !== 0 && |         docs.length !== 0 && | ||||||
|         docs[0].adminpass == params.adminpass |         docs[0].adminpass == params.adminpass | ||||||
|       ) { |       ) { | ||||||
|         db.collection(coll).find({ id: params.id }, function(err, docs) { |         db.collection(coll).find({ | ||||||
|  |           id: params.id | ||||||
|  |         }, function (err, docs) { | ||||||
|           var dont_increment = false; |           var dont_increment = false; | ||||||
|           if (docs[0]) { |           if (docs[0]) { | ||||||
|             if (docs[0].type == "suggested") { |             if (docs[0].type == "suggested") { | ||||||
|               dont_increment = true; |               dont_increment = true; | ||||||
|             } |             } | ||||||
|             db.collection(coll).remove({ id: params.id }, function(err, docs) { |             db.collection(coll).remove({ | ||||||
|  |               id: params.id | ||||||
|  |             }, function (err, docs) { | ||||||
|               socket.emit("toast", "deletesong"); |               socket.emit("toast", "deletesong"); | ||||||
|               io.to(coll).emit("channel", { |               io.to(coll).emit("channel", { | ||||||
|                 type: "deleted", |                 type: "deleted", | ||||||
|                 value: params.id |                 value: params.id | ||||||
|               }); |               }); | ||||||
|               if (!dont_increment) |               if (!dont_increment) | ||||||
|                 db.collection("frontpage_lists").update( |                 db.collection("frontpage_lists").update({ | ||||||
|                   { _id: coll, count: { $gt: 0 } }, |                     _id: coll, | ||||||
|                   { |                     count: { | ||||||
|                     $inc: { count: -1 }, |                       $gt: 0 | ||||||
|                     $set: { accessed: Functions.get_time() } |                     } | ||||||
|  |                   }, { | ||||||
|  |                     $inc: { | ||||||
|  |                       count: -1 | ||||||
|  |                     }, | ||||||
|  |                     $set: { | ||||||
|  |                       accessed: Functions.get_time() | ||||||
|  |                     } | ||||||
|  |                   }, { | ||||||
|  |                     upsert: true | ||||||
|                   }, |                   }, | ||||||
|                   { upsert: true }, |                   function (err, docs) {} | ||||||
|                   function(err, docs) {} |  | ||||||
|                 ); |                 ); | ||||||
|             }); |             }); | ||||||
|           } |           } | ||||||
| @@ -1283,9 +1340,8 @@ function delete_all(msg, coll, guid, offline, socket) { | |||||||
|         }, |         }, | ||||||
|         adminpass: { |         adminpass: { | ||||||
|           expected: "adminpass", |           expected: "adminpass", | ||||||
|           got: msg.hasOwnProperty("adminpass") |           got: msg.hasOwnProperty("adminpass") ? | ||||||
|             ? typeof msg.adminpass |             typeof msg.adminpass : undefined | ||||||
|             : undefined |  | ||||||
|         }, |         }, | ||||||
|         pass: { |         pass: { | ||||||
|           expected: "string", |           expected: "string", | ||||||
| @@ -1301,7 +1357,7 @@ function delete_all(msg, coll, guid, offline, socket) { | |||||||
|     //coll = coll.replace(/ /g,''); |     //coll = coll.replace(/ /g,''); | ||||||
|     coll = Functions.removeEmojis(coll).toLowerCase(); |     coll = Functions.removeEmojis(coll).toLowerCase(); | ||||||
|     //coll = filter.clean(coll); |     //coll = filter.clean(coll); | ||||||
|     Functions.getSessionAdminUser(Functions.getSession(socket), coll, function( |     Functions.getSessionAdminUser(Functions.getSession(socket), coll, function ( | ||||||
|       userpass, |       userpass, | ||||||
|       adminpass, |       adminpass, | ||||||
|       gotten |       gotten | ||||||
| @@ -1323,7 +1379,7 @@ function delete_all(msg, coll, guid, offline, socket) { | |||||||
|       } |       } | ||||||
|       var hash = msg.adminpass; |       var hash = msg.adminpass; | ||||||
|       var hash_userpass = msg.pass; |       var hash_userpass = msg.pass; | ||||||
|       db.collection(coll + "_settings").find(function(err, conf) { |       db.collection(coll + "_settings").find(function (err, conf) { | ||||||
|         if (conf.length == 1 && conf) { |         if (conf.length == 1 && conf) { | ||||||
|           conf = conf[0]; |           conf = conf[0]; | ||||||
|           if ( |           if ( | ||||||
| @@ -1335,16 +1391,27 @@ function delete_all(msg, coll, guid, offline, socket) { | |||||||
|                 conf.userpass != undefined && |                 conf.userpass != undefined && | ||||||
|                 conf.pass == hash_userpass)) |                 conf.pass == hash_userpass)) | ||||||
|           ) { |           ) { | ||||||
|             db.collection(coll).remove( |             db.collection(coll).remove({ | ||||||
|               { views: { $exists: false }, type: "video" }, |                 views: { | ||||||
|               { multi: true }, |                   $exists: false | ||||||
|               function(err, succ) { |                 }, | ||||||
|  |                 type: "video" | ||||||
|  |               }, { | ||||||
|  |                 multi: true | ||||||
|  |               }, | ||||||
|  |               function (err, succ) { | ||||||
|                 List.send_list(coll, false, true, true, true); |                 List.send_list(coll, false, true, true, true); | ||||||
|                 db.collection("frontpage_lists").update( |                 db.collection("frontpage_lists").update({ | ||||||
|                   { _id: coll }, |                     _id: coll | ||||||
|                   { $set: { count: 0, accessed: Functions.get_time() } }, |                   }, { | ||||||
|                   { upsert: true }, |                     $set: { | ||||||
|                   function(err, docs) {} |                       count: 0, | ||||||
|  |                       accessed: Functions.get_time() | ||||||
|  |                     } | ||||||
|  |                   }, { | ||||||
|  |                     upsert: true | ||||||
|  |                   }, | ||||||
|  |                   function (err, docs) {} | ||||||
|                 ); |                 ); | ||||||
|                 socket.emit("toast", "deleted_songs"); |                 socket.emit("toast", "deleted_songs"); | ||||||
|               } |               } | ||||||
| @@ -1369,22 +1436,31 @@ function delete_all(msg, coll, guid, offline, socket) { | |||||||
|  |  | ||||||
| function vote(coll, id, guid, socket) { | function vote(coll, id, guid, socket) { | ||||||
|   //coll = coll.replace(/ /g,''); |   //coll = coll.replace(/ /g,''); | ||||||
|   db.collection(coll).find( |   db.collection(coll).find({ | ||||||
|     { id: id, now_playing: false, type: "video" }, |       id: id, | ||||||
|     function(err, docs) { |       now_playing: false, | ||||||
|  |       type: "video" | ||||||
|  |     }, | ||||||
|  |     function (err, docs) { | ||||||
|       if ( |       if ( | ||||||
|         docs !== null && |         docs !== null && | ||||||
|         docs.length > 0 && |         docs.length > 0 && | ||||||
|         !Functions.contains(docs[0].guids, guid) |         !Functions.contains(docs[0].guids, guid) | ||||||
|       ) { |       ) { | ||||||
|         db.collection(coll).update( |         db.collection(coll).update({ | ||||||
|           { id: id }, |             id: id | ||||||
|           { |           }, { | ||||||
|             $inc: { votes: 1 }, |             $inc: { | ||||||
|             $set: { added: Functions.get_time() }, |               votes: 1 | ||||||
|             $push: { guids: guid } |             }, | ||||||
|  |             $set: { | ||||||
|  |               added: Functions.get_time() | ||||||
|  |             }, | ||||||
|  |             $push: { | ||||||
|  |               guids: guid | ||||||
|  |             } | ||||||
|           }, |           }, | ||||||
|           function(err, docs) { |           function (err, docs) { | ||||||
|             socket.emit("toast", "voted"); |             socket.emit("toast", "voted"); | ||||||
|             io.to(coll).emit("channel", { |             io.to(coll).emit("channel", { | ||||||
|               type: "vote", |               type: "vote", | ||||||
| @@ -1409,4 +1485,4 @@ module.exports.voteUndecided = voteUndecided; | |||||||
| module.exports.shuffle = shuffle; | module.exports.shuffle = shuffle; | ||||||
| module.exports.del = del; | module.exports.del = del; | ||||||
| module.exports.delete_all = delete_all; | module.exports.delete_all = delete_all; | ||||||
| module.exports.vote = vote; | module.exports.vote = vote; | ||||||
| @@ -1,12 +1,5 @@ | |||||||
| var Functions = require(pathThumbnails + "/handlers/functions.js"); | var Functions = require(pathThumbnails + "/handlers/functions.js"); | ||||||
| var crypto = require("crypto"); | var crypto = require("crypto"); | ||||||
| var Filter = require("bad-words"); |  | ||||||
| var filter = new Filter({ placeHolder: "x" }); |  | ||||||
| /*var filter = { |  | ||||||
|     clean: function(str) { |  | ||||||
|         return str; |  | ||||||
|     } |  | ||||||
| }*/ |  | ||||||
| var projects = require(pathThumbnails + "/handlers/aggregates.js"); | var projects = require(pathThumbnails + "/handlers/aggregates.js"); | ||||||
| var db = require(pathThumbnails + "/handlers/db.js"); | var db = require(pathThumbnails + "/handlers/db.js"); | ||||||
|  |  | ||||||
| @@ -48,12 +41,12 @@ function password(inp, coll, guid, offline, socket) { | |||||||
|     uncrypted = pw; |     uncrypted = pw; | ||||||
|     pw = Functions.hash_pass(Functions.decrypt_string(pw), true); |     pw = Functions.hash_pass(Functions.decrypt_string(pw), true); | ||||||
|     Functions.check_inlist(coll, guid, socket, offline, undefined, "place 8"); |     Functions.check_inlist(coll, guid, socket, offline, undefined, "place 8"); | ||||||
|     Functions.getSessionAdminUser(sessionId, coll, function( |     Functions.getSessionAdminUser(sessionId, coll, function ( | ||||||
|       userpass, |       userpass, | ||||||
|       adminpass |       adminpass | ||||||
|     ) { |     ) { | ||||||
|       adminpass = Functions.hash_pass(adminpass); |       adminpass = Functions.hash_pass(adminpass); | ||||||
|       db.collection(coll + "_settings").find(function(err, docs) { |       db.collection(coll + "_settings").find(function (err, docs) { | ||||||
|         if (docs !== null && docs.length !== 0) { |         if (docs !== null && docs.length !== 0) { | ||||||
|           if ( |           if ( | ||||||
|             docs[0].adminpass === "" || |             docs[0].adminpass === "" || | ||||||
| @@ -63,11 +56,15 @@ function password(inp, coll, guid, offline, socket) { | |||||||
|               sessionId, |               sessionId, | ||||||
|               inp.password, |               inp.password, | ||||||
|               coll, |               coll, | ||||||
|               function() { |               function () { | ||||||
|                 db.collection(coll + "_settings").update( |                 db.collection(coll + "_settings").update({ | ||||||
|                   { id: "config" }, |                     id: "config" | ||||||
|                   { $set: { adminpass: Functions.hash_pass(pw) } }, |                   }, { | ||||||
|                   function(err, docs) { |                     $set: { | ||||||
|  |                       adminpass: Functions.hash_pass(pw) | ||||||
|  |                     } | ||||||
|  |                   }, | ||||||
|  |                   function (err, docs) { | ||||||
|                     if (adminpass != pw && adminpass != "") { |                     if (adminpass != pw && adminpass != "") { | ||||||
|                       socket.emit("toast", "changedpass"); |                       socket.emit("toast", "changedpass"); | ||||||
|                     } else { |                     } else { | ||||||
| @@ -86,11 +83,15 @@ function password(inp, coll, guid, offline, socket) { | |||||||
|               sessionId, |               sessionId, | ||||||
|               inp.password, |               inp.password, | ||||||
|               coll, |               coll, | ||||||
|               function() { |               function () { | ||||||
|                 db.collection(coll + "_settings").update( |                 db.collection(coll + "_settings").update({ | ||||||
|                   { id: "config" }, |                     id: "config" | ||||||
|                   { $set: { adminpass: Functions.hash_pass(pw) } }, |                   }, { | ||||||
|                   function(err, docs) { |                     $set: { | ||||||
|  |                       adminpass: Functions.hash_pass(pw) | ||||||
|  |                     } | ||||||
|  |                   }, | ||||||
|  |                   function (err, docs) { | ||||||
|                     if (adminpass != pw) { |                     if (adminpass != pw) { | ||||||
|                       socket.emit("toast", "changedpass"); |                       socket.emit("toast", "changedpass"); | ||||||
|                     } |                     } | ||||||
| @@ -104,7 +105,7 @@ function password(inp, coll, guid, offline, socket) { | |||||||
|               Functions.getSession(socket), |               Functions.getSession(socket), | ||||||
|               "", |               "", | ||||||
|               coll, |               coll, | ||||||
|               function() { |               function () { | ||||||
|                 socket.emit("toast", "wrongpass"); |                 socket.emit("toast", "wrongpass"); | ||||||
|                 socket.emit("pw", false); |                 socket.emit("pw", false); | ||||||
|               } |               } | ||||||
| @@ -146,7 +147,7 @@ function conf_function(params, coll, guid, offline, socket) { | |||||||
|  |  | ||||||
|     Functions.check_inlist(coll, guid, socket, offline, undefined, "place 9"); |     Functions.check_inlist(coll, guid, socket, offline, undefined, "place 9"); | ||||||
|  |  | ||||||
|     Functions.getSessionAdminUser(Functions.getSession(socket), coll, function( |     Functions.getSessionAdminUser(Functions.getSession(socket), coll, function ( | ||||||
|       userpass, |       userpass, | ||||||
|       adminpass, |       adminpass, | ||||||
|       gotten |       gotten | ||||||
| @@ -181,15 +182,13 @@ function conf_function(params, coll, guid, offline, socket) { | |||||||
|         var result = { |         var result = { | ||||||
|           adminpass: { |           adminpass: { | ||||||
|             expected: "string", |             expected: "string", | ||||||
|             got: params.hasOwnProperty("adminpass") |             got: params.hasOwnProperty("adminpass") ? | ||||||
|               ? typeof params.adminpass |               typeof params.adminpass : undefined | ||||||
|               : undefined |  | ||||||
|           }, |           }, | ||||||
|           userpass: { |           userpass: { | ||||||
|             expected: "string", |             expected: "string", | ||||||
|             got: params.hasOwnProperty("userpass") |             got: params.hasOwnProperty("userpass") ? | ||||||
|               ? typeof params.userpass |               typeof params.userpass : undefined | ||||||
|               : undefined |  | ||||||
|           }, |           }, | ||||||
|           vote: { |           vote: { | ||||||
|             expected: "boolean", |             expected: "boolean", | ||||||
| @@ -197,39 +196,33 @@ function conf_function(params, coll, guid, offline, socket) { | |||||||
|           }, |           }, | ||||||
|           addsongs: { |           addsongs: { | ||||||
|             expected: "boolean", |             expected: "boolean", | ||||||
|             got: params.hasOwnProperty("addsongs") |             got: params.hasOwnProperty("addsongs") ? | ||||||
|               ? typeof params.addsongs |               typeof params.addsongs : undefined | ||||||
|               : undefined |  | ||||||
|           }, |           }, | ||||||
|           longsongs: { |           longsongs: { | ||||||
|             expected: "boolean", |             expected: "boolean", | ||||||
|             got: params.hasOwnProperty("longsongs") |             got: params.hasOwnProperty("longsongs") ? | ||||||
|               ? typeof params.longsongs |               typeof params.longsongs : undefined | ||||||
|               : undefined |  | ||||||
|           }, |           }, | ||||||
|           frontpage: { |           frontpage: { | ||||||
|             expected: "boolean", |             expected: "boolean", | ||||||
|             got: params.hasOwnProperty("frontpage") |             got: params.hasOwnProperty("frontpage") ? | ||||||
|               ? typeof params.frontpage |               typeof params.frontpage : undefined | ||||||
|               : undefined |  | ||||||
|           }, |           }, | ||||||
|           skipping: { |           skipping: { | ||||||
|             expected: "boolean", |             expected: "boolean", | ||||||
|             got: params.hasOwnProperty("skipping") |             got: params.hasOwnProperty("skipping") ? | ||||||
|               ? typeof params.skipping |               typeof params.skipping : undefined | ||||||
|               : undefined |  | ||||||
|           }, |           }, | ||||||
|           shuffling: { |           shuffling: { | ||||||
|             expected: "boolean", |             expected: "boolean", | ||||||
|             got: params.hasOwnProperty("shuffling") |             got: params.hasOwnProperty("shuffling") ? | ||||||
|               ? typeof params.shuffling |               typeof params.shuffling : undefined | ||||||
|               : undefined |  | ||||||
|           }, |           }, | ||||||
|           userpass_changed: { |           userpass_changed: { | ||||||
|             expected: "boolean", |             expected: "boolean", | ||||||
|             got: params.hasOwnProperty("userpass_changed") |             got: params.hasOwnProperty("userpass_changed") ? | ||||||
|               ? typeof params.userpass_changed |               typeof params.userpass_changed : undefined | ||||||
|               : undefined |  | ||||||
|           } |           } | ||||||
|         }; |         }; | ||||||
|         socket.emit("update_required", result); |         socket.emit("update_required", result); | ||||||
| @@ -266,15 +259,16 @@ function conf_function(params, coll, guid, offline, socket) { | |||||||
|         hash = adminpass; |         hash = adminpass; | ||||||
|       } |       } | ||||||
|       if (userpass != "") { |       if (userpass != "") { | ||||||
|         if (!params.userpass_changed && gotten) { |         if (!params.userpass_changed && gotten) {} else { | ||||||
|         } else { |  | ||||||
|           userpass = crypto |           userpass = crypto | ||||||
|             .createHash("sha256") |             .createHash("sha256") | ||||||
|             .update(userpass) |             .update(userpass) | ||||||
|             .digest("base64"); |             .digest("base64"); | ||||||
|         } |         } | ||||||
|       } |       } | ||||||
|       db.collection(coll + "_settings").find({ id: "config" }, function( |       db.collection(coll + "_settings").find({ | ||||||
|  |         id: "config" | ||||||
|  |       }, function ( | ||||||
|         err, |         err, | ||||||
|         docs |         docs | ||||||
|       ) { |       ) { | ||||||
| @@ -326,20 +320,19 @@ function conf_function(params, coll, guid, offline, socket) { | |||||||
|           } else if (frontpage) { |           } else if (frontpage) { | ||||||
|             obj["userpass"] = ""; |             obj["userpass"] = ""; | ||||||
|           } |           } | ||||||
|           db.collection(coll + "_settings").update( |           db.collection(coll + "_settings").update({ | ||||||
|             { id: "config" }, |               id: "config" | ||||||
|             { |             }, { | ||||||
|               $set: obj |               $set: obj | ||||||
|             }, |             }, | ||||||
|             function(err, docs) { |             function (err, docs) { | ||||||
|               Functions.setSessionUserPass( |               Functions.setSessionUserPass( | ||||||
|                 Functions.getSession(socket), |                 Functions.getSession(socket), | ||||||
|                 obj["userpass"], |                 obj["userpass"], | ||||||
|                 coll, |                 coll, | ||||||
|                 function() { |                 function () { | ||||||
|                   db.collection(coll + "_settings").aggregate( |                   db.collection(coll + "_settings").aggregate( | ||||||
|                     [ |                     [{ | ||||||
|                       { |  | ||||||
|                         $match: { |                         $match: { | ||||||
|                           id: "config" |                           id: "config" | ||||||
|                         } |                         } | ||||||
| @@ -348,7 +341,7 @@ function conf_function(params, coll, guid, offline, socket) { | |||||||
|                         $project: projects.toShowConfig |                         $project: projects.toShowConfig | ||||||
|                       } |                       } | ||||||
|                     ], |                     ], | ||||||
|                     function(err, docs) { |                     function (err, docs) { | ||||||
|                       if (docs[0].adminpass !== "") docs[0].adminpass = true; |                       if (docs[0].adminpass !== "") docs[0].adminpass = true; | ||||||
|                       if ( |                       if ( | ||||||
|                         docs[0].hasOwnProperty("userpass") && |                         docs[0].hasOwnProperty("userpass") && | ||||||
| @@ -359,16 +352,17 @@ function conf_function(params, coll, guid, offline, socket) { | |||||||
|                       io.to(coll).emit("conf", docs); |                       io.to(coll).emit("conf", docs); | ||||||
|                       socket.emit("toast", "savedsettings"); |                       socket.emit("toast", "savedsettings"); | ||||||
|  |  | ||||||
|                       db.collection("frontpage_lists").update( |                       db.collection("frontpage_lists").update({ | ||||||
|                         { _id: coll }, |                           _id: coll | ||||||
|                         { |                         }, { | ||||||
|                           $set: { |                           $set: { | ||||||
|                             frontpage: frontpage, |                             frontpage: frontpage, | ||||||
|                             accessed: Functions.get_time() |                             accessed: Functions.get_time() | ||||||
|                           } |                           } | ||||||
|  |                         }, { | ||||||
|  |                           upsert: true | ||||||
|                         }, |                         }, | ||||||
|                         { upsert: true }, |                         function (err, docs) {} | ||||||
|                         function(err, docs) {} |  | ||||||
|                       ); |                       ); | ||||||
|                     } |                     } | ||||||
|                   ); |                   ); | ||||||
| @@ -393,4 +387,4 @@ function conf_function(params, coll, guid, offline, socket) { | |||||||
| } | } | ||||||
|  |  | ||||||
| module.exports.password = password; | module.exports.password = password; | ||||||
| module.exports.conf_function = conf_function; | module.exports.conf_function = conf_function; | ||||||
| @@ -8,7 +8,7 @@ function requested_change(type, string, channel) { | |||||||
|  |  | ||||||
|     let transporter = nodemailer.createTransport(mailconfig); |     let transporter = nodemailer.createTransport(mailconfig); | ||||||
|  |  | ||||||
|     transporter.verify(function(error, success) { |     transporter.verify(function (error, success) { | ||||||
|       if (error) { |       if (error) { | ||||||
|         return; |         return; | ||||||
|       } else { |       } else { | ||||||
| @@ -44,4 +44,4 @@ function requested_change(type, string, channel) { | |||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
| module.exports.requested_change = requested_change; | module.exports.requested_change = requested_change; | ||||||
| @@ -19,7 +19,10 @@ function check_if_error_or_blocked(id, channel, errored, callback) { | |||||||
|     callback(false); |     callback(false); | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   db.collection(channel).find({ id: id, now_playing: true }, function( |   db.collection(channel).find({ | ||||||
|  |     id: id, | ||||||
|  |     now_playing: true | ||||||
|  |   }, function ( | ||||||
|     err, |     err, | ||||||
|     song |     song | ||||||
|   ) { |   ) { | ||||||
| @@ -29,16 +32,14 @@ function check_if_error_or_blocked(id, channel, errored, callback) { | |||||||
|     } |     } | ||||||
|     var song_info = song[0]; |     var song_info = song[0]; | ||||||
|     if (song_info.source != "soundcloud") { |     if (song_info.source != "soundcloud") { | ||||||
|       request( |       request({ | ||||||
|         { |  | ||||||
|           type: "GET", |           type: "GET", | ||||||
|           url: |           url: "https://www.googleapis.com/youtube/v3/videos?part=id,status,contentDetails&key=" + | ||||||
|             "https://www.googleapis.com/youtube/v3/videos?part=id,status,contentDetails&key=" + |  | ||||||
|             key + |             key + | ||||||
|             "&id=" + |             "&id=" + | ||||||
|             song_info.id |             song_info.id | ||||||
|         }, |         }, | ||||||
|         function(error, response, body) { |         function (error, response, body) { | ||||||
|           try { |           try { | ||||||
|             var resp = JSON.parse(body); |             var resp = JSON.parse(body); | ||||||
|             if (resp.pageInfo.totalResults == 0) { |             if (resp.pageInfo.totalResults == 0) { | ||||||
| @@ -62,7 +63,7 @@ function check_if_error_or_blocked(id, channel, errored, callback) { | |||||||
|               ) && |               ) && | ||||||
|               resp.items[0].contentDetails.regionRestriction.blocked.length > 0 |               resp.items[0].contentDetails.regionRestriction.blocked.length > 0 | ||||||
|             ) { |             ) { | ||||||
|               var any = resp.items[0].contentDetails.blocked.some(function( |               var any = resp.items[0].contentDetails.blocked.some(function ( | ||||||
|                 element |                 element | ||||||
|               ) { |               ) { | ||||||
|                 return countryCodes.indexOf(element) > -1; |                 return countryCodes.indexOf(element) > -1; | ||||||
| @@ -81,16 +82,14 @@ function check_if_error_or_blocked(id, channel, errored, callback) { | |||||||
|         } |         } | ||||||
|       ); |       ); | ||||||
|     } else { |     } else { | ||||||
|       request( |       request({ | ||||||
|         { |  | ||||||
|           type: "GET", |           type: "GET", | ||||||
|           url: |           url: "http://api.soundcloud.com/tracks/" + | ||||||
|             "http://api.soundcloud.com/tracks/" + |  | ||||||
|             song_info.id + |             song_info.id + | ||||||
|             "?client_id=" + |             "?client_id=" + | ||||||
|             soundcloudKey |             soundcloudKey | ||||||
|         }, |         }, | ||||||
|         function(error, response, body) { |         function (error, response, body) { | ||||||
|           try { |           try { | ||||||
|             var resp = JSON.parse(body); |             var resp = JSON.parse(body); | ||||||
|             if (resp.sharing != "public" || resp.embeddable_by != "all") { |             if (resp.sharing != "public" || resp.embeddable_by != "all") { | ||||||
| @@ -116,10 +115,10 @@ function filterFunction(el) { | |||||||
| function get_genres_soundcloud(song, channel) { | function get_genres_soundcloud(song, channel) { | ||||||
|   request( |   request( | ||||||
|     "http://api.soundcloud.com/tracks/" + |     "http://api.soundcloud.com/tracks/" + | ||||||
|       song.id + |     song.id + | ||||||
|       "?client_id=" + |     "?client_id=" + | ||||||
|       soundcloudKey, |     soundcloudKey, | ||||||
|     function(err, response, body) { |     function (err, response, body) { | ||||||
|       if (err) { |       if (err) { | ||||||
|         console.log("error start", err, song, "error end"); |         console.log("error start", err, song, "error end"); | ||||||
|         return; |         return; | ||||||
| @@ -138,14 +137,14 @@ function get_genres_soundcloud(song, channel) { | |||||||
|           .concat(object.tag_list.toLowerCase().split('"')); |           .concat(object.tag_list.toLowerCase().split('"')); | ||||||
|         genre = genre.filter(filterFunction); |         genre = genre.filter(filterFunction); | ||||||
|  |  | ||||||
|         db.collection(channel).update( |         db.collection(channel).update({ | ||||||
|           { id: song.id }, |             id: song.id | ||||||
|           { |           }, { | ||||||
|             $set: { |             $set: { | ||||||
|               tags: genre |               tags: genre | ||||||
|             } |             } | ||||||
|           }, |           }, | ||||||
|           function(e, d) {} |           function (e, d) {} | ||||||
|         ); |         ); | ||||||
|       } catch (e) { |       } catch (e) { | ||||||
|         console.log("errored 2", e); |         console.log("errored 2", e); | ||||||
| @@ -203,10 +202,10 @@ function get_genres_soundcloud_recursive(arr, channel, i, callback) { | |||||||
|   var song = arr[i]; |   var song = arr[i]; | ||||||
|   request( |   request( | ||||||
|     "http://api.soundcloud.com/tracks/" + |     "http://api.soundcloud.com/tracks/" + | ||||||
|       song.id + |     song.id + | ||||||
|       "?client_id=" + |     "?client_id=" + | ||||||
|       soundcloudKey, |     soundcloudKey, | ||||||
|     function(err, response, body) { |     function (err, response, body) { | ||||||
|       if (err) { |       if (err) { | ||||||
|         console.log("error start", err, song, "error end"); |         console.log("error start", err, song, "error end"); | ||||||
|         get_genres_soundcloud_recursive(arr, channel, i + 1, callback); |         get_genres_soundcloud_recursive(arr, channel, i + 1, callback); | ||||||
| @@ -228,14 +227,14 @@ function get_genres_soundcloud_recursive(arr, channel, i, callback) { | |||||||
|           .concat(object.tag_list.toLowerCase().split('"')); |           .concat(object.tag_list.toLowerCase().split('"')); | ||||||
|         genre = genre.filter(filterFunction); |         genre = genre.filter(filterFunction); | ||||||
|  |  | ||||||
|         db.collection(channel).update( |         db.collection(channel).update({ | ||||||
|           { id: song.id }, |             id: song.id | ||||||
|           { |           }, { | ||||||
|             $set: { |             $set: { | ||||||
|               tags: genre |               tags: genre | ||||||
|             } |             } | ||||||
|           }, |           }, | ||||||
|           function(e, d) { |           function (e, d) { | ||||||
|             get_genres_soundcloud_recursive(arr, channel, i + 1, callback); |             get_genres_soundcloud_recursive(arr, channel, i + 1, callback); | ||||||
|           } |           } | ||||||
|         ); |         ); | ||||||
| @@ -258,8 +257,8 @@ function get_genres_list_recursive(list, channel, callback) { | |||||||
|       soundcloud_array.push(list[i]); |       soundcloud_array.push(list[i]); | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|   start_youtube_get(youtube_array, channel, function() { |   start_youtube_get(youtube_array, channel, function () { | ||||||
|     start_soundcloud_get(soundcloud_array, channel, function() { |     start_soundcloud_get(soundcloud_array, channel, function () { | ||||||
|       if (typeof callback == "function") callback(); |       if (typeof callback == "function") callback(); | ||||||
|     }); |     }); | ||||||
|   }); |   }); | ||||||
| @@ -281,16 +280,14 @@ function get_genres_youtube_recursive(arr, channel, i, callback) { | |||||||
|     } |     } | ||||||
|     ids.push(arr[y].id); |     ids.push(arr[y].id); | ||||||
|   } |   } | ||||||
|   request( |   request({ | ||||||
|     { |  | ||||||
|       type: "GET", |       type: "GET", | ||||||
|       url: |       url: "https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id,topicDetails&key=" + | ||||||
|         "https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id,topicDetails&key=" + |  | ||||||
|         key + |         key + | ||||||
|         "&id=" + |         "&id=" + | ||||||
|         ids.join(",") |         ids.join(",") | ||||||
|     }, |     }, | ||||||
|     function(error, response, body) { |     function (error, response, body) { | ||||||
|       if (error) { |       if (error) { | ||||||
|         get_genres_youtube_recursive(arr, channel, i + ids.length, callback); |         get_genres_youtube_recursive(arr, channel, i + ids.length, callback); | ||||||
|         return; |         return; | ||||||
| @@ -315,14 +312,14 @@ function get_genres_youtube_recursive(arr, channel, i, callback) { | |||||||
|             .split(","); |             .split(","); | ||||||
|           genre = genre.filter(filterFunction); |           genre = genre.filter(filterFunction); | ||||||
|           //console.log(resp.items[i].id + " - ", genre); |           //console.log(resp.items[i].id + " - ", genre); | ||||||
|           db.collection(channel).update( |           db.collection(channel).update({ | ||||||
|             { id: resp.items[z].id }, |               id: resp.items[z].id | ||||||
|             { |             }, { | ||||||
|               $set: { |               $set: { | ||||||
|                 tags: genre |                 tags: genre | ||||||
|               } |               } | ||||||
|             }, |             }, | ||||||
|             function(e, d) {} |             function (e, d) {} | ||||||
|           ); |           ); | ||||||
|         } |         } | ||||||
|         get_genres_youtube_recursive(arr, channel, i + ids.length, callback); |         get_genres_youtube_recursive(arr, channel, i + ids.length, callback); | ||||||
| @@ -334,16 +331,14 @@ function get_genres_youtube_recursive(arr, channel, i, callback) { | |||||||
| } | } | ||||||
|  |  | ||||||
| function get_genres_youtube(ids, channel) { | function get_genres_youtube(ids, channel) { | ||||||
|   request( |   request({ | ||||||
|     { |  | ||||||
|       type: "GET", |       type: "GET", | ||||||
|       url: |       url: "https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id,topicDetails&key=" + | ||||||
|         "https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id,topicDetails&key=" + |  | ||||||
|         key + |         key + | ||||||
|         "&id=" + |         "&id=" + | ||||||
|         ids |         ids | ||||||
|     }, |     }, | ||||||
|     function(error, response, body) { |     function (error, response, body) { | ||||||
|       if (error) { |       if (error) { | ||||||
|         return; |         return; | ||||||
|       } |       } | ||||||
| @@ -366,14 +361,14 @@ function get_genres_youtube(ids, channel) { | |||||||
|             .split(","); |             .split(","); | ||||||
|           genre = genre.filter(filterFunction); |           genre = genre.filter(filterFunction); | ||||||
|           //console.log(resp.items[i].id + " - ", genre); |           //console.log(resp.items[i].id + " - ", genre); | ||||||
|           db.collection(channel).update( |           db.collection(channel).update({ | ||||||
|             { id: resp.items[i].id }, |               id: resp.items[i].id | ||||||
|             { |             }, { | ||||||
|               $set: { |               $set: { | ||||||
|                 tags: genre |                 tags: genre | ||||||
|               } |               } | ||||||
|             }, |             }, | ||||||
|             function(e, d) {} |             function (e, d) {} | ||||||
|           ); |           ); | ||||||
|         } |         } | ||||||
|       } |       } | ||||||
| @@ -383,16 +378,14 @@ function get_genres_youtube(ids, channel) { | |||||||
|  |  | ||||||
| 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,''); | ||||||
|   request( |   request({ | ||||||
|     { |  | ||||||
|       type: "GET", |       type: "GET", | ||||||
|       url: |       url: "https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id,topicDetails&key=" + | ||||||
|         "https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id,topicDetails&key=" + |  | ||||||
|         key + |         key + | ||||||
|         "&id=" + |         "&id=" + | ||||||
|         song_generated.id |         song_generated.id | ||||||
|     }, |     }, | ||||||
|     function(error, response, body) { |     function (error, response, body) { | ||||||
|       try { |       try { | ||||||
|         var resp = JSON.parse(body); |         var resp = JSON.parse(body); | ||||||
|         if (resp.items.length == 1) { |         if (resp.items.length == 1) { | ||||||
| @@ -424,9 +417,9 @@ function get_correct_info(song_generated, channel, broadcast, callback) { | |||||||
|               song_generated.start = 0; |               song_generated.start = 0; | ||||||
|               song_generated.end = duration; |               song_generated.end = duration; | ||||||
|             } |             } | ||||||
|             db.collection(channel).update( |             db.collection(channel).update({ | ||||||
|               { id: song_generated.id }, |                 id: song_generated.id | ||||||
|               { |               }, { | ||||||
|                 $set: { |                 $set: { | ||||||
|                   duration: song_generated.duration, |                   duration: song_generated.duration, | ||||||
|                   start: song_generated.start, |                   start: song_generated.start, | ||||||
| @@ -435,7 +428,7 @@ function get_correct_info(song_generated, channel, broadcast, callback) { | |||||||
|                   tags: genre |                   tags: genre | ||||||
|                 } |                 } | ||||||
|               }, |               }, | ||||||
|               function(err, docs) { |               function (err, docs) { | ||||||
|                 if (broadcast && docs.nModified == 1) { |                 if (broadcast && docs.nModified == 1) { | ||||||
|                   song_generated.new_id = song_generated.id; |                   song_generated.new_id = song_generated.id; | ||||||
|                   //if(song_generated.type == "video") |                   //if(song_generated.type == "video") | ||||||
| @@ -455,14 +448,14 @@ function get_correct_info(song_generated, channel, broadcast, callback) { | |||||||
|               } |               } | ||||||
|             ); |             ); | ||||||
|           } else { |           } else { | ||||||
|             db.collection(channel).update( |             db.collection(channel).update({ | ||||||
|               { id: song_generated.id }, |                 id: song_generated.id | ||||||
|               { |               }, { | ||||||
|                 $set: { |                 $set: { | ||||||
|                   tags: genre |                   tags: genre | ||||||
|                 } |                 } | ||||||
|               }, |               }, | ||||||
|               function(e, d) { |               function (e, d) { | ||||||
|                 if (typeof callback == "function") { |                 if (typeof callback == "function") { | ||||||
|                   callback(song_generated, true); |                   callback(song_generated, true); | ||||||
|                 } |                 } | ||||||
| @@ -502,16 +495,14 @@ function check_error_video(msg, channel) { | |||||||
|   } |   } | ||||||
|   if (msg.source == "soundcloud") return; |   if (msg.source == "soundcloud") return; | ||||||
|   //channel = channel.replace(/ /g,''); |   //channel = channel.replace(/ /g,''); | ||||||
|   request( |   request({ | ||||||
|     { |  | ||||||
|       type: "GET", |       type: "GET", | ||||||
|       url: |       url: "https://www.googleapis.com/youtube/v3/videos?part=id&key=" + | ||||||
|         "https://www.googleapis.com/youtube/v3/videos?part=id&key=" + |  | ||||||
|         key + |         key + | ||||||
|         "&id=" + |         "&id=" + | ||||||
|         msg.id |         msg.id | ||||||
|     }, |     }, | ||||||
|     function(error, response, body) { |     function (error, response, body) { | ||||||
|       try { |       try { | ||||||
|         var resp = JSON.parse(body); |         var resp = JSON.parse(body); | ||||||
|         if (resp.pageInfo.totalResults == 0) { |         if (resp.pageInfo.totalResults == 0) { | ||||||
| @@ -531,12 +522,11 @@ function findSimilar(msg, channel, broadcast, callback) { | |||||||
|     key + |     key + | ||||||
|     "&videoEmbeddable=true&part=id&type=video&order=viewCount&safeSearch=none&maxResults=5&q=" + |     "&videoEmbeddable=true&part=id&type=video&order=viewCount&safeSearch=none&maxResults=5&q=" + | ||||||
|     encodeURIComponent(msg.title); |     encodeURIComponent(msg.title); | ||||||
|   request( |   request({ | ||||||
|     { |  | ||||||
|       method: "GET", |       method: "GET", | ||||||
|       url: yt_url |       url: yt_url | ||||||
|     }, |     }, | ||||||
|     function(error, response, body) { |     function (error, response, body) { | ||||||
|       var resp = JSON.parse(body); |       var resp = JSON.parse(body); | ||||||
|       if (resp.items.length > 0) { |       if (resp.items.length > 0) { | ||||||
|         var vid_url = |         var vid_url = | ||||||
| @@ -546,12 +536,11 @@ function findSimilar(msg, channel, broadcast, callback) { | |||||||
|         for (var i = 0; i < resp.items.length; i++) { |         for (var i = 0; i < resp.items.length; i++) { | ||||||
|           vid_url += resp.items[i].id.videoId + ","; |           vid_url += resp.items[i].id.videoId + ","; | ||||||
|         } |         } | ||||||
|         request( |         request({ | ||||||
|           { |  | ||||||
|             type: "GET", |             type: "GET", | ||||||
|             url: vid_url |             url: vid_url | ||||||
|           }, |           }, | ||||||
|           function(error, response, body) { |           function (error, response, body) { | ||||||
|             var resp = JSON.parse(body); |             var resp = JSON.parse(body); | ||||||
|             var found = false; |             var found = false; | ||||||
|             var element = {}; |             var element = {}; | ||||||
| @@ -576,12 +565,12 @@ function findSimilar(msg, channel, broadcast, callback) { | |||||||
|               } |               } | ||||||
|             } |             } | ||||||
|             if (found) { |             if (found) { | ||||||
|               db.collection(channel).update( |               db.collection(channel).update({ | ||||||
|                 { id: msg.id }, |                   id: msg.id | ||||||
|                 { |                 }, { | ||||||
|                   $set: element |                   $set: element | ||||||
|                 }, |                 }, | ||||||
|                 function(err, docs) { |                 function (err, docs) { | ||||||
|                   if ( |                   if ( | ||||||
|                     docs && |                     docs && | ||||||
|                     docs.hasOwnProperty("nModified") && |                     docs.hasOwnProperty("nModified") && | ||||||
| @@ -671,4 +660,4 @@ module.exports.get_genres_soundcloud = get_genres_soundcloud; | |||||||
| module.exports.get_genres_youtube = get_genres_youtube; | module.exports.get_genres_youtube = get_genres_youtube; | ||||||
| module.exports.get_genres_list = get_genres_list; | module.exports.get_genres_list = get_genres_list; | ||||||
| module.exports.check_error_video = check_error_video; | module.exports.check_error_video = check_error_video; | ||||||
| module.exports.get_correct_info = get_correct_info; | module.exports.get_correct_info = get_correct_info; | ||||||
| @@ -22,22 +22,22 @@ function thumbnail(msg, coll, guid, offline, socket) { | |||||||
|         }, |         }, | ||||||
|         thumbnail: { |         thumbnail: { | ||||||
|           expected: "string", |           expected: "string", | ||||||
|           got: msg.hasOwnProperty("thumbnail") |           got: msg.hasOwnProperty("thumbnail") ? | ||||||
|             ? typeof msg.thumbnail |             typeof msg.thumbnail : | ||||||
|             : undefined |             undefined | ||||||
|         }, |         }, | ||||||
|         adminpass: { |         adminpass: { | ||||||
|           expected: "string", |           expected: "string", | ||||||
|           got: msg.hasOwnProperty("adminpass") |           got: msg.hasOwnProperty("adminpass") ? | ||||||
|             ? typeof msg.adminpass |             typeof msg.adminpass : | ||||||
|             : undefined |             undefined | ||||||
|         } |         } | ||||||
|       }; |       }; | ||||||
|       socket.emit("update_required", result); |       socket.emit("update_required", result); | ||||||
|       return; |       return; | ||||||
|     } |     } | ||||||
|     //coll = coll.replace(/ /g,''); |     //coll = coll.replace(/ /g,''); | ||||||
|     Functions.getSessionAdminUser(Functions.getSession(socket), coll, function( |     Functions.getSessionAdminUser(Functions.getSession(socket), coll, function ( | ||||||
|       userpass, |       userpass, | ||||||
|       adminpass |       adminpass | ||||||
|     ) { |     ) { | ||||||
| @@ -63,7 +63,9 @@ function thumbnail(msg, coll, guid, offline, socket) { | |||||||
|       } |       } | ||||||
|       var channel = msg.channel.toLowerCase(); |       var channel = msg.channel.toLowerCase(); | ||||||
|       var hash = msg.adminpass; |       var hash = msg.adminpass; | ||||||
|       db.collection(channel + "_settings").find({ id: "config" }, function( |       db.collection(channel + "_settings").find({ | ||||||
|  |         id: "config" | ||||||
|  |       }, function ( | ||||||
|         err, |         err, | ||||||
|         docs |         docs | ||||||
|       ) { |       ) { | ||||||
| @@ -79,11 +81,16 @@ function thumbnail(msg, coll, guid, offline, socket) { | |||||||
|             docs[0].adminpass !== "" && |             docs[0].adminpass !== "" && | ||||||
|             docs[0].adminpass == hash |             docs[0].adminpass == hash | ||||||
|           ) { |           ) { | ||||||
|             db.collection("suggested_thumbnails").update( |             db.collection("suggested_thumbnails").update({ | ||||||
|               { channel: channel }, |                 channel: channel | ||||||
|               { $set: { thumbnail: msg.thumbnail } }, |               }, { | ||||||
|               { upsert: true }, |                 $set: { | ||||||
|               function(err, docs) { |                   thumbnail: msg.thumbnail | ||||||
|  |                 } | ||||||
|  |               }, { | ||||||
|  |                 upsert: true | ||||||
|  |               }, | ||||||
|  |               function (err, docs) { | ||||||
|                 Notifications.requested_change( |                 Notifications.requested_change( | ||||||
|                   "thumbnail", |                   "thumbnail", | ||||||
|                   msg.thumbnail, |                   msg.thumbnail, | ||||||
| @@ -117,22 +124,22 @@ function description(msg, coll, guid, offline, socket) { | |||||||
|         }, |         }, | ||||||
|         description: { |         description: { | ||||||
|           expected: "string", |           expected: "string", | ||||||
|           got: msg.hasOwnProperty("description") |           got: msg.hasOwnProperty("description") ? | ||||||
|             ? typeof msg.description |             typeof msg.description : | ||||||
|             : undefined |             undefined | ||||||
|         }, |         }, | ||||||
|         adminpass: { |         adminpass: { | ||||||
|           expected: "string", |           expected: "string", | ||||||
|           got: msg.hasOwnProperty("adminpass") |           got: msg.hasOwnProperty("adminpass") ? | ||||||
|             ? typeof msg.adminpass |             typeof msg.adminpass : | ||||||
|             : undefined |             undefined | ||||||
|         } |         } | ||||||
|       }; |       }; | ||||||
|       socket.emit("update_required", result); |       socket.emit("update_required", result); | ||||||
|       return; |       return; | ||||||
|     } |     } | ||||||
|     //coll = coll.replace(/ /g,''); |     //coll = coll.replace(/ /g,''); | ||||||
|     Functions.getSessionAdminUser(Functions.getSession(socket), coll, function( |     Functions.getSessionAdminUser(Functions.getSession(socket), coll, function ( | ||||||
|       userpass, |       userpass, | ||||||
|       adminpass, |       adminpass, | ||||||
|       gotten |       gotten | ||||||
| @@ -154,7 +161,9 @@ function description(msg, coll, guid, offline, socket) { | |||||||
|       } |       } | ||||||
|       var channel = msg.channel.toLowerCase(); |       var channel = msg.channel.toLowerCase(); | ||||||
|       var hash = msg.adminpass; |       var hash = msg.adminpass; | ||||||
|       db.collection(channel + "_settings").find({ id: "config" }, function( |       db.collection(channel + "_settings").find({ | ||||||
|  |         id: "config" | ||||||
|  |       }, function ( | ||||||
|         err, |         err, | ||||||
|         docs |         docs | ||||||
|       ) { |       ) { | ||||||
| @@ -170,11 +179,16 @@ function description(msg, coll, guid, offline, socket) { | |||||||
|             docs[0].adminpass !== "" && |             docs[0].adminpass !== "" && | ||||||
|             docs[0].adminpass == hash |             docs[0].adminpass == hash | ||||||
|           ) { |           ) { | ||||||
|             db.collection("suggested_descriptions").update( |             db.collection("suggested_descriptions").update({ | ||||||
|               { channel: channel }, |                 channel: channel | ||||||
|               { $set: { description: msg.description } }, |               }, { | ||||||
|               { upsert: true }, |                 $set: { | ||||||
|               function(err, docs) { |                   description: msg.description | ||||||
|  |                 } | ||||||
|  |               }, { | ||||||
|  |                 upsert: true | ||||||
|  |               }, | ||||||
|  |               function (err, docs) { | ||||||
|                 Notifications.requested_change( |                 Notifications.requested_change( | ||||||
|                   "description", |                   "description", | ||||||
|                   msg.description, |                   msg.description, | ||||||
| @@ -212,16 +226,16 @@ function rules(msg, coll, guid, offline, socket) { | |||||||
|         }, |         }, | ||||||
|         adminpass: { |         adminpass: { | ||||||
|           expected: "string", |           expected: "string", | ||||||
|           got: msg.hasOwnProperty("adminpass") |           got: msg.hasOwnProperty("adminpass") ? | ||||||
|             ? typeof msg.adminpass |             typeof msg.adminpass : | ||||||
|             : undefined |             undefined | ||||||
|         } |         } | ||||||
|       }; |       }; | ||||||
|       socket.emit("update_required", result); |       socket.emit("update_required", result); | ||||||
|       return; |       return; | ||||||
|     } |     } | ||||||
|     //coll = coll.replace(/ /g,''); |     //coll = coll.replace(/ /g,''); | ||||||
|     Functions.getSessionAdminUser(Functions.getSession(socket), coll, function( |     Functions.getSessionAdminUser(Functions.getSession(socket), coll, function ( | ||||||
|       userpass, |       userpass, | ||||||
|       adminpass, |       adminpass, | ||||||
|       gotten |       gotten | ||||||
| @@ -243,7 +257,9 @@ function rules(msg, coll, guid, offline, socket) { | |||||||
|       } |       } | ||||||
|       var channel = msg.channel.toLowerCase(); |       var channel = msg.channel.toLowerCase(); | ||||||
|       var hash = msg.adminpass; |       var hash = msg.adminpass; | ||||||
|       db.collection(channel + "_settings").find({ id: "config" }, function( |       db.collection(channel + "_settings").find({ | ||||||
|  |         id: "config" | ||||||
|  |       }, function ( | ||||||
|         err, |         err, | ||||||
|         docs |         docs | ||||||
|       ) { |       ) { | ||||||
| @@ -259,11 +275,16 @@ function rules(msg, coll, guid, offline, socket) { | |||||||
|             docs[0].adminpass !== "" && |             docs[0].adminpass !== "" && | ||||||
|             docs[0].adminpass == hash |             docs[0].adminpass == hash | ||||||
|           ) { |           ) { | ||||||
|             db.collection("suggested_rules").update( |             db.collection("suggested_rules").update({ | ||||||
|               { channel: channel }, |                 channel: channel | ||||||
|               { $set: { rules: msg.rules } }, |               }, { | ||||||
|               { upsert: true }, |                 $set: { | ||||||
|               function(err, docs) { |                   rules: msg.rules | ||||||
|  |                 } | ||||||
|  |               }, { | ||||||
|  |                 upsert: true | ||||||
|  |               }, | ||||||
|  |               function (err, docs) { | ||||||
|                 Notifications.requested_change("rules", msg.rules, channel); |                 Notifications.requested_change("rules", msg.rules, channel); | ||||||
|                 socket.emit("toast", "suggested_rules"); |                 socket.emit("toast", "suggested_rules"); | ||||||
|               } |               } | ||||||
| @@ -281,4 +302,4 @@ function rules(msg, coll, guid, offline, socket) { | |||||||
|  |  | ||||||
| module.exports.thumbnail = thumbnail; | module.exports.thumbnail = thumbnail; | ||||||
| module.exports.description = description; | module.exports.description = description; | ||||||
| module.exports.rules = rules; | module.exports.rules = rules; | ||||||
		Reference in New Issue
	
	Block a user