Multi-word channel-names and API-fixes

- Spaces and signs allowed in channel-name
- Added missing functioncalls in RESTApi
This commit is contained in:
Kasper Rynning-Tønnesen
2018-05-31 14:45:21 +02:00
parent ea8fedbe46
commit 9d10397fe5
19 changed files with 275 additions and 137 deletions

View File

@@ -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");

View File

@@ -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) {}
};

View File

@@ -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();

View File

@@ -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(/&amp;/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);
}
}
};

View File

@@ -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);