summaryrefslogtreecommitdiff
path: root/dist/callback.html
diff options
context:
space:
mode:
Diffstat (limited to 'dist/callback.html')
-rw-r--r--dist/callback.html32
1 files changed, 24 insertions, 8 deletions
diff --git a/dist/callback.html b/dist/callback.html
index f212b5f..79ac83c 100644
--- a/dist/callback.html
+++ b/dist/callback.html
@@ -74,6 +74,7 @@
</div>
<div class="main">
<h1>Spotify Intersect</h1>
+ <input type="text" id="username" placeholder="Username">
<button id="Connect_button" onclick="connect_button()">Connect to Spotify</button>
<button id="Load_button" onclick="load_songs()" disabled=true>Load songs to database</button>
<p id="status"></p>
@@ -85,6 +86,11 @@
<p id="output"></p>
</div>
<script>
+ const host = "http://127.0.0.1:8000";
+ const api = host + "";
+ //const host = "https://kobert.dev";
+ //const api = host + "/spotify-api";
+ let lobby = null;
function getParameterByName(name) {
let url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
@@ -98,15 +104,27 @@
//http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript
let token = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
sessionStorage.setItem('token', token);
+ sessionStorage.setItem('lobby', lobby);
document.getElementById("Connect_button").disabled = true;
- window.location = "https://kobert.dev/spotify-api/token/" + token;
+ window.location = api + "/token/" + token;
}
function populate_users() {
- if (getParameterByName("code") != null) {
+ lobby = getParameterByName("lobby");
+ if (!lobby) {
+ lobby = sessionStorage.getItem('lobby');
+ }
+ let code = getParameterByName("code");
+ if (code !== null) {
document.getElementById("Connect_button").disabled = true;
document.getElementById("Load_button").disabled = false;
}
- fetch("https://kobert.dev/spotify-api/user")
+ if (lobby === null) {
+ document.getElementById("status").innerHTML = `Error: this is no valid lobby, please create a lobby first`;
+ document.getElementById("Connect_button").disabled = true;
+ document.getElementById("Load_button").disabled = true;
+ return;
+ }
+ fetch(api + "/user/" + lobby)
.then(function (response) {
if (!response.ok) {
document.getElementById("status").innerHTML = `Error occured while loading songs: ${response.status}`;
@@ -116,15 +134,13 @@
document.getElementById("userlist").innerHTML = '<p>' + message.replace(/\n/g, '</p>\n<p>') + '</p>';
});
});
-
}
-
function load_songs() {
console.log("loading songs");
document.getElementById("status").innerHTML = "Loading songs";
document.getElementById("Load_button").disabled = true;
let token = sessionStorage.getItem('token');
- fetch("https://kobert.dev/spotify-api/callback/" + token + "/" + getParameterByName("code"))
+ fetch(api + `/callback/${token}/${lobby}/` + getParameterByName("code"))
.then(function (response) {
if (!response.ok) {
document.getElementById("status").innerHTML = `Error occured while loading songs: ${response.status}`;
@@ -133,13 +149,13 @@
document.getElementById("status").innerHTML = "Loaded songs";
populate_users();
});
- //window.location = "https://kobert.dev/spotify-api/token/" + token;
+ //window.location = api + "/token/" + token;
}
function match_users() {
let name1 = document.getElementById("name1").value;
let name2 = document.getElementById("name2").value;
- fetch("https://kobert.dev/spotify-api/match/" + name1 + "/" + name2)
+ fetch(api + `/match/${lobby}/${name1},${name2}`)
.then(function (response) {
if (!response.ok) {
document.getElementById("status").innerHTML = `Error occured while loading songs: ${response.status}`;