mirror of
https://github.com/KevinMidboe/zoff.git
synced 2025-12-08 04:28:49 +00:00
Multi-word channel-names and API-fixes
- Spaces and signs allowed in channel-name - Added missing functioncalls in RESTApi
This commit is contained in:
@@ -28,13 +28,20 @@ $(document).on("click", "#refresh_all", function(e){
|
||||
socket.emit("get_spread");
|
||||
});
|
||||
|
||||
function decodeChannelName(str) {
|
||||
var _fn = decodeURIComponent;
|
||||
str = str.toUpperCase();
|
||||
var toReturn = _fn(str.replace(/%5F/g, "_"));
|
||||
return toReturn.toLowerCase();
|
||||
}
|
||||
|
||||
socket.on("spread_listeners", function(obj){
|
||||
$("#listeners").append("<p>Private listeners: " + obj.offline + "</p>");
|
||||
$("#listeners").append("<p>Total listeners: " + obj.total + "</p>");
|
||||
$("#listeners").append("<hr>");
|
||||
for(var x in obj.online_users){
|
||||
if(obj.online_users[x]._id != "total_users" && obj.online_users[x].hasOwnProperty("users") && obj.online_users[x].users.length > 0){
|
||||
$("#listeners").append("<p>" + obj.online_users[x]._id + ": " + obj.online_users[x].users.length + "</p>");
|
||||
$("#listeners").append("<p>" + decodeChannelName(obj.online_users[x]._id) + ": " + obj.online_users[x].users.length + "</p>");
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -144,9 +151,9 @@ function loaded() {
|
||||
var output_delete = '<option value="" disabled selected>Channels</option>';
|
||||
for(var x = 0; x < response.length; x++){
|
||||
if(response[x].count > 2){
|
||||
output_pinned += "<option class='" + response[x]._id + "' value='" + response[x]._id + "'>" + response[x]._id + "</option>";
|
||||
output_pinned += "<option class='" + response[x]._id + "' value='" + response[x]._id + "'>" + decodeChannelName(response[x]._id) + "</option>";
|
||||
}
|
||||
output_delete += "<option class='" + response[x]._id + "' value='" + response[x]._id + "'>" + response[x]._id + "</option>";
|
||||
output_delete += "<option class='" + response[x]._id + "' value='" + response[x]._id + "'>" + decodeChannelName(response[x]._id) + "</option>";
|
||||
}
|
||||
|
||||
$("#frontpage_pinned").html(output_pinned);
|
||||
@@ -232,9 +239,9 @@ $(document).on("click", ".thumbnail_link", function(e) {
|
||||
function add_to_tab(dest, resp){
|
||||
for(var x = 0; x < resp.length; x++){
|
||||
if(dest == "thumbnails"){
|
||||
$("#" + dest + "_cont").append("<div><div class='col s4 m3'>" + resp[x].channel + "</div><input type='text' readonly class='col s4 m6 thumbnail_link' value='" + resp[x].thumbnail + "'><a class='btn green waves-effect col s2 m1 approve_" + dest + "' href='#' data-channel='" + resp[x].channel + "'><i class='material-icons'>check</i></a><a class='btn red waves-effect col s2 m1 deny_" + dest + "' href='#' data-channel='" + resp[x].channel + "'>X</a></div>");
|
||||
$("#" + dest + "_cont").append("<div><div class='col s4 m3'>" + decodeChannelName(resp[x].channel) + "</div><input type='text' readonly class='col s4 m6 thumbnail_link' value='" + resp[x].thumbnail + "'><a class='btn green waves-effect col s2 m1 approve_" + dest + "' href='#' data-channel='" + resp[x].channel + "'><i class='material-icons'>check</i></a><a class='btn red waves-effect col s2 m1 deny_" + dest + "' href='#' data-channel='" + resp[x].channel + "'>X</a></div>");
|
||||
} else {
|
||||
$("#" + dest + "_cont").append("<div><div class='col s4 m3'>" + resp[x].channel + "</div><input type='text' readonly class='col s4 m6' value='" + resp[x].description + "'><a class='btn green waves-effect col s2 m1 approve_" + dest + "' href='#' data-channel='" + resp[x].channel + "'><i class='material-icons'>check</i></a><a class='btn red waves-effect col s2 m1 deny_" + dest + "' href='#' data-channel='" + resp[x].channel + "'>X</a></div>");
|
||||
$("#" + dest + "_cont").append("<div><div class='col s4 m3'>" + decodeChannelName(resp[x].channel) + "</div><input type='text' readonly class='col s4 m6' value='" + resp[x].description + "'><a class='btn green waves-effect col s2 m1 approve_" + dest + "' href='#' data-channel='" + resp[x].channel + "'><i class='material-icons'>check</i></a><a class='btn red waves-effect col s2 m1 deny_" + dest + "' href='#' data-channel='" + resp[x].channel + "'>X</a></div>");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -433,7 +440,7 @@ $(document).on("submit", "#delete_channel", function(e){
|
||||
Materialize.toast("Something went wrong...", 2000, "red lighten");
|
||||
return;
|
||||
}
|
||||
var r = confirm("Delete list " + to_delete + "?");
|
||||
var r = confirm("Delete list \""+ decodeChannelName(to_delete) + "\"?");
|
||||
if (r == true) {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
@@ -443,26 +450,7 @@ $(document).on("submit", "#delete_channel", function(e){
|
||||
},
|
||||
success: function(response){
|
||||
if(response == true){
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: "/api/lists",
|
||||
success: function(response){
|
||||
var output_pinned = "";
|
||||
var output_delete = "";
|
||||
for(var x = 0; x < response.length; x++){
|
||||
if(response[x].count > 5){
|
||||
output_pinned += "<option class='" + response[x]._id + "' value='" + response[x]._id + "'>" + response[x]._id + "</option>";
|
||||
}
|
||||
output_delete += "<option class='" + response[x]._id + "' value='" + response[x]._id + "'>" + response[x]._id + "</option>";
|
||||
}
|
||||
|
||||
$("#frontpage_pinned").html(output_pinned);
|
||||
$("#delete_list_name").html(output_delete);
|
||||
$("#delete_userpass_name").html(output_delete);
|
||||
$("#delete_channel_name").html(output_delete);
|
||||
$("select").material_select();
|
||||
}
|
||||
});
|
||||
loaded();
|
||||
Materialize.toast("Deleted channel!", 2000, "green lighten");
|
||||
} else {
|
||||
Materialize.toast("Something went wrong...", 2000, "red lighten");
|
||||
|
||||
@@ -27,7 +27,9 @@ var Channel = {
|
||||
number_suggested = 0;
|
||||
var no_socket = true;
|
||||
|
||||
chan = Helper.html("#chan");
|
||||
chan = Helper.decodeChannelName(Helper.html("#chan"));
|
||||
console.log(chan);
|
||||
console.log(Helper.decodeChannelName(chan));
|
||||
mobile_beginning = Helper.mobilecheck();
|
||||
var side = Helper.mobilecheck() ? "left" : "right";
|
||||
|
||||
@@ -185,9 +187,9 @@ var Channel = {
|
||||
|
||||
|
||||
if(!client) {
|
||||
var shareCodeUrl = window.location.protocol + "//client."+window.location.hostname+"/"+chan.toLowerCase();
|
||||
var shareCodeUrl = window.location.protocol + "//client."+window.location.hostname+"/"+encodeURIComponent(chan.toLowerCase());
|
||||
document.getElementById("share-join-qr").setAttribute("src", "https://chart.googleapis.com/chart?chs=221x221&cht=qr&choe=UTF-8&chld=L|1&chl="+shareCodeUrl);
|
||||
Helper.setHtml("#channel-name-join", "client." + window.location.hostname + "/" + chan.toLowerCase());
|
||||
Helper.setHtml("#channel-name-join", "client." + window.location.hostname + "/" + encodeURIComponent(chan.toLowerCase()));
|
||||
} else {
|
||||
Helper.removeElement(".video-container");
|
||||
Helper.removeElement(".offline-panel");
|
||||
|
||||
@@ -72,7 +72,8 @@ var Frontpage = {
|
||||
]);
|
||||
|
||||
for(var x in lists) {
|
||||
var chan = lists[x]._id;
|
||||
//console.log(lists[x]._id);
|
||||
var chan = Helper.decodeChannelName(lists[x]._id);
|
||||
if(num<12 || !popular) {
|
||||
var id = lists[x].id;
|
||||
var viewers = lists[x].viewers;
|
||||
@@ -126,7 +127,7 @@ var Frontpage = {
|
||||
options_list = options_list.sort(Frontpage.sortFunction_active);
|
||||
var data = {};
|
||||
for(var x in options_list) {
|
||||
data[options_list[x]._id] = null;
|
||||
data[Helper.decodeChannelName(options_list[x]._id)] = null;
|
||||
}
|
||||
if(document.querySelectorAll(".pin").length == 1 && !Helper.mobilecheck()) {
|
||||
Helper.tooltip(document.querySelectorAll(".pin")[0].parentElement.parentElement.parentElement, {
|
||||
@@ -206,7 +207,7 @@ var Frontpage = {
|
||||
Helper.css("#mega-background","background-size" , "cover");
|
||||
Helper.css("#mega-background","background-repeat" , "no-repeat");
|
||||
Helper.css("#mega-background","opacity", 1);
|
||||
document.querySelector(".autocomplete").setAttribute("placeholder", list[i]._id);
|
||||
document.querySelector(".autocomplete").setAttribute("placeholder", Helper.decodeChannelName(list[i]._id));
|
||||
//$(".room-namer").css("opacity", 1);
|
||||
}
|
||||
},500);
|
||||
@@ -231,12 +232,12 @@ var Frontpage = {
|
||||
Helper.css("#mega-background", "background-size" , "cover");
|
||||
Helper.css("#mega-background", "background-repeat" , "no-repeat");
|
||||
Helper.css("#mega-background", "opacity", 1);
|
||||
document.querySelector(".autocomplete").setAttribute("placeholder", list[i]._id);
|
||||
document.querySelector(".autocomplete").setAttribute("placeholder", Helper.decodeChannelName(list[i]._id));
|
||||
} catch(e) {}
|
||||
},500);
|
||||
},
|
||||
error: function() {
|
||||
document.querySelector(".autocomplete").setAttribute("placeholder", list[i]._id);
|
||||
document.querySelector(".autocomplete").setAttribute("placeholder", Helper.decodeChannelName(list[i]._id));
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -246,7 +247,7 @@ var Frontpage = {
|
||||
Helper.css("#mega-background", "background-size" , "cover");
|
||||
Helper.css("#mega-background", "background-repeat" , "no-repeat");
|
||||
Helper.css("#mega-background", "opacity", 1);
|
||||
document.querySelector(".autocomplete").setAttribute("placeholder", list[i]._id);
|
||||
document.querySelector(".autocomplete").setAttribute("placeholder", Helper.decodeChannelName(list[i]._id));
|
||||
} catch(e) {}
|
||||
};
|
||||
|
||||
|
||||
@@ -195,7 +195,7 @@ function get_list_ajax() {
|
||||
token: zoff_api_token,
|
||||
},
|
||||
headers: {"Content-Type": "application/json;charset=UTF-8"},
|
||||
url: "/api/list/" + chan.toLowerCase(),
|
||||
url: "/api/list/" + Helper.encodeChannelName(chan.toLowerCase()),
|
||||
success: function(response) {
|
||||
response = JSON.parse(response);
|
||||
if(response.results.length > 0) {
|
||||
@@ -283,7 +283,7 @@ function get_np_ajax() {
|
||||
token: zoff_api_token
|
||||
},
|
||||
headers: {"Content-Type": "application/json;charset=UTF-8"},
|
||||
url: "/api/list/" + chan.toLowerCase() + "/__np__",
|
||||
url: "/api/list/" + Helper.encodeChannelName(chan.toLowerCase()) + "/__np__",
|
||||
success: function(response) {
|
||||
response = JSON.parse(response);
|
||||
Player.getTitle(response.results[0].title, 1);
|
||||
@@ -314,7 +314,7 @@ function del_ajax(id) {
|
||||
token: zoff_api_token
|
||||
},
|
||||
headers: {"Content-Type": "application/json;charset=UTF-8"},
|
||||
url: "/api/list/" + chan.toLowerCase() + "/" + id,
|
||||
url: "/api/list/" + Helper.encodeChannelName(chan.toLowerCase()) + "/" + id,
|
||||
success: function(response) {
|
||||
toast("deletesong");
|
||||
get_list_ajax();
|
||||
@@ -351,7 +351,7 @@ function add_ajax(id, title, duration, playlist, num, full_num, start, end, sour
|
||||
token: zoff_api_token
|
||||
},
|
||||
headers: {"Content-Type": "application/json;charset=UTF-8"},
|
||||
url: "/api/list/" + chan.toLowerCase() + "/" + id,
|
||||
url: "/api/list/" + Helper.encodeChannelName(chan.toLowerCase()) + "/" + id,
|
||||
success: function(response) {
|
||||
toast("addedsong");
|
||||
get_list_ajax();
|
||||
@@ -384,7 +384,7 @@ function vote_ajax(id) {
|
||||
token: zoff_api_token
|
||||
},
|
||||
headers: {"Content-Type": "application/json;charset=UTF-8"},
|
||||
url: "/api/list/" + chan.toLowerCase() + "/" + id,
|
||||
url: "/api/list/" + Helper.encodeChannelName(chan.toLowerCase()) + "/" + id,
|
||||
success: function(response) {
|
||||
toast("voted");
|
||||
get_list_ajax();
|
||||
|
||||
@@ -1,5 +1,23 @@
|
||||
var Helper = {
|
||||
logs: [],
|
||||
|
||||
decodeChannelName: function(str) {
|
||||
var _fn = decodeURIComponent;
|
||||
str = str.toUpperCase();
|
||||
var toReturn = _fn(str.replace(/%5F/g, "_"));
|
||||
toReturn = toReturn.toLowerCase().replace(/&/g, "&");
|
||||
return toReturn.toLowerCase();
|
||||
},
|
||||
|
||||
encodeChannelName: function(str) {
|
||||
var _fn = encodeURIComponent;
|
||||
var toReturn = _fn(str);
|
||||
toReturn = toReturn.replace(/_/g, "%5F");
|
||||
toReturn = toReturn.replace(/%26amp%3B/g, "%26").replace(/%26amp%3b/g, "%26");
|
||||
toReturn = toReturn.toLowerCase();
|
||||
return toReturn;
|
||||
},
|
||||
|
||||
log: function(to_log) {
|
||||
if(localStorage.debug === "true") {
|
||||
console.log("------------ " + new Date() + " ------------");/*RemoveLogging:skip*/
|
||||
@@ -315,12 +333,12 @@ var Helper = {
|
||||
var xmlhttp = new XMLHttpRequest();
|
||||
xmlhttp.onreadystatechange = function() {
|
||||
if (xmlhttp.readyState == XMLHttpRequest.DONE) { // XMLHttpRequest.DONE == 4
|
||||
if (xmlhttp.status == 200 || xmlhttp.status == 201 || xmlhttp.status == 202) {
|
||||
obj.success(xmlhttp.responseText, xmlhttp);
|
||||
}
|
||||
else if(obj.hasOwnProperty("error")){
|
||||
obj.error(xmlhttp);
|
||||
}
|
||||
if (xmlhttp.status == 200 || xmlhttp.status == 201 || xmlhttp.status == 202) {
|
||||
obj.success(xmlhttp.responseText, xmlhttp);
|
||||
}
|
||||
else if(obj.hasOwnProperty("error")){
|
||||
obj.error(xmlhttp);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -76,6 +76,7 @@ var Player = {
|
||||
if(obj.np != undefined && !offline) {
|
||||
seekTo = (time - conf.startTime) + Player.np.start;
|
||||
Player.getTitle(song_title, viewers);
|
||||
Player.setThumbnail(conf, Player.np.id);
|
||||
if(((embed && autoplay) || !embed) && (!was_stopped || buffering) && !client) {
|
||||
Helper.log(["loadVideoById \nwas_stopped="+was_stopped+"\noffline="+offline])
|
||||
Player.loadVideoById(Player.np.id, duration, Player.np.start, Player.np.end);
|
||||
|
||||
Reference in New Issue
Block a user