Updating channel to fetch prettier

This commit is contained in:
Kasper Rynning-Tønnesen
2018-03-12 19:17:01 +01:00
parent 1d7331cb86
commit 3f0f8eb5d9
14 changed files with 196 additions and 57 deletions

View File

@@ -202,7 +202,7 @@ var Admin = {
removeplay = form.removeplay.checked;
skipping = form.skip.checked;
shuffling = form.shuffle.checked;
var pass_send = userpass == '' ? userpass : CryptoJS.SHA256(userpass).toString();
var pass_send = userpass_changed && !form.userpass.checked ? "" : userpass;
configs = {
channel: chan.toLowerCase(),
voting: voting,
@@ -218,7 +218,7 @@ var Admin = {
userpass_changed: userpass_changed
};
if(userpass_changed){
Crypt.set_userpass(chan.toLowerCase(), CryptoJS.SHA256(userpass).toString());
Crypt.set_userpass(chan.toLowerCase(), userpass);
}
emit("conf", configs);
},

View File

@@ -243,36 +243,11 @@ var Channel = {
if(!client) {
setup_chat_listener();
get_history();
//console.log(Crypt.get_userpass(chan.toLowerCase()));
} else {
var c = Crypt.get_userpass(chan.toLowerCase());
if(c == "" || c == undefined) {
c = "";
}
$.ajax({
type: "POST",
data: {
userpass: c,
},
url: "/api/list/" + chan.toLowerCase(),
success: function(response) {
if(response.results.length > 0) {
$("#channel-load").remove();
if(response.status == 403) {
start_auth();
}
$("#channel-load").remove();
List.populate_list(response.results);
}
},
error: function(response) {
if(response.responseJSON.status == 403) {
start_auth();
}
$("#channel-load").remove();
//List.populate_list(response.responseJSON.results);
}
});
}
if(client || Helper.mobilecheck()){
get_list_ajax();
get_np_ajax();
}
if(!Helper.msieversion() && !Helper.mobilecheck() && !client) Notification.requestPermission();

View File

@@ -160,6 +160,150 @@ function emit_list() {
}
}
function get_list_ajax() {
var c = Crypt.get_userpass(chan.toLowerCase());
if(c == "" || c == undefined) {
c = "";
}
$.ajax({
type: "POST",
data: {
userpass: c,
},
url: "/api/list/" + chan.toLowerCase(),
success: function(response) {
if(response.results.length > 0) {
$("#channel-load").remove();
if(response.status == 403) {
start_auth();
}
$("#channel-load").remove();
List.populate_list(response.results);
}
},
error: function(response) {
if(response.responseJSON.status == 403) {
start_auth();
} else if(response.responseJSON.status == 429) {
setTimeout(function() {
get_list_ajax();
}, response.getResponseHeader("Retry-After") * 1000)
}
$("#channel-load").remove();
//List.populate_list(response.responseJSON.results);
}
});
}
function get_np_ajax() {
var c = Crypt.get_userpass(chan.toLowerCase());
$.ajax({
type: "POST",
data: {
userpass: c,
fetch_song: true
},
url: "/api/list/" + chan.toLowerCase() + "/__np__",
success: function(response) {
Player.getTitle(response.results[0].title, 1);
},
error: function(response) {
if(response.responseJSON.status == 403) {
start_auth();
} else if(response.responseJSON.status == 429) {
setTimeout(function() {
get_np_ajax();
}, response.getResponseHeader("Retry-After") * 1000)
}
}
})
}
function del_ajax(id) {
var a = Crypt.get_pass(chan.toLowerCase());
var u = Crypt.get_userpass(chan.toLowerCase());
if(a == undefined) a = "";
if(u == undefined) u = "";
$.ajax({
type: "DELETE",
data: {
adminpass: a,
userpass: u
},
url: "/api/list/" + chan.toLowerCase() + "/" + id,
success: function(response) {
toast("deletesong");
},
error: function(response) {
if(response.responseJSON.status == 403) {
start_auth();
} else if(response.responseJSON.status == 429) {
setTimeout(function() {
vote_ajax(id);
}, response.getResponseHeader("Retry-After") * 1000);
}
}
})
}
function add_ajax(id, title, duration, playlist, num, full_num, start, end) {
var a = Crypt.get_pass(chan.toLowerCase());
var u = Crypt.get_userpass(chan.toLowerCase());
if(a == undefined) a = "";
if(u == undefined) u = "";
$.ajax({
type: "POST",
data: {
adminpass: a,
userpass: u,
title: title,
duration: duration,
end_time: end,
start_time: start,
},
url: "/api/list/" + chan.toLowerCase() + "/" + id,
success: function(response) {
toast("addedsong");
},
error: function(response) {
if(response.responseJSON.status == 409) {
vote_ajax(id);
} else if(response.responseJSON.status == 429) {
setTimeout(function() {
add_ajax(id, title, duration, playlist, num, full_num, start, end);
}, response.getResponseHeader("Retry-After") * 1000);
}
}
});
}
function vote_ajax(id) {
var a = Crypt.get_pass(chan.toLowerCase());
var u = Crypt.get_userpass(chan.toLowerCase());
if(a == undefined) a = "";
if(u == undefined) u = "";
$.ajax({
type: "PUT",
data: {
adminpass: a,
userpass: u
},
url: "/api/list/" + chan.toLowerCase() + "/" + id,
success: function(response) {
toast("voted");
},
error: function(response) {
if(response.responseJSON.status == 403) {
start_auth();
} else if(response.responseJSON.status == 429) {
setTimeout(function() {
vote_ajax(id);
}, response.getResponseHeader("Retry-After") * 1000);
}
}
})
}
function setup_auth_listener() {
socket.on('auth_required', function() {
start_auth();
@@ -288,6 +432,10 @@ function embed_code(autoplay, width, height, color, embed_code){
}
function change_offline(enabled, already_offline){
if(client) {
offline = false;
return;
}
Crypt.set_offline(enabled);
offline = enabled;
ga('send', 'event', "button-click", "offline", "", offline ? 1 : 0);

View File

@@ -554,6 +554,14 @@ var List = {
},
vote: function(id, vote) {
if(client && !socket.connected) {
if(vote != "del") {
vote_ajax(id);
} else {
del_ajax(id);
}
return;
}
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()), true)});
} else {

View File

@@ -572,7 +572,7 @@ $(document).on("change", ".password_protected", function(e) {
$(document).on("submit", "#user-password-channel-form", function(e) {
e.preventDefault();
if(user_auth_started) {
temp_user_pass = CryptoJS.SHA256($("#user-pass-input").val()).toString();
temp_user_pass = $("#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)});
@@ -595,7 +595,7 @@ $(document).on("click", ".change_user_pass_btn", function(e) {
$(document).on("click", ".submit-user-password", function(e) {
e.preventDefault();
if(user_auth_started) {
temp_user_pass = CryptoJS.SHA256($("#user-pass-input").val()).toString();
temp_user_pass = $("#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)});
} else {

View File

@@ -436,6 +436,10 @@ var Search = {
},
submit: function(id,title,duration, playlist, num, full_num, start, end){
if(client && !socket.connected) {
add_ajax(id, title, duration, playlist, num, full_num, start, end);
return;
}
if(offline && document.getElementsByName("addsongs")[0].checked && document.getElementsByName("addsongs")[0].disabled){
var found_array = [];
found_array = $.map(full_playlist, function(obj, index) {