2021-07-23 01:35:48 +05:30
|
|
|
<template>
|
2021-12-27 20:16:26 +05:30
|
|
|
<h1 class="font-bold text-center">{{ $t("titles.subscriptions") }}</h1>
|
2021-09-05 18:38:26 +05:30
|
|
|
|
2021-12-27 20:16:30 +05:30
|
|
|
<div v-if="authenticated">
|
|
|
|
<button class="btn mr-0.5">
|
2021-09-05 00:00:13 +05:30
|
|
|
<router-link to="/import">
|
2021-09-05 18:38:26 +05:30
|
|
|
{{ $t("actions.import_from_json") }}
|
2021-09-05 00:00:13 +05:30
|
|
|
</router-link>
|
|
|
|
</button>
|
2021-09-04 20:32:59 +05:30
|
|
|
|
2021-12-27 20:16:30 +05:30
|
|
|
<button class="btn" @click="exportHandler">
|
2021-09-05 18:38:26 +05:30
|
|
|
{{ $t("actions.export_to_json") }}
|
2021-09-05 00:00:13 +05:30
|
|
|
</button>
|
|
|
|
</div>
|
2021-10-09 00:22:51 +05:30
|
|
|
<hr />
|
2021-08-01 00:18:38 +05:30
|
|
|
|
2021-12-27 20:16:30 +05:30
|
|
|
<div class="grid">
|
|
|
|
<div class="mb-3" v-for="subscription in subscriptions" :key="subscription.url">
|
|
|
|
<div class="flex justify-center place-items-center">
|
|
|
|
<div class="w-full grid grid-cols-3">
|
|
|
|
<router-link :to="subscription.url" class="col-start-2 block flex text-center font-bold text-4xl">
|
|
|
|
<img :src="subscription.avatar" class="rounded-full" width="48" height="48" />
|
|
|
|
<span>{{ subscription.name }}</span>
|
|
|
|
</router-link>
|
|
|
|
<button class="btn !w-min" @click="handleButton(subscription)">
|
|
|
|
{{ subscription.subscribed ? $t("actions.unsubscribe") : $t("actions.subscribe") }}
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-07-23 01:35:48 +05:30
|
|
|
</div>
|
2021-10-09 00:22:51 +05:30
|
|
|
</div>
|
2021-09-05 00:00:13 +05:30
|
|
|
<br />
|
2021-07-23 01:35:48 +05:30
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
subscriptions: [],
|
|
|
|
};
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
if (this.authenticated)
|
|
|
|
this.fetchJson(this.apiUrl() + "/subscriptions", null, {
|
|
|
|
headers: {
|
|
|
|
Authorization: this.getAuthToken(),
|
|
|
|
},
|
|
|
|
}).then(json => {
|
|
|
|
this.subscriptions = json;
|
|
|
|
this.subscriptions.forEach(subscription => (subscription.subscribed = true));
|
|
|
|
});
|
|
|
|
else this.$router.push("/login");
|
|
|
|
},
|
|
|
|
activated() {
|
|
|
|
document.title = "Subscriptions - Piped";
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
handleButton(subscription) {
|
|
|
|
this.fetchJson(this.apiUrl() + (subscription.subscribed ? "/unsubscribe" : "/subscribe"), null, {
|
|
|
|
method: "POST",
|
|
|
|
body: JSON.stringify({
|
|
|
|
channelId: subscription.url.split("/")[2],
|
|
|
|
}),
|
|
|
|
headers: {
|
|
|
|
Authorization: this.getAuthToken(),
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
},
|
|
|
|
});
|
|
|
|
subscription.subscribed = !subscription.subscribed;
|
|
|
|
},
|
2021-08-01 00:18:38 +05:30
|
|
|
exportHandler() {
|
|
|
|
const subscriptions = [];
|
|
|
|
|
|
|
|
this.subscriptions.forEach(subscription => {
|
|
|
|
subscriptions.push({
|
|
|
|
url: "https://www.youtube.com" + subscription.url,
|
|
|
|
name: subscription.name,
|
|
|
|
service_id: 0,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
const json = JSON.stringify({
|
|
|
|
app_version: "",
|
|
|
|
app_version_int: 0,
|
|
|
|
subscriptions: subscriptions,
|
|
|
|
});
|
|
|
|
|
|
|
|
var file = new Blob([json], { type: "application/json" });
|
|
|
|
|
|
|
|
const elem = document.createElement("a");
|
|
|
|
|
|
|
|
elem.href = URL.createObjectURL(file);
|
|
|
|
elem.download = "subscriptions.json";
|
|
|
|
elem.click();
|
|
|
|
elem.remove();
|
|
|
|
},
|
2021-07-23 01:35:48 +05:30
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|