unauthenticated subscriptions (#1270)

* hmm

* unauthenticated feed

* unauthenticated rss

* Small improvements to code.

* add unauthenticated subscriptions

* cleanup

* Sort subs locally.

* Fix some bugs and small improvements.

Co-authored-by: Kavin <20838718+FireMasterK@users.noreply.github.com>
This commit is contained in:
Bnyro
2022-08-01 16:16:06 +02:00
committed by GitHub
parent 1ebf153814
commit c51a3a828e
7 changed files with 118 additions and 64 deletions

View File

@@ -69,7 +69,6 @@ export default {
},
},
activated() {
if (!this.authenticated) this.$router.push("/login");
document.title = "Import - Piped";
},
methods: {
@@ -132,21 +131,34 @@ export default {
});
},
handleImport() {
this.fetchJson(
this.authApiUrl() + "/import",
{
override: this.override,
},
{
method: "POST",
headers: {
Authorization: this.getAuthToken(),
if (this.authenticated) {
this.fetchJson(
this.authApiUrl() + "/import",
{
override: this.override,
},
body: JSON.stringify(this.subscriptions),
},
).then(json => {
if (json.message === "ok") window.location = "/feed";
});
{
method: "POST",
headers: {
Authorization: this.getAuthToken(),
},
body: JSON.stringify(this.subscriptions),
},
).then(json => {
if (json.message === "ok") window.location = "/feed";
});
} else {
this.importSubscriptionsLocally(this.subscriptions);
window.location = "/feed";
}
},
importSubscriptionsLocally(newChannels) {
const subscriptions = this.override
? [...new Set(newChannels)]
: [...new Set(this.getLocalSubscriptions().concat(newChannels))];
// Sort for better cache hits
subscriptions.sort();
localStorage.setItem("localSubscriptions", JSON.stringify(subscriptions));
},
},
};