diff --git a/src/components/ChannelPage.vue b/src/components/ChannelPage.vue index a176c315..3755f54d 100644 --- a/src/components/ChannelPage.vue +++ b/src/components/ChannelPage.vue @@ -70,7 +70,7 @@ export default { methods: { async fetchSubscribedStatus() { this.fetchJson( - this.apiUrl() + "/subscribed", + this.authApiUrl() + "/subscribed", { channelId: this.channel.id, }, @@ -113,7 +113,7 @@ export default { } }, subscribeHandler() { - this.fetchJson(this.apiUrl() + (this.subscribed ? "/unsubscribe" : "/subscribe"), null, { + this.fetchJson(this.authApiUrl() + (this.subscribed ? "/unsubscribe" : "/subscribe"), null, { method: "POST", body: JSON.stringify({ channelId: this.channel.id, diff --git a/src/components/FeedPage.vue b/src/components/FeedPage.vue index fcf4f0f0..66c8b6d6 100644 --- a/src/components/FeedPage.vue +++ b/src/components/FeedPage.vue @@ -41,7 +41,7 @@ export default { }, computed: { getRssUrl(_this) { - return _this.apiUrl() + "/feed/rss?authToken=" + _this.getAuthToken(); + return _this.authApiUrl() + "/feed/rss?authToken=" + _this.getAuthToken(); }, }, mounted() { @@ -66,7 +66,7 @@ export default { }, methods: { async fetchFeed() { - return await this.fetchJson(this.apiUrl() + "/feed", { + return await this.fetchJson(this.authApiUrl() + "/feed", { authToken: this.getAuthToken(), }); }, diff --git a/src/components/ImportPage.vue b/src/components/ImportPage.vue index c54bb481..dcc354b0 100644 --- a/src/components/ImportPage.vue +++ b/src/components/ImportPage.vue @@ -133,7 +133,7 @@ export default { }, handleImport() { this.fetchJson( - this.apiUrl() + "/import", + this.authApiUrl() + "/import", { override: this.override, }, diff --git a/src/components/LoginPage.vue b/src/components/LoginPage.vue index 9bb303b3..549a7b95 100644 --- a/src/components/LoginPage.vue +++ b/src/components/LoginPage.vue @@ -49,7 +49,7 @@ export default { }, methods: { login() { - this.fetchJson(this.apiUrl() + "/login", null, { + this.fetchJson(this.authApiUrl() + "/login", null, { method: "POST", body: JSON.stringify({ username: this.username, @@ -57,7 +57,7 @@ export default { }), }).then(resp => { if (resp.token) { - this.setPreference("authToken" + this.hashCode(this.apiUrl()), resp.token); + this.setPreference("authToken" + this.hashCode(this.authApiUrl()), resp.token); window.location = "/"; // done to bypass cache } else alert(resp.error); }); diff --git a/src/components/PlaylistAddModal.vue b/src/components/PlaylistAddModal.vue index f61511b0..aeb20921 100644 --- a/src/components/PlaylistAddModal.vue +++ b/src/components/PlaylistAddModal.vue @@ -56,7 +56,7 @@ export default { }, mounted() { this.fetchPlaylists(); - this.selectedPlaylist = this.getPreferenceString("selectedPlaylist" + this.hashCode(this.apiUrl())); + this.selectedPlaylist = this.getPreferenceString("selectedPlaylist" + this.hashCode(this.authApiUrl())); window.addEventListener("keydown", this.handleKeyDown); window.blur(); }, @@ -83,7 +83,7 @@ export default { this.$refs.addButton.disabled = true; this.processing = true; - this.fetchJson(this.apiUrl() + "/user/playlists/add", null, { + this.fetchJson(this.authApiUrl() + "/user/playlists/add", null, { method: "POST", body: JSON.stringify({ playlistId: playlistId, @@ -94,13 +94,13 @@ export default { "Content-Type": "application/json", }, }).then(json => { - this.setPreference("selectedPlaylist" + this.hashCode(this.apiUrl()), playlistId); + this.setPreference("selectedPlaylist" + this.hashCode(this.authApiUrl()), playlistId); this.$emit("close"); if (json.error) alert(json.error); }); }, async fetchPlaylists() { - this.fetchJson(this.apiUrl() + "/user/playlists", null, { + this.fetchJson(this.authApiUrl() + "/user/playlists", null, { headers: { Authorization: this.getAuthToken(), }, diff --git a/src/components/PlaylistPage.vue b/src/components/PlaylistPage.vue index d2f97513..d54d63da 100644 --- a/src/components/PlaylistPage.vue +++ b/src/components/PlaylistPage.vue @@ -57,14 +57,14 @@ export default { }, computed: { getRssUrl: _this => { - return _this.apiUrl() + "/rss/playlists/" + _this.$route.query.list; + return _this.authApiUrl() + "/rss/playlists/" + _this.$route.query.list; }, }, mounted() { this.getPlaylistData(); const playlistId = this.$route.query.list; if (this.authenticated && playlistId?.length == 36) - this.fetchJson(this.apiUrl() + "/user/playlists", null, { + this.fetchJson(this.authApiUrl() + "/user/playlists", null, { headers: { Authorization: this.getAuthToken(), }, @@ -82,7 +82,7 @@ export default { }, methods: { async fetchPlaylist() { - return await await this.fetchJson(this.apiUrl() + "/playlists/" + this.$route.query.list); + return await await this.fetchJson(this.authApiUrl() + "/playlists/" + this.$route.query.list); }, async getPlaylistData() { this.fetchPlaylist() @@ -96,7 +96,7 @@ 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(this.apiUrl() + "/nextpage/playlists/" + this.$route.query.list, { + this.fetchJson(this.authApiUrl() + "/nextpage/playlists/" + this.$route.query.list, { nextpage: this.playlist.nextpage, }).then(json => { this.playlist.relatedStreams.concat(json.relatedStreams); diff --git a/src/components/PlaylistsPage.vue b/src/components/PlaylistsPage.vue index daae9eaa..3b048a64 100644 --- a/src/components/PlaylistsPage.vue +++ b/src/components/PlaylistsPage.vue @@ -38,7 +38,7 @@ export default { }, methods: { fetchPlaylists() { - this.fetchJson(this.apiUrl() + "/user/playlists", null, { + this.fetchJson(this.authApiUrl() + "/user/playlists", null, { headers: { Authorization: this.getAuthToken(), }, @@ -48,7 +48,7 @@ export default { }, deletePlaylist(id) { if (confirm(this.$t("actions.delete_playlist_confirm"))) - this.fetchJson(this.apiUrl() + "/user/playlists/delete", null, { + this.fetchJson(this.authApiUrl() + "/user/playlists/delete", null, { method: "POST", body: JSON.stringify({ playlistId: id, @@ -65,7 +65,7 @@ export default { createPlaylist() { const name = prompt(this.$t("actions.create_playlist")); if (name) - this.fetchJson(this.apiUrl() + "/user/playlists/create", null, { + this.fetchJson(this.authApiUrl() + "/user/playlists/create", null, { method: "POST", body: JSON.stringify({ name: name, diff --git a/src/components/PreferencesPage.vue b/src/components/PreferencesPage.vue index a2dd8649..7dc68ae8 100644 --- a/src/components/PreferencesPage.vue +++ b/src/components/PreferencesPage.vue @@ -203,11 +203,33 @@ - + + + + + + + + + + + + + @@ -243,6 +265,8 @@ export default { data() { return { selectedInstance: null, + authInstance: false, + selectedAuthInstance: null, instances: [], sponsorBlock: true, skipSponsor: true, @@ -337,6 +361,8 @@ export default { if (this.testLocalStorage) { this.selectedInstance = this.getPreferenceString("instance", "https://pipedapi.kavin.rocks"); + this.authInstance = this.getPreferenceBoolean("authInstance", false); + this.selectedAuthInstance = this.getPreferenceString("auth_instance_url", this.selectedInstance); this.sponsorBlock = this.getPreferenceBoolean("sponsorblock", true); if (localStorage.getItem("selectedSkip") !== null) { @@ -428,6 +454,8 @@ export default { shouldReload = true; localStorage.setItem("instance", this.selectedInstance); + localStorage.setItem("authInstance", this.authInstance); + localStorage.setItem("auth_instance_url", this.selectedAuthInstance); localStorage.setItem("sponsorblock", this.sponsorBlock); var sponsorSelected = []; @@ -466,7 +494,7 @@ export default { return "https://www.ssllabs.com/ssltest/analyze.html?d=" + new URL(url).host + "&latest"; }, async deleteAccount() { - this.fetchJson(this.apiUrl() + "/user/delete", null, { + this.fetchJson(this.authApiUrl() + "/user/delete", null, { method: "POST", headers: { Authorization: this.getAuthToken(), @@ -482,12 +510,12 @@ export default { }, logout() { // reset the auth token - localStorage.removeItem("authToken" + this.hashCode(this.apiUrl()), this.getAuthToken()); + localStorage.removeItem("authToken" + this.hashCode(this.authApiUrl())); // redirect to trending page window.location = "/"; }, async invalidateSession() { - this.fetchJson(this.apiUrl() + "/logout", null, { + this.fetchJson(this.authApiUrl() + "/logout", null, { method: "POST", headers: { Authorization: this.getAuthToken(), diff --git a/src/components/RegisterPage.vue b/src/components/RegisterPage.vue index 759a90fa..a56653b8 100644 --- a/src/components/RegisterPage.vue +++ b/src/components/RegisterPage.vue @@ -49,7 +49,7 @@ export default { }, methods: { register() { - this.fetchJson(this.apiUrl() + "/register", null, { + this.fetchJson(this.authApiUrl() + "/register", null, { method: "POST", body: JSON.stringify({ username: this.username, @@ -57,7 +57,7 @@ export default { }), }).then(resp => { if (resp.token) { - this.setPreference("authToken" + this.hashCode(this.apiUrl()), resp.token); + this.setPreference("authToken" + this.hashCode(this.authApiUrl()), resp.token); window.location = "/"; // done to bypass cache } else alert(resp.error); }); diff --git a/src/components/SubscriptionsPage.vue b/src/components/SubscriptionsPage.vue index 99cdfd11..7e002064 100644 --- a/src/components/SubscriptionsPage.vue +++ b/src/components/SubscriptionsPage.vue @@ -39,7 +39,7 @@ export default { }, mounted() { if (this.authenticated) - this.fetchJson(this.apiUrl() + "/subscriptions", null, { + this.fetchJson(this.authApiUrl() + "/subscriptions", null, { headers: { Authorization: this.getAuthToken(), }, @@ -54,7 +54,7 @@ export default { }, methods: { handleButton(subscription) { - this.fetchJson(this.apiUrl() + (subscription.subscribed ? "/unsubscribe" : "/subscribe"), null, { + this.fetchJson(this.authApiUrl() + (subscription.subscribed ? "/unsubscribe" : "/subscribe"), null, { method: "POST", body: JSON.stringify({ channelId: subscription.url.split("/")[2], diff --git a/src/components/WatchVideo.vue b/src/components/WatchVideo.vue index fed78457..96eca506 100644 --- a/src/components/WatchVideo.vue +++ b/src/components/WatchVideo.vue @@ -430,7 +430,7 @@ export default { if (!this.channelId || !this.authenticated) return; this.fetchJson( - this.apiUrl() + "/subscribed", + this.authApiUrl() + "/subscribed", { channelId: this.channelId, }, @@ -444,7 +444,7 @@ export default { }); }, subscribeHandler() { - this.fetchJson(this.apiUrl() + (this.subscribed ? "/unsubscribe" : "/subscribe"), null, { + this.fetchJson(this.authApiUrl() + (this.subscribed ? "/unsubscribe" : "/subscribe"), null, { method: "POST", body: JSON.stringify({ channelId: this.channelId, diff --git a/src/locales/en.json b/src/locales/en.json index 7991e8e4..c21d496f 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -84,7 +84,9 @@ "delete_account": "Delete Account", "logout": "Logout from this device", "minimize_recommendations_default": "Minimize Recommendations by default", - "invalidate_session": "Logout all devices" + "invalidate_session": "Logout all devices", + "different_auth_instance": "Use a different instance for authentication", + "instance_auth_selection": "Autentication Instance Selection" }, "comment": { "pinned_by": "Pinned by", diff --git a/src/main.js b/src/main.js index ee3887fb..1cfce4a7 100644 --- a/src/main.js +++ b/src/main.js @@ -154,8 +154,13 @@ const mixin = { apiUrl() { return this.getPreferenceString("instance", "https://pipedapi.kavin.rocks"); }, + authApiUrl() { + if (this.getPreferenceBoolean("authInstance", false)) { + return this.getPreferenceString("auth_instance_url", this.apiUrl()); + } else return this.apiUrl(); + }, getAuthToken() { - return this.getPreferenceString("authToken" + this.hashCode(this.apiUrl())); + return this.getPreferenceString("authToken" + this.hashCode(this.authApiUrl())); }, hashCode(s) { return s.split("").reduce(function (a, b) {