2021-07-22 20:05:48 +00:00
|
|
|
<template>
|
|
|
|
<h1 class="uk-text-bold uk-text-center">Subscriptions</h1>
|
|
|
|
|
2021-09-04 15:02:59 +00:00
|
|
|
<button
|
|
|
|
v-if="authenticated"
|
|
|
|
@click="exportHandler"
|
|
|
|
class="uk-button uk-button-small"
|
|
|
|
style="background: #222"
|
|
|
|
type="button"
|
|
|
|
>
|
|
|
|
<router-link to="/import">
|
|
|
|
Import from JSON
|
|
|
|
</router-link>
|
|
|
|
</button>
|
|
|
|
|
|
|
|
<br />
|
|
|
|
|
2021-07-31 18:48:38 +00:00
|
|
|
<button
|
|
|
|
v-if="authenticated"
|
|
|
|
@click="exportHandler"
|
|
|
|
class="uk-button uk-button-small"
|
|
|
|
style="background: #222"
|
|
|
|
type="button"
|
|
|
|
>
|
|
|
|
Export to JSON
|
|
|
|
</button>
|
|
|
|
|
2021-07-22 20:05:48 +00:00
|
|
|
<div :key="subscription.url" v-for="subscription in subscriptions">
|
|
|
|
<div class="uk-text-primary" :style="[{ background: backgroundColor }]">
|
|
|
|
<a :href="subscription.url">
|
2021-09-01 11:36:00 +00:00
|
|
|
<img :src="subscription.avatar" class="uk-margin-small-right uk-border-circle" width="50" height="50" />
|
2021-07-22 20:05:48 +00:00
|
|
|
<span class="uk-text-truncate">{{ subscription.name }}</span>
|
|
|
|
</a>
|
|
|
|
<button
|
|
|
|
class="uk-button uk-button-small"
|
|
|
|
style="background: #222"
|
|
|
|
type="button"
|
|
|
|
@click="handleButton(subscription)"
|
|
|
|
>
|
|
|
|
{{ subscription.subscribed ? "Unsubscribe" : "Subscribe" }}
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</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>
|