mirror of
				https://github.com/KevinMidboe/zoff.git
				synced 2025-10-29 18:00:23 +00:00 
			
		
		
		
	Timeout api, and fixes it lead to
- timeout on api-calls with Retry-After present in header - Fixed issue where when server restarts you are sometimes logged out for some reason - README updates
This commit is contained in:
		| @@ -28,6 +28,13 @@ If you want to use Google Analytics, have a look at ```analytics.example.js``` i | |||||||
|  |  | ||||||
| If you have run the server before the table-structures where added, please run ```node server/apps/rewrite.js```. This will fix any crashes that occurs because of faulty document-collectionnames due to moving channel-settings to a separate collection. | If you have run the server before the table-structures where added, please run ```node server/apps/rewrite.js```. This will fix any crashes that occurs because of faulty document-collectionnames due to moving channel-settings to a separate collection. | ||||||
|  |  | ||||||
|  | Run | ||||||
|  | ``` | ||||||
|  | db.chat_logs.createIndex({ "createdAt": 1 }, { expireAfterSeconds: X }); | ||||||
|  | db.timeout_api.createIndex({ "createdAt": 1 }, { expireAfterSeconds: Y }); | ||||||
|  | ``` | ||||||
|  | in mongo to have chat_logs and api be deleted after X and Y seconds. | ||||||
|  |  | ||||||
| Use ```$ npm start``` to start the server. (Alternative you can use the ```pm2.json``` in the project-root, if you prefer pm2 for running the apps.) | Use ```$ npm start``` to start the server. (Alternative you can use the ```pm2.json``` in the project-root, if you prefer pm2 for running the apps.) | ||||||
|  |  | ||||||
| ### About | ### About | ||||||
|   | |||||||
| @@ -10,7 +10,7 @@ var mongojs = require('mongojs'); | |||||||
| var db = mongojs('mongodb://' + mongo_config.host + '/' + mongo_config.config); | var db = mongojs('mongodb://' + mongo_config.host + '/' + mongo_config.config); | ||||||
|  |  | ||||||
| db.collection("chat_logs").createIndex({ "createdAt": 1 }, { expireAfterSeconds: 600 }); | db.collection("chat_logs").createIndex({ "createdAt": 1 }, { expireAfterSeconds: 600 }); | ||||||
|  | db.collection("timeout_api").createIndex({ "createdAt": 1 }, { expireAfterSeconds: 5 }); | ||||||
| db.on('connected', function(err) { | db.on('connected', function(err) { | ||||||
|     console.log("connected"); |     console.log("connected"); | ||||||
| }) | }) | ||||||
|   | |||||||
| @@ -282,18 +282,6 @@ module.exports = function() { | |||||||
|  |  | ||||||
|         socket.on('skip', function(list) |         socket.on('skip', function(list) | ||||||
|         { |         { | ||||||
|             if(coll !== undefined) { |  | ||||||
|                 try { |  | ||||||
|                     coll = list.channel; |  | ||||||
|                     if(coll.length == 0) return; |  | ||||||
|                     coll = emojiStrip(coll).toLowerCase(); |  | ||||||
|                     coll = coll.replace("_", ""); |  | ||||||
|                     coll = encodeURIComponent(coll).replace(/\W/g, ''); |  | ||||||
|                     coll = filter.clean(coll); |  | ||||||
|                 } catch(e) { |  | ||||||
|                     return; |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|             List.skip(list, guid, coll, offline, socket); |             List.skip(list, guid, coll, offline, socket); | ||||||
|         }); |         }); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -77,11 +77,19 @@ function skip(list, guid, coll, offline, socket) { | |||||||
|  |  | ||||||
|     if(list !== undefined && list !== null && list !== "") |     if(list !== undefined && list !== null && list !== "") | ||||||
|     { |     { | ||||||
|  |         if(coll == undefined && list.hasOwnProperty('channel')) coll = list.channel; | ||||||
|         if(coll == "" || coll == undefined || coll == null) { |         if(coll !== undefined) { | ||||||
|             socket.emit("update_required"); |             try { | ||||||
|  |                 coll = list.channel; | ||||||
|  |                 if(coll.length == 0) return; | ||||||
|  |                 coll = emojiStrip(coll).toLowerCase(); | ||||||
|  |                 coll = coll.replace("_", ""); | ||||||
|  |                 coll = encodeURIComponent(coll).replace(/\W/g, ''); | ||||||
|  |                 coll = filter.clean(coll); | ||||||
|  |             } catch(e) { | ||||||
|                 return; |                 return; | ||||||
|             } |             } | ||||||
|  |         } | ||||||
|         if(typeof(list.pass) != "string" || typeof(list.id) != "string" || |         if(typeof(list.pass) != "string" || typeof(list.id) != "string" || | ||||||
|             typeof(list.channel) != "string" || typeof(list.userpass) != "string") { |             typeof(list.channel) != "string" || typeof(list.userpass) != "string") { | ||||||
|                 socket.emit("toast", "update_required"); |                 socket.emit("toast", "update_required"); | ||||||
|   | |||||||
| @@ -22,7 +22,6 @@ function password(inp, coll, guid, offline, socket) { | |||||||
|         uncrypted = pw; |         uncrypted = pw; | ||||||
|         pw = Functions.decrypt_string(socket.zoff_id, pw); |         pw = Functions.decrypt_string(socket.zoff_id, pw); | ||||||
|         Functions.check_inlist(coll, guid, socket, offline); |         Functions.check_inlist(coll, guid, socket, offline); | ||||||
|  |  | ||||||
|         if(inp.oldpass) |         if(inp.oldpass) | ||||||
|         { |         { | ||||||
|             opw = inp.oldpass; |             opw = inp.oldpass; | ||||||
|   | |||||||
| @@ -367,7 +367,7 @@ var Admin = { | |||||||
|  |  | ||||||
|     shuffle: function() { |     shuffle: function() { | ||||||
|         if(!offline) { |         if(!offline) { | ||||||
|             emit('shuffle', {adminpass: adminpass !== undefined ? Crypt.crypt_pass(adminpass) : "", channel: chan.toLowerCase(), pass: embed ? '' : Crypt.crypt_pass(Crypt.get_userpass(chan.toLowerCase()))}); |             emit('shuffle', {adminpass: adminpass !== undefined ? Crypt.crypt_pass(adminpass) : "", channel: chan.toLowerCase(), pass: embed ? '' : Crypt.crypt_pass(Crypt.get_userpass(chan.toLowerCase()), true)}); | ||||||
|         } else { |         } else { | ||||||
|             for(var x = 0; x < full_playlist.length; x++){ |             for(var x = 0; x < full_playlist.length; x++){ | ||||||
|                 var num = Math.floor(Math.random()*1000000); |                 var num = Math.floor(Math.random()*1000000); | ||||||
|   | |||||||
| @@ -135,7 +135,7 @@ var Channel = { | |||||||
|         if(no_socket || Helper.mobilecheck()){ |         if(no_socket || Helper.mobilecheck()){ | ||||||
|             var add = ""; |             var add = ""; | ||||||
|             if(private_channel) add = Crypt.getCookie("_uI") + "_"; |             if(private_channel) add = Crypt.getCookie("_uI") + "_"; | ||||||
|             socket.emit("list", {version: parseInt(localStorage.getItem("VERSION")), channel: add + chan.toLowerCase(), pass: embed ? '' : Crypt.crypt_pass(Crypt.get_userpass(chan.toLowerCase()))}); |             socket.emit("list", {version: parseInt(localStorage.getItem("VERSION")), channel: add + chan.toLowerCase(), pass: embed ? '' : Crypt.crypt_pass(Crypt.get_userpass(chan.toLowerCase()), true)}); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         if((!localStorage.getItem("_jSeen") || localStorage.getItem("_jSeen") != "seen") && !Helper.mobilecheck()) { |         if((!localStorage.getItem("_jSeen") || localStorage.getItem("_jSeen") != "seen") && !Helper.mobilecheck()) { | ||||||
| @@ -478,7 +478,7 @@ var Channel = { | |||||||
|             var add = ""; |             var add = ""; | ||||||
|             w_p = true; |             w_p = true; | ||||||
|             if(private_channel) add = Crypt.getCookie("_uI") + "_"; |             if(private_channel) add = Crypt.getCookie("_uI") + "_"; | ||||||
|             socket.emit("list", {version: parseInt(localStorage.getItem("VERSION")), channel: add + chan.toLowerCase(), pass: embed ? '' : Crypt.crypt_pass(Crypt.get_userpass(chan.toLowerCase()))}); |             socket.emit("list", {version: parseInt(localStorage.getItem("VERSION")), channel: add + chan.toLowerCase(), pass: embed ? '' : Crypt.crypt_pass(Crypt.get_userpass(chan.toLowerCase()), true)}); | ||||||
|         } else if(url_split[3] === "") { |         } else if(url_split[3] === "") { | ||||||
|             clearTimeout(timed_remove_check); |             clearTimeout(timed_remove_check); | ||||||
|             changing_to_frontpage = true; |             changing_to_frontpage = true; | ||||||
|   | |||||||
| @@ -2,6 +2,7 @@ var Crypt = { | |||||||
|  |  | ||||||
|     conf_pass: undefined, |     conf_pass: undefined, | ||||||
|     user_pass: undefined, |     user_pass: undefined, | ||||||
|  |     tmp_pass_user: "", | ||||||
|     tmp_pass: "", |     tmp_pass: "", | ||||||
|  |  | ||||||
|     init: function() { |     init: function() { | ||||||
| @@ -216,8 +217,12 @@ var Crypt = { | |||||||
|         return encrypted.toString() + "$" + iv; |         return encrypted.toString() + "$" + iv; | ||||||
|     }, |     }, | ||||||
|  |  | ||||||
|     crypt_pass: function(pass) { |     crypt_pass: function(pass, userpass) { | ||||||
|  |         if(userpass) { | ||||||
|  |             Crypt.tmp_pass_user = pass; | ||||||
|  |         } else { | ||||||
|             Crypt.tmp_pass = pass; |             Crypt.tmp_pass = pass; | ||||||
|  |         } | ||||||
|         return Crypt.crypt_chat_pass(pass); |         return Crypt.crypt_chat_pass(pass); | ||||||
|     }, |     }, | ||||||
|  |  | ||||||
|   | |||||||
| @@ -97,7 +97,7 @@ function hide_native(way) { | |||||||
|         $("#chromecast_text").html(""); |         $("#chromecast_text").html(""); | ||||||
|         $("#playing_on").css("display", "none"); |         $("#playing_on").css("display", "none"); | ||||||
|         if(!offline){ |         if(!offline){ | ||||||
|             socket.emit('pos', {channel: chan.toLowerCase(), pass: embed ? '' : Crypt.crypt_pass(Crypt.get_userpass(chan.toLowerCase()))}); |             socket.emit('pos', {channel: chan.toLowerCase(), pass: embed ? '' : Crypt.crypt_pass(Crypt.get_userpass(chan.toLowerCase()), true)}); | ||||||
|         } else { |         } else { | ||||||
|             Player.loadVideoById(video_id); |             Player.loadVideoById(video_id); | ||||||
|         } |         } | ||||||
| @@ -111,14 +111,14 @@ function chromecastListener(evt, data) { | |||||||
|             if(offline){ |             if(offline){ | ||||||
|                 Player.playNext(); |                 Player.playNext(); | ||||||
|             } else { |             } else { | ||||||
|                 socket.emit("end", {id: json_parsed.videoId, channel: chan.toLowerCase(), pass: embed ? '' : Crypt.crypt_pass(Crypt.get_userpass(chan.toLowerCase()))}); |                 socket.emit("end", {id: json_parsed.videoId, channel: chan.toLowerCase(), pass: embed ? '' : Crypt.crypt_pass(Crypt.get_userpass(chan.toLowerCase()), true)}); | ||||||
|             } |             } | ||||||
|             break; |             break; | ||||||
|         case 0: |         case 0: | ||||||
|             if(offline){ |             if(offline){ | ||||||
|                 Player.playNext(); |                 Player.playNext(); | ||||||
|             } else { |             } else { | ||||||
|                 emit("skip", {error: json_parsed.data_code, id: json_parsed.videoId, pass: adminpass == "" ? "" : Crypt.crypt_pass(adminpass), channel: chan.toLowerCase(), userpass: embed ? '' : Crypt.crypt_pass(Crypt.get_userpass(chan.toLowerCase()))}); |                 emit("skip", {error: json_parsed.data_code, id: json_parsed.videoId, pass: adminpass == "" ? "" : Crypt.crypt_pass(adminpass), channel: chan.toLowerCase(), userpass: embed ? '' : Crypt.crypt_pass(Crypt.get_userpass(chan.toLowerCase()), true)}); | ||||||
|             } |             } | ||||||
|             break; |             break; | ||||||
|         case 1: |         case 1: | ||||||
| @@ -183,7 +183,7 @@ function get_list_listener(){ | |||||||
|     socket.on("get_list", function(){ |     socket.on("get_list", function(){ | ||||||
|         var add = ""; |         var add = ""; | ||||||
|         if(private_channel) add = Crypt.getCookie("_uI") + "_"; |         if(private_channel) add = Crypt.getCookie("_uI") + "_"; | ||||||
|         socket.emit("list", { offline: offline, version: parseInt(localStorage.getItem("VERSION")), channel: add + chan.toLowerCase(), pass: embed ? '' : Crypt.crypt_pass(Crypt.get_userpass(chan.toLowerCase()))}); |         socket.emit("list", { offline: offline, version: parseInt(localStorage.getItem("VERSION")), channel: add + chan.toLowerCase(), pass: embed ? '' : Crypt.crypt_pass(Crypt.get_userpass(chan.toLowerCase()), true)}); | ||||||
|     }); |     }); | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -361,10 +361,10 @@ function change_offline(enabled, already_offline){ | |||||||
|         $("#controls").off("click", Channel.seekToClick); |         $("#controls").off("click", Channel.seekToClick); | ||||||
|         $("#seekToDuration").remove(); |         $("#seekToDuration").remove(); | ||||||
|         if(window.location.pathname != "/"){ |         if(window.location.pathname != "/"){ | ||||||
|             socket.emit("pos", {channel: chan.toLowerCase(), pass: embed ? '' : Crypt.crypt_pass(Crypt.get_userpass(chan.toLowerCase()))}); |             socket.emit("pos", {channel: chan.toLowerCase(), pass: embed ? '' : Crypt.crypt_pass(Crypt.get_userpass(chan.toLowerCase()), true)}); | ||||||
|             var add = ""; |             var add = ""; | ||||||
|             if(private_channel) add = Crypt.getCookie("_uI") + "_"; |             if(private_channel) add = Crypt.getCookie("_uI") + "_"; | ||||||
|             socket.emit("list", {version: parseInt(localStorage.getItem("VERSION")), channel: add + chan.toLowerCase(), pass: embed ? '' : Crypt.crypt_pass(Crypt.get_userpass(chan.toLowerCase()))}); |             socket.emit("list", {version: parseInt(localStorage.getItem("VERSION")), channel: add + chan.toLowerCase(), pass: embed ? '' : Crypt.crypt_pass(Crypt.get_userpass(chan.toLowerCase()), true)}); | ||||||
|             if($("#controls").hasClass("ewresize")) $("#controls").removeClass("ewresize"); |             if($("#controls").hasClass("ewresize")) $("#controls").removeClass("ewresize"); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -47,7 +47,7 @@ var Hostcontroller = { | |||||||
|                 w_p = true; |                 w_p = true; | ||||||
|                 var add = ""; |                 var add = ""; | ||||||
|                 if(private_channel) add = Crypt.getCookie("_uI") + "_"; |                 if(private_channel) add = Crypt.getCookie("_uI") + "_"; | ||||||
|                 socket.emit("list", {version: parseInt(localStorage.getItem("VERSION")), channel: add + chan.toLowerCase(), pass: embed ? '' : Crypt.crypt_pass(Crypt.get_userpass(chan.toLowerCase()))}); |                 socket.emit("list", {version: parseInt(localStorage.getItem("VERSION")), channel: add + chan.toLowerCase(), pass: embed ? '' : Crypt.crypt_pass(Crypt.get_userpass(chan.toLowerCase()), true)}); | ||||||
|  |  | ||||||
|                 window.history.pushState("object or string", "Title", "/"+chan.toLowerCase()); |                 window.history.pushState("object or string", "Title", "/"+chan.toLowerCase()); | ||||||
|             } else if(arr.type == "pause") { |             } else if(arr.type == "pause") { | ||||||
|   | |||||||
| @@ -535,7 +535,7 @@ var List = { | |||||||
|  |  | ||||||
|     vote: function(id, vote) { |     vote: function(id, vote) { | ||||||
|         if(!offline || (vote == "del" && (hasadmin && (!w_p && adminpass != "")))){ |         if(!offline || (vote == "del" && (hasadmin && (!w_p && adminpass != "")))){ | ||||||
|             emit('vote', {channel: chan, id: id, type: vote, adminpass: adminpass == "" ? "" : Crypt.crypt_pass(adminpass), pass: embed ? '' : Crypt.crypt_pass(Crypt.get_userpass(chan.toLowerCase()))}); |             emit('vote', {channel: chan, id: id, type: vote, adminpass: adminpass == "" ? "" : Crypt.crypt_pass(adminpass), pass: embed ? '' : Crypt.crypt_pass(Crypt.get_userpass(chan.toLowerCase()), true)}); | ||||||
|         } else { |         } else { | ||||||
|             if(vote == "pos"){ |             if(vote == "pos"){ | ||||||
|                 List.voted_song(id, (new Date()).getTime()/1000); |                 List.voted_song(id, (new Date()).getTime()/1000); | ||||||
| @@ -548,7 +548,7 @@ var List = { | |||||||
|  |  | ||||||
|     skip: function(way) { |     skip: function(way) { | ||||||
|         if(!offline){ |         if(!offline){ | ||||||
|             emit('skip', {pass: adminpass == "" ? "" : Crypt.crypt_pass(adminpass), id:video_id, channel: chan.toLowerCase(), userpass: embed ? '' : Crypt.crypt_pass(Crypt.get_userpass(chan.toLowerCase()))}); |             emit('skip', {pass: adminpass == "" ? "" : Crypt.crypt_pass(adminpass), id:video_id, channel: chan.toLowerCase(), userpass: embed ? '' : Crypt.crypt_pass(Crypt.get_userpass(chan.toLowerCase()), true)}); | ||||||
|         } else { |         } else { | ||||||
|             if(way) { |             if(way) { | ||||||
|                 Player.playNext(); |                 Player.playNext(); | ||||||
|   | |||||||
| @@ -258,7 +258,7 @@ initializeCastApi = function() { | |||||||
|  |  | ||||||
|                 if(Helper.mobilecheck() && !chromecast_specs_sent) { |                 if(Helper.mobilecheck() && !chromecast_specs_sent) { | ||||||
|                     chromecast_specs_sent = true; |                     chromecast_specs_sent = true; | ||||||
|                     castSession.sendMessage("urn:x-cast:zoff.me", {type: "mobilespecs", guid: guid, socketid: socket.id, adminpass: adminpass == "" ? "" : Crypt.crypt_pass(adminpass), channel: chan.toLowerCase(), userpass: embed ? '' : Crypt.crypt_pass(Crypt.get_userpass(chan.toLowerCase()))}) |                     castSession.sendMessage("urn:x-cast:zoff.me", {type: "mobilespecs", guid: guid, socketid: socket.id, adminpass: adminpass == "" ? "" : Crypt.crypt_pass(adminpass), channel: chan.toLowerCase(), userpass: embed ? '' : Crypt.crypt_pass(Crypt.get_userpass(chan.toLowerCase()), true)}) | ||||||
|                 } |                 } | ||||||
|                 hide_native(1); |                 hide_native(1); | ||||||
|                 if(Helper.mobilecheck()) { |                 if(Helper.mobilecheck()) { | ||||||
| @@ -371,7 +371,7 @@ $(document).on("click", ".pagination-results a", function(e) { | |||||||
|  |  | ||||||
| $(document).on("click", ".accept-delete", function(e) { | $(document).on("click", ".accept-delete", function(e) { | ||||||
|     e.preventDefault(); |     e.preventDefault(); | ||||||
|     emit("delete_all", {channel: chan.toLowerCase(), adminpass: adminpass == "" ? "" : Crypt.crypt_pass(adminpass), pass: embed ? '' : Crypt.crypt_pass(Crypt.get_userpass(chan.toLowerCase()))}); |     emit("delete_all", {channel: chan.toLowerCase(), adminpass: adminpass == "" ? "" : Crypt.crypt_pass(adminpass), pass: embed ? '' : Crypt.crypt_pass(Crypt.get_userpass(chan.toLowerCase()), true)}); | ||||||
|     $("#delete_song_alert").modal("close"); |     $("#delete_song_alert").modal("close"); | ||||||
| }); | }); | ||||||
|  |  | ||||||
| @@ -464,13 +464,13 @@ $(document).on("click", "#offline-mode", function(e){ | |||||||
|  |  | ||||||
| $(document).on("submit", "#thumbnail_form", function(e){ | $(document).on("submit", "#thumbnail_form", function(e){ | ||||||
|     e.preventDefault(); |     e.preventDefault(); | ||||||
|     emit("suggest_thumbnail", {channel: chan, thumbnail: $("#chan_thumbnail").val(), adminpass: Crypt.crypt_pass(Crypt.get_pass(chan.toLowerCase())), pass: embed ? '' : Crypt.crypt_pass(Crypt.get_userpass(chan.toLowerCase()))}); |     emit("suggest_thumbnail", {channel: chan, thumbnail: $("#chan_thumbnail").val(), adminpass: Crypt.crypt_pass(Crypt.get_pass(chan.toLowerCase())), pass: embed ? '' : Crypt.crypt_pass(Crypt.get_userpass(chan.toLowerCase()), true)}); | ||||||
|     $("#chan_thumbnail").val(""); |     $("#chan_thumbnail").val(""); | ||||||
| }); | }); | ||||||
|  |  | ||||||
| $(document).on("submit", "#description_form", function(e){ | $(document).on("submit", "#description_form", function(e){ | ||||||
|     e.preventDefault(); |     e.preventDefault(); | ||||||
|     emit("suggest_description", {channel: chan, description: $("#chan_description").val(), adminpass: Crypt.crypt_pass(Crypt.get_pass(chan.toLowerCase())), pass: embed ? '' : Crypt.crypt_pass(Crypt.get_userpass(chan.toLowerCase()))}); |     emit("suggest_description", {channel: chan, description: $("#chan_description").val(), adminpass: Crypt.crypt_pass(Crypt.get_pass(chan.toLowerCase())), pass: embed ? '' : Crypt.crypt_pass(Crypt.get_userpass(chan.toLowerCase()), true)}); | ||||||
|     $("#chan_description").val(""); |     $("#chan_description").val(""); | ||||||
| }); | }); | ||||||
|  |  | ||||||
| @@ -561,6 +561,7 @@ $(document).on("submit", "#user-password-channel-form", function(e) { | |||||||
|     e.preventDefault(); |     e.preventDefault(); | ||||||
|     if(user_auth_started) { |     if(user_auth_started) { | ||||||
|         temp_user_pass = CryptoJS.SHA256($("#user-pass-input").val()).toString(); |         temp_user_pass = CryptoJS.SHA256($("#user-pass-input").val()).toString(); | ||||||
|  |  | ||||||
|         $("#user-pass-input").val(""); |         $("#user-pass-input").val(""); | ||||||
|         socket.emit("list", {version: parseInt(localStorage.getItem("VERSION")), channel: chan.toLowerCase(), pass: Crypt.crypt_pass(temp_user_pass)}); |         socket.emit("list", {version: parseInt(localStorage.getItem("VERSION")), channel: chan.toLowerCase(), pass: Crypt.crypt_pass(temp_user_pass)}); | ||||||
|     } else { |     } else { | ||||||
|   | |||||||
| @@ -231,7 +231,7 @@ var Player = { | |||||||
|                 paused  = false; |                 paused  = false; | ||||||
|  |  | ||||||
|                 if(!offline) { |                 if(!offline) { | ||||||
|                     socket.emit("end", {id: video_id, channel: chan.toLowerCase(), pass: embed ? '' : Crypt.crypt_pass(Crypt.get_userpass(chan.toLowerCase()))}); |                     socket.emit("end", {id: video_id, channel: chan.toLowerCase(), pass: embed ? '' : Crypt.crypt_pass(Crypt.get_userpass(chan.toLowerCase()), true)}); | ||||||
|                 } else { |                 } else { | ||||||
|                     Player.playNext(); |                     Player.playNext(); | ||||||
|                 } |                 } | ||||||
| @@ -261,7 +261,7 @@ var Player = { | |||||||
|                         $("#pause").toggleClass("hide"); |                         $("#pause").toggleClass("hide"); | ||||||
|                 } |                 } | ||||||
|                 if((paused && !offline) || was_stopped) { |                 if((paused && !offline) || was_stopped) { | ||||||
|                     socket.emit('pos', {channel: chan.toLowerCase(), pass: embed ? '' : Crypt.crypt_pass(Crypt.get_userpass(chan.toLowerCase()))}); |                     socket.emit('pos', {channel: chan.toLowerCase(), pass: embed ? '' : Crypt.crypt_pass(Crypt.get_userpass(chan.toLowerCase()), true)}); | ||||||
|                     paused = false; |                     paused = false; | ||||||
|                     was_stopped = false; |                     was_stopped = false; | ||||||
|                 } |                 } | ||||||
| @@ -491,7 +491,7 @@ var Player = { | |||||||
|         if(!user_auth_started) { |         if(!user_auth_started) { | ||||||
|             if(newState.data == 5 || newState.data == 100 || newState.data == 101 || newState.data == 150) { |             if(newState.data == 5 || newState.data == 100 || newState.data == 101 || newState.data == 150) { | ||||||
|                 curr_playing = Player.player.getVideoUrl().replace("https://www.youtube.com/watch?v=", ""); |                 curr_playing = Player.player.getVideoUrl().replace("https://www.youtube.com/watch?v=", ""); | ||||||
|                 emit("skip", {error: newState.data, id: video_id, pass: adminpass == "" ? "" : Crypt.crypt_pass(adminpass), channel: chan.toLowerCase(), userpass: embed ? '' : Crypt.crypt_pass(Crypt.get_userpass(chan.toLowerCase()))}); |                 emit("skip", {error: newState.data, id: video_id, pass: adminpass == "" ? "" : Crypt.crypt_pass(adminpass), channel: chan.toLowerCase(), userpass: embed ? '' : Crypt.crypt_pass(Crypt.get_userpass(chan.toLowerCase()), true)}); | ||||||
|  |  | ||||||
|             } else if(video_id !== undefined) { |             } else if(video_id !== undefined) { | ||||||
|                 Player.loadVideoById(video_id, duration); |                 Player.loadVideoById(video_id, duration); | ||||||
| @@ -680,7 +680,7 @@ var Player = { | |||||||
|                     Player.player.pauseVideo(); |                     Player.player.pauseVideo(); | ||||||
|  |  | ||||||
|                     if(!offline) { |                     if(!offline) { | ||||||
|                         socket.emit("end", {id: video_id, channel: chan.toLowerCase(), pass: embed ? '' : Crypt.crypt_pass(Crypt.get_userpass(chan.toLowerCase()))}); |                         socket.emit("end", {id: video_id, channel: chan.toLowerCase(), pass: embed ? '' : Crypt.crypt_pass(Crypt.get_userpass(chan.toLowerCase()), true)}); | ||||||
|                     } else { |                     } else { | ||||||
|                         Player.playNext(); |                         Player.playNext(); | ||||||
|                     } |                     } | ||||||
|   | |||||||
| @@ -449,7 +449,7 @@ var Search = { | |||||||
|                 List.vote(id, "pos"); |                 List.vote(id, "pos"); | ||||||
|             } |             } | ||||||
|         } else { |         } else { | ||||||
|             emit("add", {id: id, start: start, end: end, title: title, adminpass: adminpass == "" ? "" : Crypt.crypt_pass(adminpass), list: chan.toLowerCase(), duration: duration, playlist: playlist, num: num, total: full_num, pass: embed ? '' : Crypt.crypt_pass(Crypt.get_userpass(chan.toLowerCase()))}); |             emit("add", {id: id, start: start, end: end, title: title, adminpass: adminpass == "" ? "" : Crypt.crypt_pass(adminpass), list: chan.toLowerCase(), duration: duration, playlist: playlist, num: num, total: full_num, pass: embed ? '' : Crypt.crypt_pass(Crypt.get_userpass(chan.toLowerCase()), true)}); | ||||||
|         }//[id, decodeURIComponent(title), adminpass, duration, playlist]); |         }//[id, decodeURIComponent(title), adminpass, duration, playlist]); | ||||||
|     }, |     }, | ||||||
|  |  | ||||||
|   | |||||||
| @@ -147,7 +147,19 @@ router.route('/api/conf/:channel_name').put(function(req, res) { | |||||||
|         res.sendStatus(400); |         res.sendStatus(400); | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
|  |     db.collection("timeout_api").find({ | ||||||
|  |         type: "DELETE", | ||||||
|  |         guid: guid, | ||||||
|  |     }, function(err, docs) { | ||||||
|  |         if(docs.length > 0) { | ||||||
|  |             var date = new Date(docs[0].createdAt); | ||||||
|  |             date.setSeconds(date.getSeconds() + 5); | ||||||
|  |             var now = new Date(); | ||||||
|  |             var retry_in = (date.getTime() - now.getTime()) / 1000; | ||||||
|  |             res.header({'Retry-After': retry_in}); | ||||||
|  |             res.sendStatus(429); | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|         validateLogin(adminpass, userpass, channel_name, "config", res, function(exists) { |         validateLogin(adminpass, userpass, channel_name, "config", res, function(exists) { | ||||||
|             if(!exists) { |             if(!exists) { | ||||||
|                 res.sendStatus(404); |                 res.sendStatus(404); | ||||||
| @@ -191,11 +203,20 @@ router.route('/api/conf/:channel_name').put(function(req, res) { | |||||||
|                     frontpage:frontpage, accessed: Functions.get_time()} |                     frontpage:frontpage, accessed: Functions.get_time()} | ||||||
|                 }, |                 }, | ||||||
|                 {upsert:true}, function(err, docs){ |                 {upsert:true}, function(err, docs){ | ||||||
|  |                     db.collection("timeout_api").update({type: "DELETE", guid: guid}, { | ||||||
|  |                         $set: { | ||||||
|  |                             "createdAt": new Date(), | ||||||
|  |                             type: "DELETE", | ||||||
|  |                             guid: guid, | ||||||
|  |                         }, | ||||||
|  |                     }, {upsert: true}, function(err, docs) { | ||||||
|                         res.header({'Content-Type': 'application/json'}); |                         res.header({'Content-Type': 'application/json'}); | ||||||
|                         res.status(200).send(JSON.stringify(obj)); |                         res.status(200).send(JSON.stringify(obj)); | ||||||
|                     }); |                     }); | ||||||
|                 }); |                 }); | ||||||
|             }); |             }); | ||||||
|  |         }); | ||||||
|  |     }); | ||||||
| }) | }) | ||||||
|  |  | ||||||
| router.route('/api/list/:channel_name/:video_id').put(function(req,res) { | router.route('/api/list/:channel_name/:video_id').put(function(req,res) { | ||||||
| @@ -206,6 +227,7 @@ router.route('/api/list/:channel_name/:video_id').put(function(req,res) { | |||||||
|         res.sendStatus(400); |         res.sendStatus(400); | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     try { |     try { | ||||||
|         var ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress; |         var ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress; | ||||||
|         var guid = Functions.hash_pass(req.get('User-Agent') + ip + req.headers["accept-language"]); |         var guid = Functions.hash_pass(req.get('User-Agent') + ip + req.headers["accept-language"]); | ||||||
| @@ -223,6 +245,20 @@ router.route('/api/list/:channel_name/:video_id').put(function(req,res) { | |||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     db.collection("timeout_api").find({ | ||||||
|  |         type: "PUT", | ||||||
|  |         guid: guid, | ||||||
|  |     }, function(err, docs) { | ||||||
|  |         if(docs.length > 0) { | ||||||
|  |             var date = new Date(docs[0].createdAt); | ||||||
|  |             date.setSeconds(date.getSeconds() + 5); | ||||||
|  |             var now = new Date(); | ||||||
|  |             var retry_in = (date.getTime() - now.getTime()) / 1000; | ||||||
|  |             res.header({'Retry-After': retry_in}); | ||||||
|  |             res.sendStatus(429); | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  |  | ||||||
|         validateLogin(adminpass, userpass, channel_name, "vote", res, function(exists) { |         validateLogin(adminpass, userpass, channel_name, "vote", res, function(exists) { | ||||||
|             if(!exists) { |             if(!exists) { | ||||||
|                 res.sendStatus(404); |                 res.sendStatus(404); | ||||||
| @@ -241,15 +277,24 @@ router.route('/api/list/:channel_name/:video_id').put(function(req,res) { | |||||||
|                     db.collection(channel_name).update({id: video_id}, {$inc:{votes:1}, $set:{added:Functions.get_time()}, $push :{guids: guid}}, function(err, success) { |                     db.collection(channel_name).update({id: video_id}, {$inc:{votes:1}, $set:{added:Functions.get_time()}, $push :{guids: guid}}, function(err, success) { | ||||||
|                         io.to(channel_name).emit("channel", {type: "vote", value: video_id, time: Functions.get_time()}); |                         io.to(channel_name).emit("channel", {type: "vote", value: video_id, time: Functions.get_time()}); | ||||||
|                         List.getNextSong(channel_name, function() { |                         List.getNextSong(channel_name, function() { | ||||||
|  |                             db.collection("timeout_api").update({type: "PUT", guid: guid}, { | ||||||
|  |                                 $set: { | ||||||
|  |                                     "createdAt": new Date(), | ||||||
|  |                                     type: "PUT", | ||||||
|  |                                     guid: guid, | ||||||
|  |                                 }, | ||||||
|  |                             }, {upsert: true}, function(err, docs) { | ||||||
|                                 res.header({'Content-Type': 'application/json'}); |                                 res.header({'Content-Type': 'application/json'}); | ||||||
|                                 res.status(200).send(JSON.stringify(song[0])); |                                 res.status(200).send(JSON.stringify(song[0])); | ||||||
|                                 return; |                                 return; | ||||||
|                             }); |                             }); | ||||||
|                         }); |                         }); | ||||||
|  |                     }); | ||||||
|                 } |                 } | ||||||
|             }) |             }) | ||||||
|         }); |         }); | ||||||
|     }); |     }); | ||||||
|  | }); | ||||||
|  |  | ||||||
| router.route('/api/list/:channel_name/:video_id').post(function(req,res) { | router.route('/api/list/:channel_name/:video_id').post(function(req,res) { | ||||||
|     res.header("Access-Control-Allow-Origin", "*"); |     res.header("Access-Control-Allow-Origin", "*"); | ||||||
| @@ -284,6 +329,20 @@ router.route('/api/list/:channel_name/:video_id').post(function(req,res) { | |||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     db.collection("timeout_api").find({ | ||||||
|  |         type: "POST", | ||||||
|  |         guid: guid, | ||||||
|  |     }, function(err, docs) { | ||||||
|  |         if(docs.length > 0) { | ||||||
|  |             var date = new Date(docs[0].createdAt); | ||||||
|  |             date.setSeconds(date.getSeconds() + 5); | ||||||
|  |             var now = new Date(); | ||||||
|  |             var retry_in = (date.getTime() - now.getTime()) / 1000; | ||||||
|  |             res.header({'Retry-After': retry_in}); | ||||||
|  |             res.sendStatus(429); | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  |  | ||||||
|         validateLogin(adminpass, userpass, channel_name, "add", res, function(exists) { |         validateLogin(adminpass, userpass, channel_name, "add", res, function(exists) { | ||||||
|             db.collection(channel_name).find({id: video_id}, function(err, result) { |             db.collection(channel_name).find({id: video_id}, function(err, result) { | ||||||
|                 if(result.length == 0) { |                 if(result.length == 0) { | ||||||
| @@ -307,31 +366,17 @@ router.route('/api/list/:channel_name/:video_id').post(function(req,res) { | |||||||
|                             db.collection(channel_name).insert(new_song, function(err, success) { |                             db.collection(channel_name).insert(new_song, function(err, success) { | ||||||
|                                 if(create_frontpage_lists) { |                                 if(create_frontpage_lists) { | ||||||
|                                     db.collection("frontpage_lists").insert({"_id": channel_name, "count" : 1, "frontpage": true, "accessed": Functions.get_time(), "viewers": 1}, function(err, docs) { |                                     db.collection("frontpage_lists").insert({"_id": channel_name, "count" : 1, "frontpage": true, "accessed": Functions.get_time(), "viewers": 1}, function(err, docs) { | ||||||
|                                     io.to(channel_name).emit("conf", configs); |                                         postEnd(channel_name, configs, new_song, guid, res); | ||||||
|                                     io.to(channel_name).emit("channel", {type: "added", value: new_song}); |  | ||||||
|                                     List.getNextSong(channel_name, function() { |  | ||||||
|                                         res.header({'Content-Type': 'application/json'}); |  | ||||||
|                                         res.status(200).send(JSON.stringify(new_song)); |  | ||||||
|                                         return; |  | ||||||
|                                     }); |  | ||||||
|                                     }); |                                     }); | ||||||
|                                 } else if(set_np) { |                                 } else if(set_np) { | ||||||
|                                     Frontpage.update_frontpage(channel_name, video_id, title, function() { |                                     Frontpage.update_frontpage(channel_name, video_id, title, function() { | ||||||
|                                         io.to(channel_name).emit("np", new_song); |                                         io.to(channel_name).emit("np", new_song); | ||||||
|                                     List.getNextSong(channel_name, function() { |                                         postEnd(channel_name, configs, new_song, guid, res); | ||||||
|                                         res.header({'Content-Type': 'application/json'}); |  | ||||||
|                                         res.status(200).send(JSON.stringify(new_song)); |  | ||||||
|                                         return; |  | ||||||
|                                     }); |  | ||||||
|                                     }); |                                     }); | ||||||
|                                 } else { |                                 } else { | ||||||
|                                     db.collection("frontpage_lists").update({"_id": channel_name}, {$inc: {count: 1}}, function(err, docs) { |                                     db.collection("frontpage_lists").update({"_id": channel_name}, {$inc: {count: 1}}, function(err, docs) { | ||||||
|                                         io.to(channel_name).emit("channel", {type: "added", value: new_song}); |                                         io.to(channel_name).emit("channel", {type: "added", value: new_song}); | ||||||
|                                     List.getNextSong(channel_name, function() { |                                         postEnd(channel_name, configs, new_song, guid, res); | ||||||
|                                         res.header({'Content-Type': 'application/json'}); |  | ||||||
|                                         res.status(200).send(JSON.stringify(new_song)); |  | ||||||
|                                         return; |  | ||||||
|                                     }); |  | ||||||
|                                     }); |                                     }); | ||||||
|                                 } |                                 } | ||||||
|                             }); |                             }); | ||||||
| @@ -344,6 +389,25 @@ router.route('/api/list/:channel_name/:video_id').post(function(req,res) { | |||||||
|             }); |             }); | ||||||
|         }); |         }); | ||||||
|     }); |     }); | ||||||
|  | }); | ||||||
|  |  | ||||||
|  | function postEnd(channel_name, configs, new_song, guid, res) { | ||||||
|  |     io.to(channel_name).emit("conf", configs); | ||||||
|  |     io.to(channel_name).emit("channel", {type: "added", value: new_song}); | ||||||
|  |     List.getNextSong(channel_name, function() { | ||||||
|  |         db.collection("timeout_api").update({type: "POST", guid: guid}, { | ||||||
|  |             $set: { | ||||||
|  |                 "createdAt": new Date(), | ||||||
|  |                 type: "POST", | ||||||
|  |                 guid: guid, | ||||||
|  |             }, | ||||||
|  |         }, {upsert: true}, function(err, docs) { | ||||||
|  |             res.header({'Content-Type': 'application/json'}); | ||||||
|  |             res.status(200).send(JSON.stringify(new_song)); | ||||||
|  |             return; | ||||||
|  |         }); | ||||||
|  |     }); | ||||||
|  | } | ||||||
|  |  | ||||||
| router.route('/api/list/:channel_name').get(function(req, res) { | router.route('/api/list/:channel_name').get(function(req, res) { | ||||||
|     res.header("Access-Control-Allow-Origin", "*"); |     res.header("Access-Control-Allow-Origin", "*"); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user