mirror of
https://github.com/TeamPiped/Piped.git
synced 2024-12-23 14:03:35 +00:00
Allow the usage of a different instance for authentication.
This commit is contained in:
parent
7803732da6
commit
37512b4e77
@ -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,
|
||||
|
@ -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(),
|
||||
});
|
||||
},
|
||||
|
@ -133,7 +133,7 @@ export default {
|
||||
},
|
||||
handleImport() {
|
||||
this.fetchJson(
|
||||
this.apiUrl() + "/import",
|
||||
this.authApiUrl() + "/import",
|
||||
{
|
||||
override: this.override,
|
||||
},
|
||||
|
@ -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);
|
||||
});
|
||||
|
@ -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(),
|
||||
},
|
||||
|
@ -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);
|
||||
|
@ -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,
|
||||
|
@ -203,11 +203,33 @@
|
||||
|
||||
<label for="ddlInstanceSelection"><strong v-text="`${$t('actions.instance_selection')}:`" /></label>
|
||||
<br />
|
||||
<select id="ddlInstanceSelection" v-model="selectedInstance" class="select w-auto" @change="onChange($event)">
|
||||
<select id="ddlInstanceSelection" v-model="selectedAuthInstance" class="select w-auto" @change="onChange($event)">
|
||||
<option v-for="instance in instances" :key="instance.name" :value="instance.api_url" v-text="instance.name" />
|
||||
</select>
|
||||
<br />
|
||||
<label for="chkAuthInstance"><strong v-text="`${$t('actions.different_auth_instance')}:`" /></label>
|
||||
<br />
|
||||
<input id="chkAuthInstance" v-model="authInstance" class="checkbox" type="checkbox" @change="onChange($event)" />
|
||||
<template v-if="authInstance">
|
||||
<br />
|
||||
<label for="ddlAuthInstanceSelection"><strong v-text="`${$t('actions.instance_auth_selection')}:`" /></label>
|
||||
<br />
|
||||
<select
|
||||
id="ddlAuthInstanceSelection"
|
||||
v-model="selectedAuthInstance"
|
||||
class="select w-auto"
|
||||
@change="onChange($event)"
|
||||
>
|
||||
<option
|
||||
v-for="instance in instances"
|
||||
:key="instance.name"
|
||||
:value="instance.api_url"
|
||||
v-text="instance.name"
|
||||
/>
|
||||
</select>
|
||||
</template>
|
||||
<!-- options that are visible only when logged in -->
|
||||
<br />
|
||||
<div v-if="this.authenticated">
|
||||
<label for="txtDeleteAccountPassword"><strong v-t="'actions.delete_account'" /></label>
|
||||
<br />
|
||||
@ -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(),
|
||||
|
@ -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);
|
||||
});
|
||||
|
@ -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],
|
||||
|
@ -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,
|
||||
|
@ -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",
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user