Moved oauth callback to /api/oauth and embed to /api/embed, with utilizing the search in url

This commit is contained in:
Kasper Rynning-Tønnesen
2018-10-07 12:48:41 +02:00
parent 5333b4bc13
commit 2e8da96706
6 changed files with 85 additions and 48 deletions

View File

@@ -1,6 +1,6 @@
window.addEventListener("load", function() { window.addEventListener("load", function() {
var query = getQueryHash(window.location.hash); var query = getQueryHash(window.location.hash);
var redirect = window.location.protocol + "//" + window.location.hostname + "/o_callback"; var redirect = window.location.protocol + "//" + window.location.hostname + "/api/oauth";
var client_id; var client_id;
var response; var response;
var scope; var scope;

View File

@@ -52,10 +52,12 @@ var began = false;
var seekTo; var seekTo;
var socket; var socket;
var video_id; var video_id;
var hash = window.location.hash.substring(1).split("&"); var embedOptions = getSearch(window.location.search);
var chan = Helper.decodeChannelName(hash[0]); var chan = Helper.decodeChannelName(embedOptions["channel"]);
var autoplay = false; var autoplay = embedOptions["autoplay"];
var color = "#808080"; var videoonly = embedOptions["videoonly"];
var color = "#" + embedOptions["color"];
var localmode = embedOptions["localmode"];
var dragging = false; var dragging = false;
var user_auth_started = false; var user_auth_started = false;
var user_auth_avoid = false; var user_auth_avoid = false;
@@ -98,14 +100,26 @@ window.addEventListener("message", receiveMessage, false);
window.addEventListener("DOMContentLoaded", function() { window.addEventListener("DOMContentLoaded", function() {
}); });
window.addEventListener("load", function() {
if(hash.length >= 2 && hash.indexOf("autoplay") > 0){ function getSearch(elem) {
autoplay = true; var result = {};
Helper.css("#player", "visibility", "hidden"); var search = window.location.search.split("&");
} else { for(var i = 0; i < search.length; i++) {
//paused = true; var currElement = search[i].split("=");
var key = currElement[0].replace("?", "");
var value = currElement[1];
if(value == "true") value = true;
else if(value == "false") value = false;
result[key] = value;
} }
if(hash.indexOf("videoonly") > -1) { return result;
}
window.addEventListener("load", function() {
if(autoplay){
Helper.css("#player", "visibility", "hidden");
}
if(videoonly) {
Helper.addClass("#wrapper", "hide"); Helper.addClass("#wrapper", "hide");
Helper.addClass("#controls", "hide"); Helper.addClass("#controls", "hide");
Helper.addClass("#player", "video_only"); Helper.addClass("#player", "video_only");
@@ -116,13 +130,13 @@ window.addEventListener("load", function() {
M.Modal.init(document.getElementById("locked_channel"), { M.Modal.init(document.getElementById("locked_channel"), {
dismissible: false dismissible: false
}); });
color = "#" + hash[1];
add = "https://zoff.me"; add = "https://zoff.me";
//if(window.location.hostname == "localhost") add = "localhost"; //if(window.location.hostname == "localhost") add = "localhost";
//add = "localhost"; //add = "localhost";
socket = io.connect(''+add+':8080', connection_options); socket = io.connect(''+add+':8080', connection_options);
if(hash.indexOf("localmode") > 1) { if(localmode) {
change_offline(true, false); change_offline(true, false);
} }
@@ -170,7 +184,7 @@ window.addEventListener("load", function() {
//Helper.css("#controls", "background-color", color); //Helper.css("#controls", "background-color", color);
document.querySelector("body").style.backgroundColor = color; document.querySelector("body").style.backgroundColor = color;
if(hash.indexOf("controll") > -1) { if(embedOptions.hasOwnProperty("control") && embedOptions.control) {
Hostcontroller.change_enabled(true); Hostcontroller.change_enabled(true);
} else { } else {
Hostcontroller.change_enabled(false); Hostcontroller.change_enabled(false);

View File

@@ -797,7 +797,7 @@ function disable_debug(){
function embed_code(autoplay, width, height, color, embed_videoonly, embed_localmode){ function embed_code(autoplay, width, height, color, embed_videoonly, embed_localmode){
var autoplay_add = ""; var autoplay_add = "";
if(autoplay == "&autoplay") autoplay_add = 'allow="autoplay"'; if(autoplay == "&autoplay") autoplay_add = 'allow="autoplay"';
return '<iframe src="https://zoff.me/_embed#' + chan.toLowerCase() + '&' + color + autoplay + embed_videoonly + embed_localmode + '" width="' + width + 'px" height="' + height + 'px" ' + autoplay_add + '></iframe>'; return '<iframe src="https://zoff.me/api/embed/?channel=' + chan.toLowerCase() + color + autoplay + embed_videoonly + embed_localmode + '" width="' + width + 'px" height="' + height + 'px" ' + autoplay_add + '></iframe>';
} }
function change_offline(enabled, already_offline){ function change_offline(enabled, already_offline){

View File

@@ -88,14 +88,14 @@ var not_import_html = "";
var not_export_html = ""; var not_export_html = "";
var embed_height = 300; var embed_height = 300;
var embed_width = 600; var embed_width = 600;
var embed_videoonly = ""; var embed_videoonly = "&videoonly=false";
var embed_localmode = ""; var embed_localmode = "&localmode=false";
var embed_autoplay = "&autoplay"; var embed_autoplay = "&autoplay=true";
var connect_error = false; var connect_error = false;
var access_token_data_youtube = {}; var access_token_data_youtube = {};
var youtube_authenticated = false; var youtube_authenticated = false;
var chromecastAvailable = false; var chromecastAvailable = false;
var color = "2d2d2d"; var color = "&color=2d2d2d";
var find_start = false; var find_start = false;
var durationTimeout; var durationTimeout;
var find_started = false; var find_started = false;
@@ -859,7 +859,7 @@ function addDynamicListeners() {
addListener("input", '#color_embed', function(e){ addListener("input", '#color_embed', function(e){
var that = e; var that = e;
color = that.value.substring(1); color = "&color=" + that.value.substring(1);
document.getElementById("embed-area").value = embed_code(embed_autoplay, embed_width, embed_height, color, embed_videoonly, embed_localmode); document.getElementById("embed-area").value = embed_code(embed_autoplay, embed_width, embed_height, color, embed_videoonly, embed_localmode);
}); });
@@ -944,7 +944,7 @@ function addDynamicListeners() {
youtube_window.close(); youtube_window.close();
window.callback = ""; window.callback = "";
}; };
youtube_window = window.open("/o_callback#youtube=true&nonce=" + nonce, "", "width=600, height=600"); youtube_window = window.open("/api/oauth#youtube=true&nonce=" + nonce, "", "width=600, height=600");
} else { } else {
List.exportToYoutube(); List.exportToYoutube();
} }
@@ -972,7 +972,7 @@ function addDynamicListeners() {
spotify_window.close(); spotify_window.close();
window.callback = ""; window.callback = "";
}; };
spotify_window = window.open("/o_callback#spotify=true&nonce=" + nonce, "", "width=600, height=600"); spotify_window = window.open("/api/oauth#spotify=true&nonce=" + nonce, "", "width=600, height=600");
}); });
addListener("submit", "#listImport", function(event){ addListener("submit", "#listImport", function(event){
@@ -1103,28 +1103,45 @@ function addDynamicListeners() {
Search.importSpotifyPlaylist('https://api.spotify.com/v1/users/' + user + '/playlists/' + playlist_id + '/tracks'); Search.importSpotifyPlaylist('https://api.spotify.com/v1/users/' + user + '/playlists/' + playlist_id + '/tracks');
} else { } else {
before_toast(); var url = document.getElementById("import_spotify").value.split("https://open.spotify.com/playlist/");
M.toast({html: "It seems you've entered a invalid url.", displayLength: 4000});
if(url.length == 2) {
/*url = url[1].split("/");
var user = url[0];*/
var playlist_id = url[1];
playlist_id = playlist_id.replace("?", "");
document.getElementById("import_spotify").disabled = true;
Helper.addClass("#import_spotify", "hide");
Helper.removeClass("#playlist_loader_spotify", "hide");
ga('send', 'event', "import", "spotify");
Search.importSpotifyPlaylist('https://api.spotify.com/v1/playlists/' + playlist_id + '/tracks');
} else {
before_toast();
M.toast({html: "It seems you've entered a invalid url.", displayLength: 4000});
}
} }
} }
document.getElementById("import_spotify").value = ""; document.getElementById("import_spotify").value = "";
}); });
addListener("change", "#autoplay", function(e) { addListener("change", "#autoplay", function(e) {
if(e.checked) embed_autoplay = "&autoplay"; if(e.checked) embed_autoplay = "&autoplay=true";
else embed_autoplay = ""; else embed_autoplay = "&autoplay=false";
document.getElementById("embed-area").value = embed_code(embed_autoplay, embed_width, embed_height, color, embed_videoonly, embed_localmode); document.getElementById("embed-area").value = embed_code(embed_autoplay, embed_width, embed_height, color, embed_videoonly, embed_localmode);
}); });
addListener("change", "#videoonly", function(e) { addListener("change", "#videoonly", function(e) {
if(e.checked) embed_videoonly = "&videoonly"; if(e.checked) embed_videoonly = "&videoonly=true";
else embed_videoonly = ""; else embed_videoonly = "&videoonly=false";
document.getElementById("embed-area").value = embed_code(embed_autoplay, embed_width, embed_height, color, embed_videoonly, embed_localmode); document.getElementById("embed-area").value = embed_code(embed_autoplay, embed_width, embed_height, color, embed_videoonly, embed_localmode);
}); });
addListener("change", "#localmode", function(e) { addListener("change", "#localmode", function(e) {
if(e.checked) embed_localmode = "&localmode"; if(e.checked) embed_localmode = "&localmode=true";
else embed_localmode = ""; else embed_localmode = "&localmode=false";
document.getElementById("embed-area").value = embed_code(embed_autoplay, embed_width, embed_height, color, embed_videoonly, embed_localmode); document.getElementById("embed-area").value = embed_code(embed_autoplay, embed_width, embed_height, color, embed_videoonly, embed_localmode);
}); });
@@ -1262,7 +1279,7 @@ function addDynamicListeners() {
spotify_window.close(); spotify_window.close();
window.callback = ""; window.callback = "";
}; };
spotify_window = window.open("/o_callback#spotify=true&nonce=" + nonce, "", "width=600, height=600"); spotify_window = window.open("/api/oauth#spotify=true&nonce=" + nonce, "", "width=600, height=600");
}); });
addListener("click", ".import-youtube", function(event){ addListener("click", ".import-youtube", function(event){

View File

@@ -498,7 +498,7 @@ importPlaylist: function(pId,pageToken){
youtube_window.close(); youtube_window.close();
window.callback = ""; window.callback = "";
}; };
youtube_window = window.open("/o_callback#youtube=true&nonce=" + nonce, "", "width=600, height=600"); youtube_window = window.open("/api/oauth#youtube=true&nonce=" + nonce, "", "width=600, height=600");
} else { } else {
Helper.log([ Helper.log([
"import list error: ", "import list error: ",
@@ -555,7 +555,7 @@ importPlaylist: function(pId,pageToken){
youtube_window.close(); youtube_window.close();
window.callback = ""; window.callback = "";
}; };
youtube_window = window.open("/o_callback#youtube=true&nonce=" + nonce, "", "width=600, height=600"); youtube_window = window.open("/api/oauth#youtube=true&nonce=" + nonce, "", "width=600, height=600");
} else { } else {
Helper.log([ Helper.log([
"import list error: ", "import list error: ",

View File

@@ -57,6 +57,23 @@ router.route('/').post(function(req, res, next){
root(req, res, next); root(req, res, next);
}); });
router.route('/api/embed').get(function(req, res, next) {
var data = {
year: year,
javascript_file: "embed.min.js",
captcha: res.recaptcha,
analytics: analytics,
stylesheet: "embed.css",
embed: true,
og_image: "https://zoff.me/assets/images/small-square.jpg",
}
res.render('layouts/client/embed', data);
});
router.route('/api/oauth').get(function(req, res, next) {
res.sendFile(path.join(pathThumbnails, '/public/assets/html/callback.html'));
});
router.route('/api/apply').get(function(req, res, next) { router.route('/api/apply').get(function(req, res, next) {
var data = { var data = {
year: year, year: year,
@@ -196,20 +213,9 @@ function channel(req, res, next) {
} else if(subdomain.length >= 2 && subdomain[0] == "www") { } else if(subdomain.length >= 2 && subdomain[0] == "www") {
res.redirect("https://zoff.me"); res.redirect("https://zoff.me");
} else { } else {
if(req.params.channel_name == "_embed") { if(req.params.channel_name == "o_callback") {
//res.sendFile(path.join(pathThumbnails, '/public/assets/html/embed.html')); res.redirect("/api/oauth");
var data = { //res.sendFile(path.join(pathThumbnails, '/public/assets/html/callback.html'));
year: year,
javascript_file: "embed.min.js",
captcha: res.recaptcha,
analytics: analytics,
stylesheet: "embed.css",
embed: true,
og_image: "https://zoff.me/assets/images/small-square.jpg",
}
res.render('layouts/client/embed', data);
} else if(req.params.channel_name == "o_callback") {
res.sendFile(path.join(pathThumbnails, '/public/assets/html/callback.html'));
} else { } else {
/*db.collection("frontpage_lists").find({"_id": Functions.encodeChannelName(req.params.channel_name)}, function(err, docs) { /*db.collection("frontpage_lists").find({"_id": Functions.encodeChannelName(req.params.channel_name)}, function(err, docs) {
console.log(docs); console.log(docs);