From 83239c32823371faf86687802475e24e9da3ea29 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 22 Oct 2021 08:19:51 +0530 Subject: [PATCH] More porting --- src/components/Player.vue | 17 +++++++-------- src/routes/Channel.vue | 4 ++-- src/routes/Playlist.vue | 4 ++-- src/routes/Preferences.vue | 6 +++--- src/routes/SearchMenu.vue | 2 +- src/routes/SearchResults.vue | 4 ++-- src/routes/TrendingPage.vue | 6 +++--- src/routes/WatchVideo.vue | 36 +++++++++++-------------------- src/store/authentication-store.js | 7 +++++- src/store/index.js | 2 +- 10 files changed, 40 insertions(+), 48 deletions(-) diff --git a/src/components/Player.vue b/src/components/Player.vue index 46a3505..d60ffcc 100644 --- a/src/components/Player.vue +++ b/src/components/Player.vue @@ -142,7 +142,7 @@ export default { localPlayer.configure( 'streaming.bufferingGoal', - Math.max(this.$store.getters.getPreferenceNumber('bufferGoal', 10), 10) + Math.max(this.$store.getters['prefs/getPreferenceNumber']('bufferGoal', 10), 10) ) this.setPlayerAttrs(localPlayer, videoEl, uri, mime, shaka) @@ -166,14 +166,14 @@ export default { }) videoEl.addEventListener('volumechange', () => { - this.$store.commit('setPrefs', { + this.$store.commit('prefs/setPrefs', { id: 'volume', value: videoEl.volume }) }) videoEl.addEventListener('ratechange', () => { - this.$store.commit('setPrefs', { + this.$store.commit('prefs/setPrefs', { id: 'rate', value: videoEl.playbackRate }) @@ -206,7 +206,7 @@ export default { this.player = player - const disableVideo = this.$store.getters.getPreferenceBoolean('listen', false) && !this.video.livestream + const disableVideo = this.$store.getters['prefs/getPreferenceBoolean']('listen', false) && !this.video.livestream this.player.configure({ preferredVideoCodecs: this.preferredVideoCodecs, @@ -216,9 +216,8 @@ export default { } }) - const quality = this.$store.getters.getPreferenceNumber('quality', 0) - const qualityConds = - quality > 0 && (this.video.audioStreams.length > 0 || this.video.livestream) && !disableVideo + const quality = this.$store.getters['prefs/getPreferenceNumber']('quality', 0) + const qualityConds = quality > 0 && (this.video.audioStreams.length > 0 || this.video.livestream) && !disableVideo if (qualityConds) this.player.configure('abr.enabled', false) player.load(uri, 0, mime).then(() => { @@ -248,8 +247,8 @@ export default { subtitle.name ) }) - videoEl.volume = this.$store.getters.getPreferenceNumber('volume', 1) - videoEl.playbackRate = this.$store.getters.getPreferenceNumber('rate', 1) + videoEl.volume = this.$store.getters['prefs/getPreferenceNumber']('volume', 1) + videoEl.playbackRate = this.$store.getters['prefs/getPreferenceNumber']('rate', 1) }) } }, diff --git a/src/routes/Channel.vue b/src/routes/Channel.vue index 9c8ba6a..950af7c 100644 --- a/src/routes/Channel.vue +++ b/src/routes/Channel.vue @@ -55,7 +55,7 @@ export default { }, methods: { async fetchChannel () { - return this.$store.dispatch('fetchJson', { + return this.$store.dispatch('auth/makeRequest', { path: '/' + this.$route.params.path + '/' + this.$route.params.channelId }) }, @@ -71,7 +71,7 @@ export default { }, fetchMoreVideos () { - this.$store.dispatch('fetchJson', { + this.$store.dispatch('auth/makeRequest', { path: '/nextpage/channel/' + this.channel.id, params: { nextpage: this.channel.nextpage diff --git a/src/routes/Playlist.vue b/src/routes/Playlist.vue index 75d688c..b0101e6 100644 --- a/src/routes/Playlist.vue +++ b/src/routes/Playlist.vue @@ -61,7 +61,7 @@ export default { }, computed: { getRssUrl () { - return this.$store.getters.apiUrl + '/rss/playlists/' + this.$route.query.list + return this.$store.getters['prefs/apiUrl'] + '/rss/playlists/' + this.$route.query.list }, chunkedByFour () { @@ -70,7 +70,7 @@ export default { }, methods: { async fetchPlaylist () { - return this.$store.dispatch('fetchJson', { + return this.$store.dispatch('auth/makeRequest', { path: '/playlists/' + this.$route.query.list }) }, diff --git a/src/routes/Preferences.vue b/src/routes/Preferences.vue index d05de70..5ec5867 100644 --- a/src/routes/Preferences.vue +++ b/src/routes/Preferences.vue @@ -3,8 +3,8 @@

{{ $t('titles.preferences') }}

- - + +

{{ $t('preferences.' + opt.id) }}


{{ $t('actions.instances_list') }}
@@ -139,7 +139,7 @@ export default { }, methods: { setValue (k, v) { - this.$store.commit('setPrefs', { + this.$store.commit('prefs/setPrefs', { id: k, value: v }) diff --git a/src/routes/SearchMenu.vue b/src/routes/SearchMenu.vue index 1649943..f17db0b 100644 --- a/src/routes/SearchMenu.vue +++ b/src/routes/SearchMenu.vue @@ -54,7 +54,7 @@ export default { methods: { async refreshSuggestions () { this.requestInProgress = true - this.searchSuggestions = await this.$store.dispatch('fetchJson', { + this.searchSuggestions = await this.$store.dispatch('auth/makeRequest', { path: '/suggestions', params: { query: this.searchText diff --git a/src/routes/SearchResults.vue b/src/routes/SearchResults.vue index cbbb106..5d6a0af 100644 --- a/src/routes/SearchResults.vue +++ b/src/routes/SearchResults.vue @@ -98,7 +98,7 @@ export default { }, async fetchResults () { - return this.$store.dispatch('fetchJson', { + return this.$store.dispatch('auth/makeRequest', { path: 'search', params: { q: this.$route.query.search_query, @@ -127,7 +127,7 @@ export default { }, fetchMoreResults () { - this.$store.dispatch('fetchJson', { + this.$store.dispatch('auth/makeRequest', { path: '/nextpage/search', params: { nextpage: this.results.nextpage, diff --git a/src/routes/TrendingPage.vue b/src/routes/TrendingPage.vue index ed9e779..7de8ecd 100644 --- a/src/routes/TrendingPage.vue +++ b/src/routes/TrendingPage.vue @@ -31,16 +31,16 @@ export default { }, mounted () { - const region = this.$store.getters.getPreference('region', 'US') + const region = this.$store.getters['prefs/getPreference']('region', 'US') this.fetchTrending(region).then(videos => (this.videos = videos)) }, methods: { async fetchTrending (region) { - return this.$store.dispatch('fetchJson', { + return this.$store.dispatch('auth/makeRequest', { path: '/trending', params: { - region: region || 'US' + region: region } }) } diff --git a/src/routes/WatchVideo.vue b/src/routes/WatchVideo.vue index e2eb2a5..8518a61 100644 --- a/src/routes/WatchVideo.vue +++ b/src/routes/WatchVideo.vue @@ -52,7 +52,7 @@
@@ -170,7 +170,7 @@ export default { params: { category: '["' + - this.$store.getters.getPreference('selectedSkip', 'sponsor,interaction,selfpromo,music_offtopic').replaceAll( + this.$store.getters['prefs/getPreference']('selectedSkip', 'sponsor,interaction,selfpromo,music_offtopic').replaceAll( ',', '","' ) + @@ -179,7 +179,7 @@ export default { }) }, fetchComments () { - return this.$store.dispatch('fetchJson', { + return this.$store.dispatch('auth/makeRequest', { path: '/comments/' + this.getVideoId() }) }, @@ -191,7 +191,7 @@ export default { }, fetchMoreComments () { - this.$store.dispatch('fetchJson', { + this.$store.dispatch('auth/makeRequest', { path: '/nextpage/comments/' + this.getVideoId(), params: { nextpage: this.comments.nextpage @@ -203,7 +203,7 @@ export default { }, onAutoplayChg (ev) { - this.$store.commit('setPrefs', { + this.$store.commit('prefs/setPrefs', { id: 'autoplay', value: ev }) @@ -232,7 +232,7 @@ export default { }) }, async getSponsors () { - if (this.$store.getters.getPreference('sponsorblock', true)) { this.fetchSponsors().then(data => (this.sponsors = data)) } + if (this.$store.getters['prefs/getPreference']('sponsorblock', true)) { this.fetchSponsors().then(data => (this.sponsors = data)) } }, async getComments () { this.fetchComments().then(data => (this.comments = data)) @@ -240,33 +240,21 @@ export default { async fetchSubscribedStatus () { if (!this.channelId) return - this.$store.dispatch('fetchJson', { + this.$store.dispatch('auth/makeRequest', { path: '/subscribed', params: { channelId: this.channelId - }, - options: { - headers: { - Authorization: this.$store.getters.getAuthToken - } } }).then(json => { this.subscribed = json.subscribed }) }, subscribeHandler () { - this.$store.dispatch('fetchJson', { + this.$store.dispatch('auth/makeRequest', { + method: 'POST', path: (this.subscribed ? '/unsubscribe' : '/subscribe'), - params: null, - options: { - method: 'POST', - body: JSON.stringify({ - channelId: this.channelId - }), - headers: { - Authorization: this.$store.getters.getAuthToken, - 'Content-Type': 'application/json' - } + data: { + channelId: this.channelId } }) this.subscribed = !this.subscribed @@ -278,7 +266,7 @@ export default { }, computed: { isAutoplayEnabled () { - return this.$store.getters.getPreferenceBoolean('autoplay') + return this.$store.getters['prefs/getPreferenceBoolean']('autoplay') } }, components: { diff --git a/src/store/authentication-store.js b/src/store/authentication-store.js index 20f77a7..118bff1 100644 --- a/src/store/authentication-store.js +++ b/src/store/authentication-store.js @@ -34,7 +34,12 @@ const AuthenticationStore = { baseURL: rootGetters['prefs/apiUrl'], method, url: path, - params + params, + headers: state.isAuthenticated + ? { + Authorization: state.authToken + } + : undefined }) return resp diff --git a/src/store/index.js b/src/store/index.js index 2ca419f..04e1212 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -14,7 +14,7 @@ const store = new Vuex.Store({ } }) -store.watch(state => state.prefs.prefs, (nextPrefs) => { +store.watch(state => state['prefs/prefs'], (nextPrefs) => { if (isPlainObject(nextPrefs)) { window.localStorage.setItem('PREFERENCES', JSON.stringify(nextPrefs)) }