2021-07-22 20:05:48 +00:00
|
|
|
<template>
|
2022-08-01 14:16:06 +00:00
|
|
|
<div class="flex justify-between w-full">
|
2022-07-28 17:58:57 +00:00
|
|
|
<div class="flex">
|
2022-09-05 17:48:05 +00:00
|
|
|
<button class="btn mr-2">
|
2022-07-27 05:52:25 +00:00
|
|
|
<router-link to="/import" v-t="'actions.import_from_json'" />
|
|
|
|
</button>
|
|
|
|
<button class="btn" @click="exportHandler" v-t="'actions.export_to_json'" />
|
|
|
|
</div>
|
|
|
|
<i18n-t keypath="subscriptions.subscribed_channels_count">{{ subscriptions.length }}</i18n-t>
|
2021-09-04 18:30:13 +00:00
|
|
|
</div>
|
2021-10-08 18:52:51 +00:00
|
|
|
<hr />
|
2021-07-31 18:48:38 +00:00
|
|
|
|
2021-12-27 14:46:30 +00:00
|
|
|
<div class="grid">
|
|
|
|
<div class="mb-3" v-for="subscription in subscriptions" :key="subscription.url">
|
|
|
|
<div class="flex justify-center place-items-center">
|
2022-07-28 17:58:57 +00:00
|
|
|
<div class="w-full flex justify-between items-center">
|
2022-09-05 17:48:05 +00:00
|
|
|
<router-link :to="subscription.url" class="pp-import-channel flex font-bold">
|
|
|
|
<img :src="subscription.avatar" width="48" height="48" />
|
2022-07-28 17:58:57 +00:00
|
|
|
<span class="mx-2" v-text="subscription.name" />
|
2021-12-27 14:46:30 +00:00
|
|
|
</router-link>
|
2021-12-27 16:29:25 +00:00
|
|
|
<button
|
2022-08-17 13:34:57 +00:00
|
|
|
class="btn w-min"
|
2021-12-27 16:29:25 +00:00
|
|
|
@click="handleButton(subscription)"
|
2022-01-30 23:48:27 +00:00
|
|
|
v-t="`actions.${subscription.subscribed ? 'unsubscribe' : 'subscribe'}`"
|
2021-12-27 16:29:25 +00:00
|
|
|
/>
|
2021-12-27 14:46:30 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-07-22 20:05:48 +00:00
|
|
|
</div>
|
2021-10-08 18:52:51 +00:00
|
|
|
</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() {
|
2022-08-01 14:16:06 +00:00
|
|
|
this.fetchSubscriptions().then(json => {
|
|
|
|
this.subscriptions = json;
|
|
|
|
this.subscriptions.forEach(subscription => (subscription.subscribed = true));
|
|
|
|
});
|
2021-07-22 20:05:48 +00:00
|
|
|
},
|
|
|
|
activated() {
|
|
|
|
document.title = "Subscriptions - Piped";
|
|
|
|
},
|
|
|
|
methods: {
|
2022-08-01 14:16:06 +00:00
|
|
|
async fetchSubscriptions() {
|
|
|
|
if (this.authenticated) {
|
|
|
|
return await this.fetchJson(this.authApiUrl() + "/subscriptions", null, {
|
|
|
|
headers: {
|
|
|
|
Authorization: this.getAuthToken(),
|
|
|
|
},
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return await this.fetchJson(this.authApiUrl() + "/subscriptions/unauthenticated", {
|
|
|
|
channels: this.getUnauthenticatedChannels(),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2021-07-22 20:05:48 +00:00
|
|
|
handleButton(subscription) {
|
2022-08-01 16:29:49 +00:00
|
|
|
const channelId = subscription.url.split("/")[2];
|
|
|
|
if (this.authenticated) {
|
|
|
|
this.fetchJson(this.authApiUrl() + (subscription.subscribed ? "/unsubscribe" : "/subscribe"), null, {
|
|
|
|
method: "POST",
|
|
|
|
body: JSON.stringify({
|
|
|
|
channelId: channelId,
|
|
|
|
}),
|
|
|
|
headers: {
|
|
|
|
Authorization: this.getAuthToken(),
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
},
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.handleLocalSubscriptions(channelId);
|
|
|
|
}
|
2021-07-22 20:05:48 +00:00
|
|
|
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,
|
|
|
|
});
|
|
|
|
|
2022-08-02 08:14:03 +00:00
|
|
|
this.download(json, "subscriptions.json", "application/json");
|
2021-07-31 18:48:38 +00:00
|
|
|
},
|
2021-07-22 20:05:48 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|