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() { mounted() {
if (this.authenticated)
this.fetchFeed().then(videos => { this.fetchFeed().then(videos => {
this.videosStore = videos; this.videosStore = videos;
this.loadMoreVideos(); this.loadMoreVideos();
this.updateWatched(this.videos); this.updateWatched(this.videos);
}); });
else this.$router.push("/login");
}, },
activated() { activated() {
document.title = this.$t("titles.feed") + " - Piped"; document.title = this.$t("titles.feed") + " - Piped";
@ -66,9 +64,21 @@ export default {
}, },
methods: { methods: {
async fetchFeed() { async fetchFeed() {
if (this.authenticated) {
return await this.fetchJson(this.authApiUrl() + "/feed", { return await this.fetchJson(this.authApiUrl() + "/feed", {
authToken: this.getAuthToken(), 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() { loadMoreVideos() {
this.currentVideoCount = Math.min(this.currentVideoCount + this.videoStep, this.videosStore.length); this.currentVideoCount = Math.min(this.currentVideoCount + this.videoStep, this.videosStore.length);

View file

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

View file

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