Skip to content

Commit

Permalink
fix(web): handle http/https dynamically
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTipo01 committed Oct 26, 2023
1 parent f45905e commit c445362
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
6 changes: 3 additions & 3 deletions web/src/lib/favorites.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export async function AddFavorite(token, host) {
let folder = document.getElementById("folder")?.value;

// Request
let route = `https://${host}/favorites`
let route = `${host}/favorites`
let response = await fetch(route, {
method: 'POST',
headers: {
Expand Down Expand Up @@ -34,7 +34,7 @@ export async function AddFavorite(token, host) {

export async function RemoveFavorite(token, name, host) {
// Request
let route = `https://${host}/favorites?` + new URLSearchParams({'name': name, 'token': token}).toString();
let route = `${host}/favorites?` + new URLSearchParams({'name': name, 'token': token}).toString();
let response = await fetch(route, {
method: 'DELETE',
headers: {
Expand All @@ -60,7 +60,7 @@ export async function RemoveFavorite(token, name, host) {

export async function GetFavorites(token, host) {
// Request
let route = `https://${host}/favorites?` + new URLSearchParams({"token": token}).toString();
let route = `${host}/favorites?` + new URLSearchParams({"token": token}).toString();
let response = await fetch(route, {
method: "GET",
headers: {
Expand Down
6 changes: 3 additions & 3 deletions web/src/lib/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export async function AddToQueue(GuildID, token, host) {
shuffle = document.getElementById("shuffle")?.checked;
}
// Request
let route = `https://${host}/queue/${GuildID}`
let route = `${host}/queue/${GuildID}`
let response = await fetch(route, {
method: 'POST',
headers: {
Expand Down Expand Up @@ -44,7 +44,7 @@ export async function AddToQueue(GuildID, token, host) {

export async function RemoveFromQueue(GuildID, token, clear=false, host) { // AKA skip
// Request
let route = `https://${host}/queue/${GuildID}?` + new URLSearchParams({'clean': clear, 'token': token}).toString();
let route = `${host}/queue/${GuildID}?` + new URLSearchParams({'clean': clear, 'token': token}).toString();
let response = await fetch(route, {
method: "DELETE",
headers: {
Expand All @@ -68,7 +68,7 @@ export async function RemoveFromQueue(GuildID, token, clear=false, host) { // AK

export async function GetQueue(GuildID, token, host) {
// Request
let route = `https://${host}/queue/${GuildID}?` + new URLSearchParams({"token": token}).toString();
let route = `${host}/queue/${GuildID}?` + new URLSearchParams({"token": token}).toString();
let response = await fetch(route, {
method: "GET",
headers: {
Expand Down
2 changes: 1 addition & 1 deletion web/src/lib/song.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export async function ToggleSong(GuildID, token, action = "", host) { // AKA Pa
return -8
}
else {
let route = `https://${host}/${action}/${GuildID}?` + new URLSearchParams({"token": token}).toString();
let route = `${host}/${action}/${GuildID}?` + new URLSearchParams({"token": token}).toString();
let response = await fetch(route, {
method: "GET",
headers: {
Expand Down
2 changes: 1 addition & 1 deletion web/src/lib/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ export function GetToken() {
}

export function GetHost() {
return window.location.host;
return window.location.protocol + "//" + window.location.host;
}
9 changes: 8 additions & 1 deletion web/src/routes/queue.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@
// WebSocket
onMount(async () => {
let websocket_url = `wss://gerry.thetipo.rocks/ws/${GuildId}?` + new URLSearchParams({"token": token}).toString();
let websocket_url = `${host}/ws/${GuildId}?` + new URLSearchParams({"token": token}).toString();
// If the host is in https, use wss instead of ws
if (host.startsWith("https")) {
websocket_url = 'wss://' + websocket_url;
} else {
websocket_url = 'ws://' + websocket_url;
}
const socket = new WebSocket(websocket_url);
socket.onmessage = function(e) {
const Notification = Object.freeze({
Expand Down

0 comments on commit c445362

Please sign in to comment.