2021-07-22 20:05:48 +00:00
|
|
|
<template>
|
2021-12-27 14:46:26 +00:00
|
|
|
<h1 class="font-bold text-center">{{ $t("titles.subscriptions") }}</h1>
|
2021-09-05 13:08:26 +00:00
|
|
|
|
2021-12-27 14:46:26 +00:00
|
|
|
<div>
|
|
|
|
<button v-if="authenticated" class="uk-button uk-button-small" style=" margin-right: 0.5rem">
|
2021-09-04 18:30:13 +00:00
|
|
|
<router-link to="/import">
|
2021-09-05 13:08:26 +00:00
|
|
|
{{ $t("actions.import_from_json") }}
|
2021-09-04 18:30:13 +00:00
|
|
|
</router-link>
|
|
|
|
</button>
|
2021-09-04 15:02:59 +00:00
|
|
|
|
2021-12-27 14:46:26 +00:00
|
|
|
<button v-if="authenticated" class="uk-button uk-button-small" style="color: white" @click="exportHandler">
|
2021-09-05 13:08:26 +00:00
|
|
|
{{ $t("actions.export_to_json") }}
|
2021-09-04 18:30:13 +00:00
|
|
|
</button>
|
|
|
|
</div>
|
2021-10-08 18:52:51 +00:00
|
|
|
<hr />
|
2021-07-31 18:48:38 +00:00
|
|
|
|
2021-10-28 17:55:20 +00:00
|
|
|
<div v-for="subscription in subscriptions" :key="subscription.url" style="text-align: center">
|
2021-10-08 18:52:51 +00:00
|
|
|
<div class="uk-text-primary" :style="[{ background: backgroundColor }]">
|
|
|
|
<a :href="subscription.url">
|
2021-12-27 14:46:26 +00:00
|
|
|
<img :src="subscription.avatar" class="uk-margin-small-right rounded-full" width="96" height="96" />
|
2021-10-08 18:52:51 +00:00
|
|
|
<span
|
|
|
|
class="uk-text-large"
|
|
|
|
style="width: 30rem; display: inline-block; text-align: center; margin-left: 6rem"
|
|
|
|
>{{ subscription.name }}</span
|
2021-09-04 18:30:13 +00:00
|
|
|
>
|
2021-10-08 18:52:51 +00:00
|
|
|
</a>
|
|
|
|
<button
|
|
|
|
class="uk-button uk-button-large"
|
|
|
|
style="background: #222; margin-left: 0.5rem; width: 185px"
|
|
|
|
@click="handleButton(subscription)"
|
|
|
|
>
|
|
|
|
{{ subscription.subscribed ? $t("actions.unsubscribe") : $t("actions.subscribe") }}
|
|
|
|
</button>
|
2021-07-22 20:05:48 +00:00
|
|
|
</div>
|
2021-10-08 18:52:51 +00:00
|
|
|
<br />
|
|
|
|
</div>
|
2021-09-04 18:30:13 +00:00
|
|
|
<br />
|
2021-07-22 20:05:48 +00:00
|
|
|
</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-07-31 18:48:38 +00:00
|
|
|
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-22 20:05:48 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|