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,10 +77,18 @@ 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 {
|
||||||
return;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
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") {
|
||||||
|
|||||||
@@ -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) {
|
||||||
Crypt.tmp_pass = pass;
|
if(userpass) {
|
||||||
|
Crypt.tmp_pass_user = pass;
|
||||||
|
} else {
|
||||||
|
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,52 +147,73 @@ router.route('/api/conf/:channel_name').put(function(req, res) {
|
|||||||
res.sendStatus(400);
|
res.sendStatus(400);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
db.collection("timeout_api").find({
|
||||||
validateLogin(adminpass, userpass, channel_name, "config", res, function(exists) {
|
type: "DELETE",
|
||||||
if(!exists) {
|
guid: guid,
|
||||||
res.sendStatus(404);
|
}, 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;
|
return;
|
||||||
}
|
}
|
||||||
|
validateLogin(adminpass, userpass, channel_name, "config", res, function(exists) {
|
||||||
|
if(!exists) {
|
||||||
|
res.sendStatus(404);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if((!userpass_changed && frontpage) || (userpass_changed && userpass == "")) {
|
if((!userpass_changed && frontpage) || (userpass_changed && userpass == "")) {
|
||||||
userpass = "";
|
userpass = "";
|
||||||
} else if(userpass_changed && userpass != "") {
|
} else if(userpass_changed && userpass != "") {
|
||||||
frontpage = false;
|
frontpage = false;
|
||||||
}
|
}
|
||||||
var description = "";
|
var description = "";
|
||||||
|
|
||||||
var obj = {
|
var obj = {
|
||||||
addsongs:addsongs,
|
addsongs:addsongs,
|
||||||
allvideos:allvideos,
|
allvideos:allvideos,
|
||||||
frontpage:frontpage,
|
frontpage:frontpage,
|
||||||
skip:skipping,
|
skip:skipping,
|
||||||
vote:voting,
|
vote:voting,
|
||||||
removeplay:removeplay,
|
removeplay:removeplay,
|
||||||
shuffle:shuffling,
|
shuffle:shuffling,
|
||||||
longsongs:longsongs,
|
longsongs:longsongs,
|
||||||
adminpass:adminpass,
|
adminpass:adminpass,
|
||||||
desc: description,
|
desc: description,
|
||||||
};
|
};
|
||||||
if(userpass_changed) {
|
if(userpass_changed) {
|
||||||
obj["userpass"] = userpass;
|
obj["userpass"] = userpass;
|
||||||
} else if (frontpage) {
|
} else if (frontpage) {
|
||||||
obj["userpass"] = "";
|
obj["userpass"] = "";
|
||||||
}
|
}
|
||||||
db.collection(channel_name + "_settings").update({views:{$exists:true}}, {
|
db.collection(channel_name + "_settings").update({views:{$exists:true}}, {
|
||||||
$set:obj
|
$set:obj
|
||||||
}, function(err, docs){
|
}, function(err, docs){
|
||||||
|
|
||||||
if(obj.adminpass !== "") obj.adminpass = true;
|
if(obj.adminpass !== "") obj.adminpass = true;
|
||||||
if(obj.hasOwnProperty("userpass") && obj.userpass != "") obj.userpass = true;
|
if(obj.hasOwnProperty("userpass") && obj.userpass != "") obj.userpass = true;
|
||||||
else obj.userpass = false;
|
else obj.userpass = false;
|
||||||
io.to(channel_name).emit("conf", [obj]);
|
io.to(channel_name).emit("conf", [obj]);
|
||||||
|
|
||||||
db.collection("frontpage_lists").update({_id: channel_name}, {$set:{
|
db.collection("frontpage_lists").update({_id: channel_name}, {$set:{
|
||||||
frontpage:frontpage, accessed: Functions.get_time()}
|
frontpage:frontpage, accessed: Functions.get_time()}
|
||||||
},
|
},
|
||||||
{upsert:true}, function(err, docs){
|
{upsert:true}, function(err, docs){
|
||||||
res.header({'Content-Type': 'application/json'});
|
db.collection("timeout_api").update({type: "DELETE", guid: guid}, {
|
||||||
res.status(200).send(JSON.stringify(obj));
|
$set: {
|
||||||
|
"createdAt": new Date(),
|
||||||
|
type: "DELETE",
|
||||||
|
guid: guid,
|
||||||
|
},
|
||||||
|
}, {upsert: true}, function(err, docs) {
|
||||||
|
res.header({'Content-Type': 'application/json'});
|
||||||
|
res.status(200).send(JSON.stringify(obj));
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -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,31 +245,54 @@ router.route('/api/list/:channel_name/:video_id').put(function(req,res) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
validateLogin(adminpass, userpass, channel_name, "vote", res, function(exists) {
|
db.collection("timeout_api").find({
|
||||||
if(!exists) {
|
type: "PUT",
|
||||||
res.sendStatus(404);
|
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;
|
return;
|
||||||
}
|
}
|
||||||
db.collection(channel_name).find({id: video_id, now_playing: false}, function(err, song) {
|
|
||||||
if(song.length == 0) {
|
validateLogin(adminpass, userpass, channel_name, "vote", res, function(exists) {
|
||||||
|
if(!exists) {
|
||||||
res.sendStatus(404);
|
res.sendStatus(404);
|
||||||
return;
|
return;
|
||||||
} else if(song[0].guids.indexOf(guid) > -1) {
|
|
||||||
res.sendStatus(409);
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
song[0].votes += 1;
|
|
||||||
song[0].guids.push(guid);
|
|
||||||
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()});
|
|
||||||
List.getNextSong(channel_name, function() {
|
|
||||||
res.header({'Content-Type': 'application/json'});
|
|
||||||
res.status(200).send(JSON.stringify(song[0]));
|
|
||||||
return;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
})
|
db.collection(channel_name).find({id: video_id, now_playing: false}, function(err, song) {
|
||||||
|
if(song.length == 0) {
|
||||||
|
res.sendStatus(404);
|
||||||
|
return;
|
||||||
|
} else if(song[0].guids.indexOf(guid) > -1) {
|
||||||
|
res.sendStatus(409);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
song[0].votes += 1;
|
||||||
|
song[0].guids.push(guid);
|
||||||
|
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()});
|
||||||
|
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.status(200).send(JSON.stringify(song[0]));
|
||||||
|
return;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -284,67 +329,86 @@ router.route('/api/list/:channel_name/:video_id').post(function(req,res) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
validateLogin(adminpass, userpass, channel_name, "add", res, function(exists) {
|
db.collection("timeout_api").find({
|
||||||
db.collection(channel_name).find({id: video_id}, function(err, result) {
|
type: "POST",
|
||||||
if(result.length == 0) {
|
guid: guid,
|
||||||
db.collection(channel_name).find({now_playing: true}, function(err, now_playing) {
|
}, function(err, docs) {
|
||||||
var set_np = false;
|
if(docs.length > 0) {
|
||||||
if(now_playing.length == 0) {
|
var date = new Date(docs[0].createdAt);
|
||||||
set_np = true;
|
date.setSeconds(date.getSeconds() + 5);
|
||||||
}
|
var now = new Date();
|
||||||
var new_song = {"added": Functions.get_time(),"guids":[guid],"id":video_id,"now_playing":set_np,"title":title,"votes":1, "duration":duration, "start": parseInt(start_time), "end": parseInt(end_time)};
|
var retry_in = (date.getTime() - now.getTime()) / 1000;
|
||||||
db.collection("frontpage_lists").find({"_id": channel_name}, function(err, count) {
|
res.header({'Retry-After': retry_in});
|
||||||
var create_frontpage_lists = false;
|
res.sendStatus(429);
|
||||||
if(count.length == 0) {
|
return;
|
||||||
create_frontpage_lists = true;
|
}
|
||||||
|
|
||||||
|
validateLogin(adminpass, userpass, channel_name, "add", res, function(exists) {
|
||||||
|
db.collection(channel_name).find({id: video_id}, function(err, result) {
|
||||||
|
if(result.length == 0) {
|
||||||
|
db.collection(channel_name).find({now_playing: true}, function(err, now_playing) {
|
||||||
|
var set_np = false;
|
||||||
|
if(now_playing.length == 0) {
|
||||||
|
set_np = true;
|
||||||
}
|
}
|
||||||
if(!exists) {
|
var new_song = {"added": Functions.get_time(),"guids":[guid],"id":video_id,"now_playing":set_np,"title":title,"votes":1, "duration":duration, "start": parseInt(start_time), "end": parseInt(end_time)};
|
||||||
var configs = {"addsongs":false, "adminpass":"", "allvideos":true, "frontpage":true, "longsongs":false, "removeplay": false, "shuffle": true, "skip": false, "skips": [], "startTime":Functions.get_time(), "views": [], "vote": false, "desc": ""};
|
db.collection("frontpage_lists").find({"_id": channel_name}, function(err, count) {
|
||||||
db.collection(channel_name + "_settings").insert(configs, function(err, docs){
|
var create_frontpage_lists = false;
|
||||||
io.to(channel_name).emit("conf", configs);
|
if(count.length == 0) {
|
||||||
});
|
create_frontpage_lists = true;
|
||||||
}
|
}
|
||||||
db.collection(channel_name).insert(new_song, function(err, success) {
|
if(!exists) {
|
||||||
if(create_frontpage_lists) {
|
var configs = {"addsongs":false, "adminpass":"", "allvideos":true, "frontpage":true, "longsongs":false, "removeplay": false, "shuffle": true, "skip": false, "skips": [], "startTime":Functions.get_time(), "views": [], "vote": false, "desc": ""};
|
||||||
db.collection("frontpage_lists").insert({"_id": channel_name, "count" : 1, "frontpage": true, "accessed": Functions.get_time(), "viewers": 1}, function(err, docs) {
|
db.collection(channel_name + "_settings").insert(configs, function(err, docs){
|
||||||
io.to(channel_name).emit("conf", configs);
|
io.to(channel_name).emit("conf", configs);
|
||||||
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) {
|
|
||||||
Frontpage.update_frontpage(channel_name, video_id, title, function() {
|
|
||||||
io.to(channel_name).emit("np", new_song);
|
|
||||||
List.getNextSong(channel_name, function() {
|
|
||||||
res.header({'Content-Type': 'application/json'});
|
|
||||||
res.status(200).send(JSON.stringify(new_song));
|
|
||||||
return;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
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});
|
|
||||||
List.getNextSong(channel_name, function() {
|
|
||||||
res.header({'Content-Type': 'application/json'});
|
|
||||||
res.status(200).send(JSON.stringify(new_song));
|
|
||||||
return;
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
db.collection(channel_name).insert(new_song, function(err, success) {
|
||||||
|
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) {
|
||||||
|
postEnd(channel_name, configs, new_song, guid, res);
|
||||||
|
});
|
||||||
|
} else if(set_np) {
|
||||||
|
Frontpage.update_frontpage(channel_name, video_id, title, function() {
|
||||||
|
io.to(channel_name).emit("np", new_song);
|
||||||
|
postEnd(channel_name, configs, new_song, guid, res);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
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});
|
||||||
|
postEnd(channel_name, configs, new_song, guid, res);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
} else {
|
||||||
} else {
|
res.sendStatus(409);
|
||||||
res.sendStatus(409);
|
return;
|
||||||
return;
|
}
|
||||||
}
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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", "*");
|
||||||
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");
|
||||||
|
|||||||
Reference in New Issue
Block a user