mirror of
				https://github.com/KevinMidboe/zoff.git
				synced 2025-10-29 18:00:23 +00:00 
			
		
		
		
	Merge pull request #466 from zoff-music/feature/strict-skip-api
Feature/strict skip api
This commit is contained in:
		
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @@ -6,6 +6,7 @@ server/config/cert_config.js | |||||||
| server/config/recaptcha.js | server/config/recaptcha.js | ||||||
| server/config/analytics.js | server/config/analytics.js | ||||||
| server/config/google.js | server/config/google.js | ||||||
|  | server/config/allowed_api.js | ||||||
| server/public/assets/dist/maps/ | server/public/assets/dist/maps/ | ||||||
| server/public/assets/dist/callback.min.js | server/public/assets/dist/callback.min.js | ||||||
| server/public/assets/dist/token.min.js | server/public/assets/dist/token.min.js | ||||||
|   | |||||||
| @@ -87,9 +87,10 @@ app.socketIO = io; | |||||||
|  |  | ||||||
|  |  | ||||||
| /* Globally needed "libraries" and files */ | /* Globally needed "libraries" and files */ | ||||||
| var Functions = require(pathThumbnails + '/handlers/functions.js'); |  | ||||||
| var router = require(pathThumbnails + '/routing/client/router.js'); | var router = require(pathThumbnails + '/routing/client/router.js'); | ||||||
| var api = require(pathThumbnails + '/routing/client/api.js'); | var api_file = require(pathThumbnails + '/routing/client/api.js'); | ||||||
|  | var api = api_file.router; | ||||||
|  | api_file.sIO = app.socketIO; | ||||||
| var ico_router = require(pathThumbnails + '/routing/client/icons_routing.js'); | var ico_router = require(pathThumbnails + '/routing/client/icons_routing.js'); | ||||||
|  |  | ||||||
| app.get('/robots.txt', function (req, res) { | app.get('/robots.txt', function (req, res) { | ||||||
|   | |||||||
							
								
								
									
										3
									
								
								server/config/allowed_api.example.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								server/config/allowed_api.example.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,3 @@ | |||||||
|  | var key = [""]; | ||||||
|  |  | ||||||
|  | module.exports = key; | ||||||
| @@ -11,6 +11,8 @@ var toShowConfig = { | |||||||
|     "userpass": 1, |     "userpass": 1, | ||||||
|     "vote": 1, |     "vote": 1, | ||||||
|     "toggleChat": { $ifNull: [ "$toggleChat", true ] }, |     "toggleChat": { $ifNull: [ "$toggleChat", true ] }, | ||||||
|  |     "strictSkip": { $ifNull: [ "$strictSkip", false ] }, | ||||||
|  |     "strictSkipNumber": { $ifNull: [ "$strictSkipNumber", 10 ] }, | ||||||
|     "description": { $ifNull: [ "$description", "" ] }, |     "description": { $ifNull: [ "$description", "" ] }, | ||||||
|     "thumbnail": { $ifNull: [ "$thumbnail", "" ] }, |     "thumbnail": { $ifNull: [ "$thumbnail", "" ] }, | ||||||
|     "rules": { $ifNull: [ "$rules", "" ] }, |     "rules": { $ifNull: [ "$rules", "" ] }, | ||||||
|   | |||||||
| @@ -438,7 +438,7 @@ function left_channel(coll, guid, short_id, in_list, socket, change, caller) { | |||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| function checkTimeout(type, timeout, channel, guid, conf_pass, this_pass, socket, callback, error_message){ | function checkTimeout(type, timeout, channel, guid, conf_pass, this_pass, socket, callback, error_message, error_callback){ | ||||||
|     if(conf_pass != "" && conf_pass == this_pass) { |     if(conf_pass != "" && conf_pass == this_pass) { | ||||||
|         callback(); |         callback(); | ||||||
|         return; |         return; | ||||||
| @@ -454,7 +454,9 @@ function checkTimeout(type, timeout, channel, guid, conf_pass, this_pass, socket | |||||||
|  |  | ||||||
|             var retry_in = (date.getTime() - now.getTime()) / 1000; |             var retry_in = (date.getTime() - now.getTime()) / 1000; | ||||||
|             if(retry_in > 0) { |             if(retry_in > 0) { | ||||||
|                 if(error_message) { |                 if(typeof(error_callback) == "function") { | ||||||
|  |                     error_callback(); | ||||||
|  |                 } else if(error_message) { | ||||||
|                     var sOrNot = Math.ceil(retry_in) > 1 || Math.ceil(retry_in) == 0 ? "s" : ""; |                     var sOrNot = Math.ceil(retry_in) > 1 || Math.ceil(retry_in) == 0 ? "s" : ""; | ||||||
|                     socket.emit("toast", error_message + Math.ceil(retry_in) + " second" + sOrNot + "."); |                     socket.emit("toast", error_message + Math.ceil(retry_in) + " second" + sOrNot + "."); | ||||||
|                 } else { |                 } else { | ||||||
|   | |||||||
| @@ -123,7 +123,7 @@ function list(msg, guid, coll, offline, socket) { | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| function skip(list, guid, coll, offline, socket) { | function skip(list, guid, coll, offline, socket, callback) { | ||||||
|     var socketid = socket.zoff_id; |     var socketid = socket.zoff_id; | ||||||
|  |  | ||||||
|     if(list !== undefined && list !== null && list !== "") |     if(list !== undefined && list !== null && list !== "") | ||||||
| @@ -198,15 +198,20 @@ function skip(list, guid, coll, offline, socket) { | |||||||
|  |  | ||||||
|                     hash = adminpass; |                     hash = adminpass; | ||||||
|                     //db.collection(coll + "_settings").find(function(err, docs){ |                     //db.collection(coll + "_settings").find(function(err, docs){ | ||||||
|  |                     var strictSkip = false; | ||||||
|  |                     var strictSkipNumber = 10; | ||||||
|  |                     if(docs[0].strictSkip) strictSkip = docs[0].strictSkip; | ||||||
|  |                     if(docs[0].strictSkipNumber) strictSkipNumber = docs[0].strictSkipNumber; | ||||||
|                     if(docs !== null && docs.length !== 0) |                     if(docs !== null && docs.length !== 0) | ||||||
|                     { |                     { | ||||||
|                         if(!docs[0].skip || (docs[0].adminpass == hash && docs[0].adminpass !== "") || error) |                         if(!docs[0].skip || (docs[0].adminpass == hash && docs[0].adminpass !== "") || error) | ||||||
|                         { |                         { | ||||||
|                             db.collection("frontpage_lists").find({"_id": coll}, function(err, frontpage_viewers){ |                             db.collection("frontpage_lists").find({"_id": coll}, function(err, frontpage_viewers){ | ||||||
|                                 if((frontpage_viewers[0].viewers/2 <= docs[0].skips.length+1 && !Functions.contains(docs[0].skips, guid) && frontpage_viewers[0].viewers != 2) || |                                 if( | ||||||
|  |                                     (strictSkip && ((docs[0].adminpass == hash && docs[0].adminpass !== "") || (docs[0].skips.length+1 >= strictSkipNumber))) || | ||||||
|  |                                     (!strictSkip && ((frontpage_viewers[0].viewers/2 <= docs[0].skips.length+1 && !Functions.contains(docs[0].skips, guid) && frontpage_viewers[0].viewers != 2) || | ||||||
|                                         (frontpage_viewers[0].viewers == 2 && docs[0].skips.length+1 == 2 && !Functions.contains(docs[0].skips, guid)) || |                                         (frontpage_viewers[0].viewers == 2 && docs[0].skips.length+1 == 2 && !Functions.contains(docs[0].skips, guid)) || | ||||||
|                                 (docs[0].adminpass == hash && docs[0].adminpass !== "" && docs[0].skip)) |                                         (docs[0].adminpass == hash && docs[0].adminpass !== "" && docs[0].skip)))) | ||||||
|                                 { |                                 { | ||||||
|                                     Functions.checkTimeout("skip", 1, coll, coll, error, true, socket, function() { |                                     Functions.checkTimeout("skip", 1, coll, coll, error, true, socket, function() { | ||||||
|                                         change_song(coll, error, video_id, docs); |                                         change_song(coll, error, video_id, docs); | ||||||
| @@ -223,14 +228,27 @@ function skip(list, guid, coll, offline, socket) { | |||||||
|                                             } |                                             } | ||||||
|                                         }); |                                         }); | ||||||
|                                     }, "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({ id: "config" }, {$push:{skips:guid}}, function(err, d){ |                                     db.collection(coll + "_settings").update({ id: "config" }, {$push:{skips:guid}}, function(err, d){ | ||||||
|                                         if(frontpage_viewers[0].viewers == 2) |                                         if(frontpage_viewers[0].viewers == 2 && !strictSkip) { | ||||||
|                                             to_skip = 1; |                                             to_skip = 1; | ||||||
|                                         else |                                         } else if(strictSkip) { | ||||||
|  |                                             to_skip = (strictSkipNumber) - docs[0].skips.length-1; | ||||||
|  |                                         } else { | ||||||
|                                             to_skip = (Math.ceil(frontpage_viewers[0].viewers/2) - docs[0].skips.length-1); |                                             to_skip = (Math.ceil(frontpage_viewers[0].viewers/2) - docs[0].skips.length-1); | ||||||
|  |                                         } | ||||||
|                                         socket.emit("toast", to_skip + " more are needed to skip!"); |                                         socket.emit("toast", to_skip + " more are needed to skip!"); | ||||||
|                                         socket.to(coll).emit('chat', {from: name, msg: " voted to skip"}); |                                         db.collection("user_names").find({"guid": guid}, function(err, docs) { | ||||||
|  |                                             if(docs.length == 1) { | ||||||
|  |                                                 db.collection("registered_users").find({"_id": docs[0].name}, function(err, n) { | ||||||
|  |                                                     var icon = false; | ||||||
|  |                                                     if(n.length > 0 && n[0].icon) { | ||||||
|  |                                                         icon = n[0].icon; | ||||||
|  |                                                     } | ||||||
|  |                                                     socket.to(coll).emit('chat', {from: docs[0].name, msg: " voted to skip"}); | ||||||
|  |                                                 }) | ||||||
|  |                                             } | ||||||
|  |                                         }); | ||||||
|                                     }); |                                     }); | ||||||
|                                 }else{ |                                 }else{ | ||||||
|                                     socket.emit("toast", "alreadyskip"); |                                     socket.emit("toast", "alreadyskip"); | ||||||
|   | |||||||
| @@ -222,6 +222,14 @@ function conf_function(params, coll, guid, offline, socket) { | |||||||
|                     if(params.hasOwnProperty("toggleChat") && docs[0].adminpass != "" && docs[0].adminpass != undefined && docs[0].adminpass == hash) { |                     if(params.hasOwnProperty("toggleChat") && docs[0].adminpass != "" && docs[0].adminpass != undefined && docs[0].adminpass == hash) { | ||||||
|                         obj.toggleChat = params.toggleChat; |                         obj.toggleChat = params.toggleChat; | ||||||
|                     } |                     } | ||||||
|  |                     if(params.hasOwnProperty("strictSkip") && docs[0].adminpass != "" && docs[0].adminpass != undefined && docs[0].adminpass == hash) { | ||||||
|  |                         obj.strictSkip = params.strictSkip; | ||||||
|  |                     } | ||||||
|  |                     if(params.hasOwnProperty("strictSkipNumber") && docs[0].adminpass != "" && docs[0].adminpass != undefined && docs[0].adminpass == hash) { | ||||||
|  |                         try { | ||||||
|  |                             obj.strictSkipNumber = parseInt(params.strictSkipNumber); | ||||||
|  |                         } catch(e) {} | ||||||
|  |                     } | ||||||
|                     if(params.userpass_changed) { |                     if(params.userpass_changed) { | ||||||
|                         obj["userpass"] = userpass; |                         obj["userpass"] = userpass; | ||||||
|                     } else if (frontpage) { |                     } else if (frontpage) { | ||||||
|   | |||||||
| @@ -824,12 +824,20 @@ input[type=text]:focus:not([readonly]) + label, input[type=password]:focus:not([ | |||||||
|     width: 100%; |     width: 100%; | ||||||
| } | } | ||||||
|  |  | ||||||
| #password{ | #password, #strict-input-number{ | ||||||
|     width: 84%; |     width: 84%; | ||||||
|     margin-left: 30px; |     margin-left: 30px; | ||||||
|     margin-bottom: 0; |     margin-bottom: 0; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | #strict-input-number { | ||||||
|  |     border-bottom: transparent; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .strict-skip-info { | ||||||
|  |     width: 1000px; | ||||||
|  | } | ||||||
|  |  | ||||||
| span.badge.new, | span.badge.new, | ||||||
| .progress .determinate, | .progress .determinate, | ||||||
| .progress .indeterminate, | .progress .indeterminate, | ||||||
| @@ -2412,7 +2420,7 @@ nav ul li:hover, nav ul li.active { | |||||||
|     color: lightgrey; |     color: lightgrey; | ||||||
| } | } | ||||||
|  |  | ||||||
| #admin-lock | #admin-lock, #strict-skip-lock | ||||||
| { | { | ||||||
|     position:absolute; |     position:absolute; | ||||||
|     display: flex; |     display: flex; | ||||||
|   | |||||||
| @@ -3,6 +3,11 @@ var Admin = { | |||||||
|     beginning:true, |     beginning:true, | ||||||
|     logged_in: false, |     logged_in: false, | ||||||
|  |  | ||||||
|  |     update_strict_skip: function(value) { | ||||||
|  |         var form = document.getElementById("adminSettingsForm"); | ||||||
|  |         form.strictSkipNumber = value; | ||||||
|  |         Admin.submitAdmin(form, false); | ||||||
|  |     }, | ||||||
|  |  | ||||||
|     pw: function(msg) { |     pw: function(msg) { | ||||||
|         Admin.logged_in = msg; |         Admin.logged_in = msg; | ||||||
| @@ -16,12 +21,16 @@ var Admin = { | |||||||
|             if(Helper.html(".suggested-badge") != "0" && Helper.html(".suggested-badge") != "") { |             if(Helper.html(".suggested-badge") != "0" && Helper.html(".suggested-badge") != "") { | ||||||
|                 Helper.removeClass(".suggested-badge", "hide"); |                 Helper.removeClass(".suggested-badge", "hide"); | ||||||
|             } |             } | ||||||
|  |             if(conf != undefined && conf.strictSkip) { | ||||||
|  |                 Helper.removeClass(".strict-skip-input", "hide"); | ||||||
|  |             } | ||||||
|         } else { |         } else { | ||||||
|             Admin.hideUserSuggested(); |             Admin.hideUserSuggested(); | ||||||
|  |             Helper.addClass(".strict-skip-input", "hide"); | ||||||
|         } |         } | ||||||
|         Helper.removeClass(".delete-context-menu", "context-menu-disabled"); |         Helper.removeClass(".delete-context-menu", "context-menu-disabled"); | ||||||
|         names     = ["vote","addsongs","longsongs","frontpage", "allvideos", |         names     = ["vote","addsongs","longsongs","frontpage", "allvideos", | ||||||
|         "removeplay", "skip", "shuffle", "userpass", "toggleChat"]; |         "removeplay", "skip", "shuffle", "userpass", "toggleChat", "strictSkip"]; | ||||||
|         //Crypt.set_pass(chan.toLowerCase(), Crypt.tmp_pass); |         //Crypt.set_pass(chan.toLowerCase(), Crypt.tmp_pass); | ||||||
|  |  | ||||||
|         for (var i = 0; i < names.length; i++) { |         for (var i = 0; i < names.length; i++) { | ||||||
| @@ -105,7 +114,7 @@ var Admin = { | |||||||
|         w_p       = true; |         w_p       = true; | ||||||
|         adminpass = ""; |         adminpass = ""; | ||||||
|         names     = ["vote","addsongs","longsongs","frontpage", "allvideos", |         names     = ["vote","addsongs","longsongs","frontpage", "allvideos", | ||||||
|         "removeplay", "skip", "shuffle", "toggleChat"]; |         "removeplay", "skip", "shuffle", "toggleChat", "strictSkip"]; | ||||||
|         document.getElementById("password").value = ""; |         document.getElementById("password").value = ""; | ||||||
|         Helper.addClass(".info_change_li", "hide"); |         Helper.addClass(".info_change_li", "hide"); | ||||||
|         for (i = 0; i < names.length; i++) { |         for (i = 0; i < names.length; i++) { | ||||||
| @@ -120,7 +129,7 @@ var Admin = { | |||||||
|             document.getElementById("admin-lock").innerHTML = "lock"; |             document.getElementById("admin-lock").innerHTML = "lock"; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |         Helper.addClass(".strict-skip-input", "hide"); | ||||||
|         Helper.addClass(".user-password-li", "hide"); |         Helper.addClass(".user-password-li", "hide"); | ||||||
|         Helper.addClass(".chat-toggle-li", "hide"); |         Helper.addClass(".chat-toggle-li", "hide"); | ||||||
|         Helper.addClass(".delete-all", "hide"); |         Helper.addClass(".delete-all", "hide"); | ||||||
| @@ -138,7 +147,7 @@ var Admin = { | |||||||
|     }, |     }, | ||||||
|  |  | ||||||
|     save: function(userpass) { |     save: function(userpass) { | ||||||
|         Admin.submitAdmin(document.getElementById("adminForm").elements, userpass); |         Admin.submitAdmin(document.getElementById("adminSettingsForm").elements, userpass); | ||||||
|     }, |     }, | ||||||
|  |  | ||||||
|     set_conf: function(conf_array) { |     set_conf: function(conf_array) { | ||||||
| @@ -146,7 +155,7 @@ var Admin = { | |||||||
|         music     = conf_array.allvideos; |         music     = conf_array.allvideos; | ||||||
|         longsongs = conf_array.longsongs; |         longsongs = conf_array.longsongs; | ||||||
|         names     = ["vote","addsongs","longsongs","frontpage", "allvideos", |         names     = ["vote","addsongs","longsongs","frontpage", "allvideos", | ||||||
|         "removeplay", "skip", "shuffle", "userpass", "toggleChat"]; |         "removeplay", "skip", "shuffle", "userpass", "toggleChat", "strictSkip"]; | ||||||
|         if(!conf.hasOwnProperty("toggleChat")) conf.toggleChat = true; |         if(!conf.hasOwnProperty("toggleChat")) conf.toggleChat = true; | ||||||
|         toggleChat = conf.toggleChat; |         toggleChat = conf.toggleChat; | ||||||
|         hasadmin = conf_array.adminpass != ""; |         hasadmin = conf_array.adminpass != ""; | ||||||
| @@ -163,6 +172,7 @@ var Admin = { | |||||||
|                 document.getElementsByName(names[i])[0].removeAttribute("disabled"); |                 document.getElementsByName(names[i])[0].removeAttribute("disabled"); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |         document.getElementById("strict-input-number").value = conf.strictSkipNumber; | ||||||
|         if((hasadmin) && !Admin.logged_in) { |         if((hasadmin) && !Admin.logged_in) { | ||||||
|             if(Helper.html("#admin-lock") != "lock") Admin.display_logged_out(); |             if(Helper.html("#admin-lock") != "lock") Admin.display_logged_out(); | ||||||
|         } else if(!hasadmin) { |         } else if(!hasadmin) { | ||||||
| @@ -172,7 +182,14 @@ var Admin = { | |||||||
|                 Helper.removeClass(".change_user_pass", "hide"); |                 Helper.removeClass(".change_user_pass", "hide"); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |         if(Admin.logged_in) { | ||||||
|  |             if(conf != undefined && conf.strictSkip) { | ||||||
|  |                 Helper.removeClass(".strict-skip-input", "hide"); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         if(conf != undefined && !conf.strictSkip) { | ||||||
|  |             Helper.addClass(".strict-skip-input", "hide"); | ||||||
|  |         } | ||||||
|         if(!document.getElementsByClassName("password_protected")[0].checked) { |         if(!document.getElementsByClassName("password_protected")[0].checked) { | ||||||
|             Helper.addClass(".change_user_pass", "hide"); |             Helper.addClass(".change_user_pass", "hide"); | ||||||
|             //Crypt.remove_userpass(chan.toLowerCase()); |             //Crypt.remove_userpass(chan.toLowerCase()); | ||||||
| @@ -217,6 +234,13 @@ var Admin = { | |||||||
|         skipping   = form.skip.checked; |         skipping   = form.skip.checked; | ||||||
|         shuffling  = form.shuffle.checked; |         shuffling  = form.shuffle.checked; | ||||||
|         toggleChat = form.toggleChat.checked; |         toggleChat = form.toggleChat.checked; | ||||||
|  |         strictSkip = form.strictSkip.checked; | ||||||
|  |  | ||||||
|  |         if(form.strictSkipNumber) { | ||||||
|  |             strictSkipNumber = form.strictSkipNumber; | ||||||
|  |         } else { | ||||||
|  |             strictSkipNumber = conf.strictSkipNumber; | ||||||
|  |         } | ||||||
|  |  | ||||||
|         var pass_send = userpass_changed && !form.userpass.checked ? "" : userpass; |         var pass_send = userpass_changed && !form.userpass.checked ? "" : userpass; | ||||||
|         configs = { |         configs = { | ||||||
| @@ -231,8 +255,10 @@ var Admin = { | |||||||
|             skipping: skipping, |             skipping: skipping, | ||||||
|             shuffling: shuffling, |             shuffling: shuffling, | ||||||
|             toggleChat: toggleChat, |             toggleChat: toggleChat, | ||||||
|  |             strictSkip: strictSkip, | ||||||
|             userpass: Crypt.crypt_pass(pass_send), |             userpass: Crypt.crypt_pass(pass_send), | ||||||
|             userpass_changed: userpass_changed |             userpass_changed: userpass_changed, | ||||||
|  |             strictSkipNumber: strictSkipNumber | ||||||
|         }; |         }; | ||||||
|  |  | ||||||
|         emit("conf", configs); |         emit("conf", configs); | ||||||
|   | |||||||
| @@ -1278,6 +1278,11 @@ function addDynamicListeners() { | |||||||
|         Admin.pass_save(); |         Admin.pass_save(); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|  |     addListener("submit", "#strictSkipForm", function(event){ | ||||||
|  |         this.preventDefault(); | ||||||
|  |         Admin.update_strict_skip(document.getElementById("strict-input-number").value); | ||||||
|  |     }); | ||||||
|  |  | ||||||
|     addListener("click", "#channel-share-modal", function(){ |     addListener("click", "#channel-share-modal", function(){ | ||||||
|         M.Modal.getInstance(document.getElementById("channel-share-modal")).close(); |         M.Modal.getInstance(document.getElementById("channel-share-modal")).close(); | ||||||
|     }); |     }); | ||||||
|   | |||||||
| @@ -5,14 +5,16 @@ | |||||||
|     </div> |     </div> | ||||||
|     <div class="collapsible-body"> |     <div class="collapsible-body"> | ||||||
|         <ul> |         <ul> | ||||||
|             <form action="#" id="adminForm" onsubmit="return false;"> |  | ||||||
|  |  | ||||||
|  |             <form action="#" id="adminForm" onsubmit="return false;"> | ||||||
|                 <li class="white-bg"> |                 <li class="white-bg"> | ||||||
|                     <div class="input-field field-settings"> |                     <div class="input-field field-settings"> | ||||||
|                         <i id="admin-lock" class="material-icons">lock</i> |                         <i id="admin-lock" class="material-icons">lock</i> | ||||||
|                         <input placeholder="Enter admin password" id="password" type="password" class="validate" /> |                         <input placeholder="Enter admin password" id="password" type="password" class="validate" /> | ||||||
|                     </div> |                     </div> | ||||||
|                 </li> |                 </li> | ||||||
|  |             </form> | ||||||
|  |             <form action="#" id="adminSettingsForm" onsubmit="return false;"> | ||||||
|                 <li> |                 <li> | ||||||
|                     <span class="switch-text"> |                     <span class="switch-text"> | ||||||
|                         Add songs |                         Add songs | ||||||
| @@ -25,7 +27,6 @@ | |||||||
|                         </label> |                         </label> | ||||||
|                     </div> |                     </div> | ||||||
|                 </li> |                 </li> | ||||||
|  |  | ||||||
|                 <li> |                 <li> | ||||||
|                     <span class="switch-text"> |                     <span class="switch-text"> | ||||||
|                         Vote |                         Vote | ||||||
| @@ -51,7 +52,6 @@ | |||||||
|                         </label> |                         </label> | ||||||
|                     </div> |                     </div> | ||||||
|                 </li> |                 </li> | ||||||
|  |  | ||||||
|                 <li> |                 <li> | ||||||
|                     <span class="switch-text"> |                     <span class="switch-text"> | ||||||
|                         Skip |                         Skip | ||||||
| @@ -64,7 +64,6 @@ | |||||||
|                         </label> |                         </label> | ||||||
|                     </div> |                     </div> | ||||||
|                 </li> |                 </li> | ||||||
|  |  | ||||||
|                 <li> |                 <li> | ||||||
|                     <span class="switch-text"> |                     <span class="switch-text"> | ||||||
|                         Song length |                         Song length | ||||||
| @@ -77,7 +76,6 @@ | |||||||
|                         </label> |                         </label> | ||||||
|                     </div> |                     </div> | ||||||
|                 </li> |                 </li> | ||||||
|  |  | ||||||
|                 <li> |                 <li> | ||||||
|                     <span class="switch-text"> |                     <span class="switch-text"> | ||||||
|                         Type |                         Type | ||||||
| @@ -114,6 +112,18 @@ | |||||||
|                         </label> |                         </label> | ||||||
|                     </div> |                     </div> | ||||||
|                 </li> |                 </li> | ||||||
|  |                 <li> | ||||||
|  |                     <span class="switch-text"> | ||||||
|  |                         Strict skip | ||||||
|  |                     </span> | ||||||
|  |                     <div class="switch"> | ||||||
|  |                         <label> | ||||||
|  |                             <span class="left-span">Off</span> | ||||||
|  |                             <input name="strictSkip" type="checkbox" class="conf" /><span class="lever"></span> | ||||||
|  |                             <span class="right-span">On</span> | ||||||
|  |                         </label> | ||||||
|  |                     </div> | ||||||
|  |                 </li> | ||||||
|                 <li class="chat-toggle-li hide"> |                 <li class="chat-toggle-li hide"> | ||||||
|                     <span class="switch-text"> |                     <span class="switch-text"> | ||||||
|                         Chat |                         Chat | ||||||
| @@ -139,7 +149,15 @@ | |||||||
|                     </div> |                     </div> | ||||||
|                 </li> |                 </li> | ||||||
|             </form> |             </form> | ||||||
|  |             <form action="#" id="strictSkipForm" onsubmit="return false;"> | ||||||
|  |                 <li class="white-bg strict-skip-input hide"> | ||||||
|  |                     <div class="input-field field-settings"> | ||||||
|  |                         <i id="strict-skip-lock" class="material-icons">queue_play_next</i> | ||||||
|  |                         <input placeholder="Strict skip number" id="strict-input-number" type="number" class="validate" /> | ||||||
|  |                         <div class="strict-skip-info">votes needed to skip.</div> | ||||||
|  |                     </div> | ||||||
|  |                 </li> | ||||||
|  |             </form> | ||||||
|             <li class="change_user_pass hide"> |             <li class="change_user_pass hide"> | ||||||
|                 <a href="#!" class="change_user_pass_btn btn waves-effect blue">Change password</a> |                 <a href="#!" class="change_user_pass_btn btn waves-effect blue">Change password</a> | ||||||
|             </li> |             </li> | ||||||
|   | |||||||
| @@ -6,6 +6,7 @@ var ObjectId = mongojs.ObjectId; | |||||||
| var token_db = mongojs("tokens"); | var token_db = mongojs("tokens"); | ||||||
| var cookieParser = require("cookie-parser"); | var cookieParser = require("cookie-parser"); | ||||||
| var db = require(pathThumbnails + '/handlers/db.js'); | var db = require(pathThumbnails + '/handlers/db.js'); | ||||||
|  | var allowed_key = require(pathThumbnails + '/config/allowed_api.js'); | ||||||
| var crypto = require('crypto'); | var crypto = require('crypto'); | ||||||
| var List = require(pathThumbnails + '/handlers/list.js'); | var List = require(pathThumbnails + '/handlers/list.js'); | ||||||
| var Functions = require(pathThumbnails + '/handlers/functions.js'); | var Functions = require(pathThumbnails + '/handlers/functions.js'); | ||||||
| @@ -14,6 +15,11 @@ var Search = require(pathThumbnails + '/handlers/search.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 _exports = { | ||||||
|  |     router: router, | ||||||
|  |     sIO: {} | ||||||
|  | } | ||||||
| var projects = require(pathThumbnails + "/handlers/aggregates.js"); | var projects = require(pathThumbnails + "/handlers/aggregates.js"); | ||||||
|  |  | ||||||
| var error = { | var error = { | ||||||
| @@ -67,6 +73,24 @@ var error = { | |||||||
|         success: false, |         success: false, | ||||||
|         results: [], |         results: [], | ||||||
|     }, |     }, | ||||||
|  |     settings: { | ||||||
|  |         status: 409, | ||||||
|  |         error: "The channel doesn't have strict skipping enabled.", | ||||||
|  |         success: false, | ||||||
|  |         results: [], | ||||||
|  |     }, | ||||||
|  |     already_skip: { | ||||||
|  |         status: 206, | ||||||
|  |         error: false, | ||||||
|  |         success: true, | ||||||
|  |         results: [], | ||||||
|  |     }, | ||||||
|  |     more_skip_needed: { | ||||||
|  |         status: 202, | ||||||
|  |         error: false, | ||||||
|  |         success: true, | ||||||
|  |         results: [], | ||||||
|  |     }, | ||||||
|     no_error: { |     no_error: { | ||||||
|         status: 200, |         status: 200, | ||||||
|         error: false, |         error: false, | ||||||
| @@ -271,6 +295,75 @@ router.route('/api/list/:channel_name/:video_id').delete(function(req, res) { | |||||||
|     }); |     }); | ||||||
| }); | }); | ||||||
|  |  | ||||||
|  | router.route('/api/skip/:channel_name').post(function(req, res) { | ||||||
|  |     res.header("Access-Control-Allow-Origin", "*"); | ||||||
|  |     res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); | ||||||
|  |     res.header({"Content-Type": "application/json"}); | ||||||
|  |  | ||||||
|  |     var api_key = req.body.api_key; | ||||||
|  |     var guid = req.body.chat_name; | ||||||
|  |     var channel_name = cleanChannelName(req.params.channel_name); | ||||||
|  |     var userpass = ""; | ||||||
|  |     if(req.body.userpass && req.body.userpass != "") userpass = crypto.createHash('sha256').update(Functions.decrypt_string(req.body.userpass)).digest("base64"); | ||||||
|  |     if(allowed_key.indexOf(api_key) > -1) { | ||||||
|  |         db.collection(channel_name + "_settings").find({"id": "config"}, function(err, settings) { | ||||||
|  |             if(settings.length == 0) { | ||||||
|  |                 res.status(404).send(error.not_found.list); | ||||||
|  |                 return; | ||||||
|  |             } | ||||||
|  |             settings = settings[0]; | ||||||
|  |             if(!settings.strictSkip) { | ||||||
|  |                 res.status(409).send(error.settings); | ||||||
|  |                 return; | ||||||
|  |             } | ||||||
|  |             if(settings.userpass == "" || (settings.userpass == userpass)) { | ||||||
|  |                 if(settings.skips.length+1 >= settings.strictSkipNumber && !Functions.contains(settings.skips, guid)) { | ||||||
|  |                     Functions.checkTimeout("skip", 1, channel_name, channel_name, false, true, undefined, function() { | ||||||
|  |                         db.collection(channel_name).find({now_playing: true}, function(err, np) { | ||||||
|  |                             if(np.length != 1) { | ||||||
|  |                                 res.status(404).send(error.not_found.list); | ||||||
|  |                                 return; | ||||||
|  |                             } | ||||||
|  |                             List.change_song(channel_name, false, np[0].id, [settings], function() { | ||||||
|  |                                 res.status(200).send(error.no_error); | ||||||
|  |                                 return; | ||||||
|  |                             }); | ||||||
|  |                             _exports.sIO.to(channel_name).emit('chat', {from: guid, icon: false, msg: " skipped via API."}); | ||||||
|  |                         }); | ||||||
|  |                     }, "", function() { | ||||||
|  |                         res.status(429).send(error.tooMany); | ||||||
|  |                         return; | ||||||
|  |                     }); | ||||||
|  |                 } else if(!Functions.contains(settings.skips, guid)) { | ||||||
|  |                     db.collection(channel_name + "_settings").update({ id: "config" }, {$push:{skips:guid}}, function(err, d){ | ||||||
|  |                         var to_skip = (settings.strictSkipNumber) - settings.skips.length-1; | ||||||
|  |                         _exports.sIO.to(channel_name).emit('chat', {from: guid, msg: " voted to skip via API."}); | ||||||
|  |                         // VOTED TO SKIP | ||||||
|  |                         var to_send = error.more_skip_needed; | ||||||
|  |                         to_send.results = [to_skip] | ||||||
|  |                         res.status(202).send(to_send); | ||||||
|  |                         return; | ||||||
|  |                     }); | ||||||
|  |                 } else { | ||||||
|  |                     //ALREADY SKIP | ||||||
|  |                     res.status(206).send(error.already_skip); | ||||||
|  |                     return; | ||||||
|  |                 } | ||||||
|  |             } else { | ||||||
|  |                 // NOT AUTHENTICATED | ||||||
|  |                 res.status(403).send(error.not_authenticated); | ||||||
|  |                 return; | ||||||
|  |             } | ||||||
|  |         }); | ||||||
|  |     } else { | ||||||
|  |         // WRONG API KEY | ||||||
|  |         var toSend = error.not_authenticated; | ||||||
|  |         toSend.status = 406; | ||||||
|  |         res.status(406).send(toSend); | ||||||
|  |         return; | ||||||
|  |     } | ||||||
|  | }); | ||||||
|  |  | ||||||
| router.route('/api/conf/:channel_name').put(function(req, res) { | router.route('/api/conf/:channel_name').put(function(req, res) { | ||||||
|     res.header("Access-Control-Allow-Origin", "*"); |     res.header("Access-Control-Allow-Origin", "*"); | ||||||
|     res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); |     res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); | ||||||
| @@ -1492,4 +1585,4 @@ function postEnd(channel_name, configs, new_song, guid, res, authenticated, auth | |||||||
|     }); |     }); | ||||||
| } | } | ||||||
|  |  | ||||||
| module.exports = router; | module.exports = _exports; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user