add unauthenticated subscriptions

This commit is contained in:
Bnyro 2022-08-01 14:28:56 +02:00
parent f18388c828
commit 45a0b0a179
4 changed files with 40 additions and 26 deletions

View file

@ -1,7 +1,7 @@
<template> <template>
<h1 v-t="'titles.feed'" class="font-bold text-center my-4" /> <h1 v-t="'titles.feed'" class="font-bold text-center my-4" />
<button v-if="authenticated" class="btn mr-2" @click="exportHandler"> <button class="btn mr-2" @click="exportHandler">
<router-link to="/subscriptions">Subscriptions</router-link> <router-link to="/subscriptions">Subscriptions</router-link>
</button> </button>
@ -85,15 +85,6 @@ export default {
this.loadMoreVideos(); this.loadMoreVideos();
} }
}, },
getUnauthenticatedChannels() {
const localSubscriptions = this.getLocalSubscriptions();
var channels = "";
localSubscriptions.forEach((element, index) => {
channels += element;
if (localSubscriptions.size != index) channels += ",";
});
return channels;
},
}, },
}; };
</script> </script>

View file

@ -69,7 +69,6 @@ export default {
}, },
}, },
activated() { activated() {
if (!this.authenticated) this.$router.push("/login");
document.title = "Import - Piped"; document.title = "Import - Piped";
}, },
methods: { methods: {
@ -132,21 +131,25 @@ export default {
}); });
}, },
handleImport() { handleImport() {
this.fetchJson( if (this.authenticated) {
this.authApiUrl() + "/import", this.fetchJson(
{ this.authApiUrl() + "/import",
override: this.override, {
}, override: this.override,
{
method: "POST",
headers: {
Authorization: this.getAuthToken(),
}, },
body: JSON.stringify(this.subscriptions), {
}, method: "POST",
).then(json => { headers: {
if (json.message === "ok") window.location = "/feed"; Authorization: this.getAuthToken(),
}); },
body: JSON.stringify(this.subscriptions),
},
).then(json => {
if (json.message === "ok") window.location = "/feed";
});
} else {
this.importSubscriptionsLocally(this.subscriptions);
}
}, },
}, },
}; };

View file

@ -49,7 +49,14 @@ export default {
this.subscriptions = json; this.subscriptions = json;
this.subscriptions.forEach(subscription => (subscription.subscribed = true)); this.subscriptions.forEach(subscription => (subscription.subscribed = true));
}); });
else this.$router.push("/login"); else {
this.fetchJson(this.authApiUrl() + "/subscriptions/unauthenticated", null, {
channels: this.getUnauthenticatedChannels(),
}).then(json => {
this.subscriptions = json;
this.subscriptions.forEach(subscription => (subscription.subscribed = true));
});
}
}, },
activated() { activated() {
document.title = "Subscriptions - Piped"; document.title = "Subscriptions - Piped";

View file

@ -215,6 +215,19 @@ const mixin = {
else localSubscriptions.push(channelId); else localSubscriptions.push(channelId);
localStorage.setItem("localSubscriptions", JSON.stringify(localSubscriptions)); localStorage.setItem("localSubscriptions", JSON.stringify(localSubscriptions));
}, },
getUnauthenticatedChannels() {
const localSubscriptions = this.getLocalSubscriptions();
var channels = "";
localSubscriptions.forEach((element, index) => {
channels += element;
if (localSubscriptions.size != index) channels += ",";
});
return channels;
},
importSubscriptionsLocally(newChannels) {
const subscriptions = this.getLocalSubscriptions().concat(newChannels);
localStorage.setItem("localSubscriptions"), JSON.stringify(subscriptions);
},
}, },
computed: { computed: {
theme() { theme() {