allow relative urls
authormarcelveldt <marcelvanderveldt@MacBook-Silvia.local>
Fri, 25 Oct 2019 14:25:29 +0000 (16:25 +0200)
committermarcelveldt <marcelvanderveldt@MacBook-Silvia.local>
Fri, 25 Oct 2019 14:25:29 +0000 (16:25 +0200)
this fixes ingress support

music_assistant/web/app.js
music_assistant/web/components/player.vue.js
music_assistant/web/lib/utils.js
music_assistant/web/pages/artistdetails.vue.js
music_assistant/web/pages/browse.vue.js
music_assistant/web/pages/config.vue.js
music_assistant/web/pages/playlistdetails.vue.js
music_assistant/web/pages/queue.vue.js
music_assistant/web/pages/search.vue.js
music_assistant/web/pages/trackdetails.vue.js

index 0a90cb66b40220e3caa89edae6324d1d6d24f140..7ac1bec962ea9ac4ca4465448eadb52d5e73dade 100644 (file)
@@ -68,7 +68,9 @@ const globalStore = new Vue({
         showplaymenu: false,
         showsearchbox: false,
         playmenuitem: null,
-        server: null
+        server: null,
+        apiAddress: null,
+        wsAddress: null
     }
 })
 Vue.prototype.$globals = globalStore;
@@ -103,9 +105,15 @@ var app = new Vue({
             localStorage.setItem('last_update', cur_update);
             window.location.reload(true);
         }
-        var loc = window.location;
-        console.log(loc);
-        this.$globals.server = loc;
+        // TODO: retrieve serveraddress through discovery and/or user settings
+        let loc = window.location;
+        this.$globals.server = loc.origin + loc.pathname;
+        this.$globals.apiAddress = this.$globals.server + 'api/';
+        if (loc.protocol === "https:") {
+            this.$globals.wsAddress = "wss://"+ loc.host + loc.pathname + 'ws';
+        } else {
+            this.$globals.wsAddress = "ws://"+ loc.host + loc.pathname + 'ws';
+        }
     },
     data: { },
     methods: {},
index adf7e32cf0ec931a85269909b6790bdbb02c8764..b9fa0ec128223e1ef7c2f28a4411f9f8f02b5f4b 100755 (executable)
@@ -149,7 +149,7 @@ Vue.component("player", {
       if (!val)
         this.cur_player_item = null;
       else {
-        const api_url = '/api/players/' + this.active_player_id + '/queue/' + val;
+        const api_url = this.$globals.server + 'api/players/' + this.active_player_id + '/queue/' + val;
         axios
           .get(api_url)
           .then(result => {
@@ -364,18 +364,10 @@ Vue.component("player", {
 
     },
     connectWS() {
-      var loc = window.location, new_uri;
-      if (loc.protocol === "https:") {
-          new_uri = "wss:";
-      } else {
-          new_uri = "ws:";
-      }
-      new_uri += "/" + loc.host;
-      new_uri += loc.pathname + "ws";
-      this.ws = new WebSocket(new_uri);
+      this.ws = new WebSocket(this.$globals.wsAddress);
 
       this.ws.onopen = function() {
-        console.log('websocket connected! ' + new_uri);
+        console.log('websocket connected! ' + this.$globals.wsAddress);
         this.createAudioPlayer();
         data = JSON.stringify({message:'players', message_details: null});
         this.ws.send(data);
index e078d26d486cb9515b77750cd68a0051215530d6..922471c86f13f0252818314e1a8d2030cfe553d1 100644 (file)
@@ -39,7 +39,7 @@ String.prototype.formatDuration = function () {
         return hours+':'+minutes+':'+seconds;
 }
 function toggleLibrary (item) {
-    var endpoint = "/api/" + item.media_type + "/";
+    var endpoint = this.$globals.server + "api/" + item.media_type + "/";
     item_id = item.item_id.toString();
     var action = "/library_remove"
     if (item.in_library.length == 0)
index 46600303ce63e53bc115b198b554f12cd506112a..379f83541b4910ff313b92a5b1754ea027413b2d 100755 (executable)
@@ -73,7 +73,7 @@ var ArtistDetails = Vue.component('ArtistDetails', {
     },
     getInfo (lazy=true) {
       this.$globals.loading = true;
-      const api_url = '/api/artists/' + this.media_id;
+      const api_url = this.$globals.apiAddress + 'artists/' + this.media_id;
       console.log(api_url + ' - ' + this.provider);
       axios
         .get(api_url, { params: { lazy: lazy, provider: this.provider }})
@@ -98,7 +98,7 @@ var ArtistDetails = Vue.component('ArtistDetails', {
     },
     getArtistTopTracks () {
       
-      const api_url = '/api/artists/' + this.media_id + '/toptracks'
+      const api_url = this.$globals.apiAddress + 'artists/' + this.media_id + '/toptracks'
       axios
       .get(api_url, { params: { provider: this.provider }})
         .then(result => {
@@ -111,7 +111,7 @@ var ArtistDetails = Vue.component('ArtistDetails', {
         
     },
     getArtistAlbums () {
-      const api_url = '/api/artists/' + this.media_id + '/albums'
+      const api_url = this.$globals.apiAddress + 'artists/' + this.media_id + '/albums'
       console.log('loading ' + api_url);
       axios
       .get(api_url, { params: { provider: this.provider }})
index 49bcdc8b0c7cbedc5008be39144ee8dffa7dc371..fbc11c68af24bd36ca655d508ef8602264deccf7 100755 (executable)
@@ -34,7 +34,7 @@ var Browse = Vue.component('Browse', {
   methods: {
     getItems () {
       this.$globals.loading = true
-      const api_url = '/api/' + this.mediatype;
+      const api_url = this.$globals.apiAddress + this.mediatype;
       axios
         .get(api_url, { params: { offset: this.offset, limit: 50, provider: this.provider }})
         .then(result => {
index 85107552e668cfddacc7203b6d6f884680e8982d..74582dcb87f38138ae4ff8511afde927905c29c1 100755 (executable)
@@ -106,7 +106,7 @@ var Config = Vue.component('Config', {
   methods: {
     getConfig () {
       axios
-        .get('/api/config')
+        .get(this.$globals.apiAddress + 'config')
         .then(result => {
           this.conf = result.data;
         })
@@ -118,7 +118,7 @@ var Config = Vue.component('Config', {
       console.log(key + "/" + subkey + " changed!");
       console.log(newvalue);
       axios
-        .post('/api/config/'+key+'/'+subkey, newvalue)
+        .post(this.$globals.apiAddress + 'config/'+key+'/'+subkey, newvalue)
         .then(result => {
           console.log(result);
           if (result.data.restart_required)
@@ -129,7 +129,7 @@ var Config = Vue.component('Config', {
         });
     },
     getPlayers () {
-      const api_url = '/api/players';
+      const api_url = this.$globals.apiAddress + 'players';
       axios
         .get(api_url)
         .then(result => {
index b9c617d4d02a135c0111af3a4f1da148a1c1c18c..f96d3817d16117b44189d14cf26d48dd6dc1ba2d 100755 (executable)
@@ -44,7 +44,7 @@ var PlaylistDetails = Vue.component('PlaylistDetails', {
   },
   methods: {
     getInfo () {
-      const api_url = '/api/playlists/' + this.media_id
+      const api_url = this.$globals.apiAddress + 'playlists/' + this.media_id
       axios
       .get(api_url, { params: { provider: this.provider }})
         .then(result => {
@@ -57,7 +57,7 @@ var PlaylistDetails = Vue.component('PlaylistDetails', {
     },
     getPlaylistTracks () {
       this.$globals.loading = true
-      const api_url = '/api/playlists/' + this.media_id + '/tracks'
+      const api_url = this.$globals.apiAddress + 'playlists/' + this.media_id + '/tracks'
       axios
         .get(api_url, { params: { offset: this.offset, limit: 25, provider: this.provider}})
         .then(result => {
index 9bc25a94745e9e58616f67fa100fe1a7a38bdbce..8440ec2c81e9fd3d8dd15c845eb779b2e6812915 100755 (executable)
@@ -29,7 +29,7 @@ var Queue = Vue.component('Queue', {
   methods: {
 
     getQueueTracks (offset, limit) {
-      const api_url = '/api/players/' + this.player_id + '/queue'
+      const api_url = this.$globals.apiAddress + 'players/' + this.player_id + '/queue'
       return axios.get(api_url, { params: { offset: offset, limit: limit}})
         .then(response => {
             if (response.data.length < 1 )
index 996c01ef28babcd02155f7ba0aed6f84e2d50175..fd86688e9c3dfbdf4534fc977ef0ae53937e5d5e 100755 (executable)
@@ -126,7 +126,7 @@ var Search = Vue.component('Search', {
       if (this.searchQuery) {
         this.$globals.loading = true;
         console.log(this.searchQuery);
-        const api_url = '/api/search'
+        const api_url = this.$globals.apiAddress + 'search'
         console.log('loading ' + api_url);
           axios
             .get(api_url, {
index e8f08963d6c28e197c9a53e18408e4a598a6e54c..3b428732acb9f052608e694542578f1444b9279e 100755 (executable)
@@ -46,7 +46,7 @@ var TrackDetails = Vue.component('TrackDetails', {
   methods: {
     getInfo () {
       this.$globals.loading = true;
-      const api_url = '/api/tracks/' + this.media_id
+      const api_url = this.$globals.apiAddress + 'tracks/' + this.media_id
       axios
         .get(api_url, { params: { provider: this.provider }})
         .then(result => {
@@ -60,7 +60,7 @@ var TrackDetails = Vue.component('TrackDetails', {
         });
     },
     getTrackVersions () {
-      const api_url = '/api/search';
+      const api_url = this.$globals.apiAddress + 'search';
       var searchstr = this.info.artists[0].name + " - " + this.info.name
       axios
         .get(api_url, { params: { query: searchstr, limit: 50, media_types: 'tracks', online: true}})