From 0992e1e96d8bcc21c4ebe8f92ab859a15b7f750d Mon Sep 17 00:00:00 2001
From: FireMasterK <20838718+FireMasterK@users.noreply.github.com>
Date: Sat, 17 Jul 2021 04:26:41 +0530
Subject: [PATCH] Login and subscriptions. (#256)
* WIP login and subscriptions.
* Add a working feed and unsubscribe button.
* Allow importing subscriptions from Google Takeout, NewPipe and Invidious.
---
package.json | 1 +
src/components/Channel.vue | 44 ++++++++++-
src/components/FeedPage.vue | 74 ++++++++++++++++++
src/components/ImportPage.vue | 129 ++++++++++++++++++++++++++++++++
src/components/LoginPage.vue | 66 ++++++++++++++++
src/components/Navigation.vue | 14 ++++
src/components/RegisterPage.vue | 66 ++++++++++++++++
src/main.js | 23 ++++++
src/router/router.js | 20 +++++
yarn.lock | 12 +++
10 files changed, 448 insertions(+), 1 deletion(-)
create mode 100644 src/components/FeedPage.vue
create mode 100644 src/components/ImportPage.vue
create mode 100644 src/components/LoginPage.vue
create mode 100644 src/components/RegisterPage.vue
diff --git a/package.json b/package.json
index 39f7fdf2..49e2e2d6 100644
--- a/package.json
+++ b/package.json
@@ -17,6 +17,7 @@
"dompurify": "^2.3.0",
"hotkeys-js": "^3.8.7",
"mux.js": "^5.12.2",
+ "javascript-time-ago": "^2.3.8",
"register-service-worker": "^1.7.1",
"shaka-player": "3.2.0",
"uikit": "3.7.0",
diff --git a/src/components/Channel.vue b/src/components/Channel.vue
index fc30cd1e..8ba6dd19 100644
--- a/src/components/Channel.vue
+++ b/src/components/Channel.vue
@@ -6,6 +6,16 @@
@@ -28,6 +38,7 @@ export default {
data() {
return {
channel: null,
+ subscribed: false,
};
},
mounted() {
@@ -40,6 +51,21 @@ export default {
window.removeEventListener("scroll", this.handleScroll);
},
methods: {
+ async fetchSubscribedStatus() {
+ this.fetchJson(
+ this.apiUrl() + "/subscribed",
+ {
+ channelId: this.channel.id,
+ },
+ {
+ headers: {
+ Authorization: this.getAuthToken(),
+ },
+ },
+ ).then(json => {
+ this.subscribed = json.subscribed;
+ });
+ },
async fetchChannel() {
const url = this.apiUrl() + "/" + this.$route.params.path + "/" + this.$route.params.channelId;
return await this.fetchJson(url);
@@ -48,7 +74,10 @@ export default {
this.fetchChannel()
.then(data => (this.channel = data))
.then(() => {
- if (!this.channel.error) document.title = this.channel.name + " - Piped";
+ if (!this.channel.error) {
+ document.title = this.channel.name + " - Piped";
+ if (this.authenticated) this.fetchSubscribedStatus();
+ }
});
},
handleScroll() {
@@ -65,6 +94,19 @@ export default {
});
}
},
+ subscribeHandler() {
+ this.fetchJson(this.apiUrl() + (this.subscribed ? "/unsubscribe" : "/subscribe"), null, {
+ method: "POST",
+ body: JSON.stringify({
+ channelId: this.channel.id,
+ }),
+ headers: {
+ Authorization: this.getAuthToken(),
+ "Content-Type": "application/json",
+ },
+ });
+ this.subscribed = !this.subscribed;
+ },
},
components: {
ErrorHandler,
diff --git a/src/components/FeedPage.vue b/src/components/FeedPage.vue
new file mode 100644
index 00000000..390efee8
--- /dev/null
+++ b/src/components/FeedPage.vue
@@ -0,0 +1,74 @@
+
+ Feed
+
+ You can import subscriptions from here.
+
+
+
+
+
+
+
+
+ {{ video.title }}
+
+
+
+
+
+
+
+ {{ numberFormat(video.views) }} views
+
+
+
+ {{ timeAgo(video.uploaded) }}
+
+
+
+ {{ timeFormat(video.duration) }}
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/components/ImportPage.vue b/src/components/ImportPage.vue
new file mode 100644
index 00000000..f898cd70
--- /dev/null
+++ b/src/components/ImportPage.vue
@@ -0,0 +1,129 @@
+
+
+
+
+
Importing Subscriptions from YouTube
+
+
+ Open
+
takeout.google.com/takeout/custom/youtube
+
+ In "Select data to include", click on "All YouTube data included" and select only "subscriptions".
+
+ Create the export and download the zip file.
+
+ Extract subscriptions.json from the zip file.
+
+ Select and import the file above.
+
+
+
Importing Subscriptions from Invidious
+
+
+
+
Importing Subscriptions from NewPipe
+
+
+ Go to the Feed tab.
+
+ Click on the arrow on where it says "Subscriptions".
+
+ Save the file somewhere.
+
+ Select and import the file above.
+
+
+
+
+
diff --git a/src/components/LoginPage.vue b/src/components/LoginPage.vue
new file mode 100644
index 00000000..3be179e8
--- /dev/null
+++ b/src/components/LoginPage.vue
@@ -0,0 +1,66 @@
+
+
+
+
+
diff --git a/src/components/Navigation.vue b/src/components/Navigation.vue
index b154e006..5f923608 100644
--- a/src/components/Navigation.vue
+++ b/src/components/Navigation.vue
@@ -25,6 +25,15 @@
Preferences
+
+ Login
+
+
+ Register
+
+
+ Feed
+
@@ -60,6 +69,11 @@ export default {
suggestionsVisible: false,
};
},
+ computed: {
+ shouldShowLogin(_this) {
+ return _this.getAuthToken() == null;
+ },
+ },
methods: {
onKeyUp(e) {
if (e.key === "Enter") {
diff --git a/src/components/RegisterPage.vue b/src/components/RegisterPage.vue
new file mode 100644
index 00000000..afb4bc60
--- /dev/null
+++ b/src/components/RegisterPage.vue
@@ -0,0 +1,66 @@
+