unauthenticated feed

This commit is contained in:
Bnyro 2022-08-01 13:53:04 +02:00
parent e902c0b6e2
commit 5327a0ba58
3 changed files with 25 additions and 13 deletions

View file

@ -45,13 +45,11 @@ export default {
},
},
mounted() {
if (this.authenticated)
this.fetchFeed().then(videos => {
this.videosStore = videos;
this.loadMoreVideos();
this.updateWatched(this.videos);
});
else this.$router.push("/login");
this.fetchFeed().then(videos => {
this.videosStore = videos;
this.loadMoreVideos();
this.updateWatched(this.videos);
});
},
activated() {
document.title = this.$t("titles.feed") + " - Piped";
@ -66,9 +64,21 @@ export default {
},
methods: {
async fetchFeed() {
return await this.fetchJson(this.authApiUrl() + "/feed", {
authToken: this.getAuthToken(),
});
if (this.authenticated) {
return await this.fetchJson(this.authApiUrl() + "/feed", {
authToken: this.getAuthToken(),
});
} else {
const localSubscriptions = this.getLocalSubscriptions();
var channels = "";
localSubscriptions.forEach((element, index) => {
channels += element;
if (localSubscriptions.size != index) channels += ",";
});
return await this.fetchJson(this.authApiUrl() + "/feed/unauthenticated", {
channels: channels,
});
}
},
loadMoreVideos() {
this.currentVideoCount = Math.min(this.currentVideoCount + this.videoStep, this.videosStore.length);

View file

@ -52,7 +52,7 @@
<li v-if="authenticated">
<router-link v-t="'titles.playlists'" to="/playlists" />
</li>
<li v-if="authenticated && !shouldShowTrending">
<li v-if="!shouldShowTrending">
<router-link v-t="'titles.feed'" to="/feed" />
</li>
</ul>
@ -81,7 +81,7 @@
<li v-if="authenticated">
<router-link v-t="'titles.playlists'" to="/playlists" />
</li>
<li v-if="authenticated && !shouldShowTrending">
<li v-if="!shouldShowTrending">
<router-link v-t="'titles.feed'" to="/feed" />
</li>
</ul>

View file

@ -203,7 +203,9 @@ const mixin = {
return JSON.parse(localStorage.getItem("localSubscriptions"));
},
isSubscribedLocally(channelId) {
return this.getLocalSubscriptions().includes(channelId);
const localSubscriptions = this.getLocalSubscriptions();
if (localSubscriptions == null) return false;
return localSubscriptions.includes(channelId);
},
handleLocalSubscriptions(channelId) {
var localSubscriptions = this.getLocalSubscriptions();