diff --git a/src/components/Channel.vue b/src/components/Channel.vue index 715054e1..27eb541f 100644 --- a/src/components/Channel.vue +++ b/src/components/Channel.vue @@ -74,13 +74,9 @@ export default { if (this.loading || !this.channel || !this.channel.nextpage) return; if (window.innerHeight + window.scrollY >= document.body.offsetHeight - window.innerHeight) { this.loading = true; - this.fetchJson( - Constants.BASE_URL + - "/nextpage/channels/" + - this.channel.id + - "?nextpage=" + - encodeURIComponent(this.channel.nextpage), - ).then(json => { + this.fetchJson(Constants.BASE_URL + "/nextpage/channels/" + this.channel.id, { + nextpage: this.channel.nextpage, + }).then(json => { this.channel.relatedStreams.concat(json.relatedStreams); this.channel.nextpage = json.nextpage; this.loading = false; diff --git a/src/components/Playlist.vue b/src/components/Playlist.vue index 10fae9e7..0f98997c 100644 --- a/src/components/Playlist.vue +++ b/src/components/Playlist.vue @@ -74,13 +74,9 @@ export default { if (this.loading || !this.playlist || !this.playlist.nextpage) return; if (window.innerHeight + window.scrollY >= document.body.offsetHeight - window.innerHeight) { this.loading = true; - this.fetchJson( - Constants.BASE_URL + - "/nextpage/playlists/" + - this.$route.query.list + - "?nextpage=" + - encodeURIComponent(this.playlist.nextpage), - ).then(json => { + this.fetchJson(Constants.BASE_URL + "/nextpage/playlists/" + this.$route.query.list, { + nextpage: this.playlist.nextpage, + }).then(json => { this.playlist.relatedStreams.concat(json.relatedStreams); this.playlist.nextpage = json.nextpage; this.loading = false; diff --git a/src/components/SearchResults.vue b/src/components/SearchResults.vue index f03a6dd9..e021dc09 100644 --- a/src/components/SearchResults.vue +++ b/src/components/SearchResults.vue @@ -100,13 +100,10 @@ export default { }, methods: { async fetchResults() { - return await await this.fetchJson( - Constants.BASE_URL + - "/search?q=" + - encodeURIComponent(this.$route.query.search_query) + - "&filter=" + - this.selectedFilter, - ); + return await await this.fetchJson(Constants.BASE_URL + "/search", { + q: this.$route.query.search_query, + filter: this.selectedFilter, + }); }, async updateResults() { document.title = this.$route.query.search_query + " - Piped"; @@ -116,16 +113,11 @@ export default { if (this.loading || !this.results || !this.results.nextpage) return; if (window.innerHeight + window.scrollY >= document.body.offsetHeight - window.innerHeight) { this.loading = true; - this.fetchJson( - Constants.BASE_URL + - "/nextpage/search" + - "?nextpage=" + - encodeURIComponent(this.results.nextpage) + - "&q=" + - encodeURIComponent(this.$route.query.search_query) + - "&filter=" + - this.selectedFilter, - ).then(json => { + this.fetchJson(Constants.BASE_URL + "/nextpage/search", { + nextpage: this.results.nextpage, + q: this.$route.query.search_query, + filter: this.selectedFilter, + }).then(json => { this.results.nextpage = json.nextpage; this.results.id = json.id; this.loading = false; diff --git a/src/components/SearchSuggestions.vue b/src/components/SearchSuggestions.vue index 7dffa594..11330ffa 100644 --- a/src/components/SearchSuggestions.vue +++ b/src/components/SearchSuggestions.vue @@ -49,9 +49,9 @@ export default { } }, async refreshSuggestions() { - this.searchSuggestions = await this.fetchJson( - Constants.BASE_URL + "/suggestions?query=" + encodeURI(this.searchText), - ); + this.searchSuggestions = await this.fetchJson(Constants.BASE_URL + "/suggestions", { + query: this.searchText, + }); this.searchSuggestions.unshift(this.searchText); this.setSelected(0); }, diff --git a/src/components/WatchVideo.vue b/src/components/WatchVideo.vue index 59078490..331ee11f 100644 --- a/src/components/WatchVideo.vue +++ b/src/components/WatchVideo.vue @@ -144,15 +144,12 @@ export default { return this.fetchJson(Constants.BASE_URL + "/streams/" + this.getVideoId()); }, async fetchSponsors() { - return await this.fetchJson( - Constants.BASE_URL + - "/sponsors/" + - this.getVideoId() + - "?category=" + - (localStorage && localStorage.getItem("selectedSkip") !== null - ? encodeURIComponent('["' + localStorage.getItem("selectedSkip").replace(",", '","') + '"]') - : encodeURIComponent('["sponsor", "interaction", "selfpromo", "music_offtopic"]')), - ); + return await this.fetchJson(Constants.BASE_URL + "/sponsors/" + this.getVideoId(), { + category: + localStorage && localStorage.getItem("selectedSkip") !== null + ? '["' + localStorage.getItem("selectedSkip").replace(",", '","') + '"]' + : '["sponsor", "interaction", "selfpromo", "music_offtopic"]', + }); }, fetchComments() { return this.fetchJson(Constants.BASE_URL + "/comments/" + this.getVideoId()); @@ -191,13 +188,9 @@ export default { if (this.loading || !this.comments || !this.comments.nextpage) return; if (window.innerHeight + window.scrollY >= this.$refs.comments.offsetHeight - window.innerHeight) { this.loading = true; - this.fetchJson( - Constants.BASE_URL + - "/nextpage/comments/" + - this.getVideoId() + - "?url=" + - encodeURIComponent(this.comments.nextpage), - ).then(json => { + this.fetchJson(Constants.BASE_URL + "/nextpage/comments/" + this.getVideoId(), { + url: this.comments.nextpage, + }).then(json => { this.comments.nextpage = json.nextpage; this.loading = false; json.comments.map(comment => this.comments.comments.push(comment)); diff --git a/src/main.js b/src/main.js index fd873392..498f58d9 100644 --- a/src/main.js +++ b/src/main.js @@ -55,7 +55,12 @@ const mixin = { num = parseInt(num) return num.toLocaleString('en-US') }, - fetchJson: function (url, options) { + fetchJson: function (url, params, options) { + if (params) { + url = new URL(url); + for (var param in params) + url.searchParams.set(param, params[param]) + } return fetch(url, options).then(response => { return response.json(); });