0
0
Fork 0
mirror of https://github.com/VueTubeApp/VueTube synced 2024-11-10 05:25:07 +00:00
VueTube/NUXT/store/channel/index.js

52 lines
2.4 KiB
JavaScript
Raw Normal View History

const getDefaultState = () => {
return {
loading: null,
error: null,
avatar: null,
banner: null,
title: null,
subscribe: null,
subscribeAlt: null,
descriptionPreview: null,
subscribers: null,
videos: null,
};
};
export const state = getDefaultState();
2022-05-14 04:16:15 +00:00
export const actions = {
fetchChannel({ state }, channelUrl) {
Object.assign(state, getDefaultState());
state.loading = true;
2022-05-14 04:16:15 +00:00
this.$youtube
2022-05-14 05:10:38 +00:00
.getChannel(
`https://youtube.com/channel/${channelUrl.substring(
channelUrl.lastIndexOf("/") + 1
2022-05-14 05:10:38 +00:00
)}`
)
2022-05-14 04:16:15 +00:00
.then((channel) => {
state.loading = false;
2022-05-14 04:16:15 +00:00
state.banner =
channel.header.channelMobileHeaderRenderer.channelHeader.elementRenderer.newElement.type.componentType.model.channelHeaderModel.channelBanner?.image.sources[0].url;
2022-05-14 04:16:15 +00:00
state.avatar =
channel.header.channelMobileHeaderRenderer.channelHeader.elementRenderer.newElement.type.componentType.model.channelHeaderModel.channelProfile.avatarData.avatar?.image.sources[0].url;
2022-05-14 04:16:15 +00:00
state.title =
channel.header.channelMobileHeaderRenderer.channelHeader.elementRenderer.newElement.type.componentType.model.channelHeaderModel.channelProfile.title;
state.subscribe =
channel.header.channelMobileHeaderRenderer.channelHeader.elementRenderer.newElement.type.componentType.model.channelHeaderModel.channelProfile.subscribeButton.subscribeButtonContent.buttonText;
state.subscribeAlt =
channel.header.channelMobileHeaderRenderer.channelHeader.elementRenderer.newElement.type.componentType.model.channelHeaderModel.channelProfile.subscribeButton.subscribeButtonContent.accessibilityText;
state.descriptionPreview =
channel.header.channelMobileHeaderRenderer.channelHeader.elementRenderer.newElement.type.componentType.model.channelHeaderModel.channelProfile.descriptionPreview.description;
state.subscribers =
channel.header.channelMobileHeaderRenderer.channelHeader.elementRenderer.newElement.type.componentType.model.channelHeaderModel.channelProfile.metadata.subscriberCountText;
state.videos =
channel.header.channelMobileHeaderRenderer.channelHeader.elementRenderer.newElement.type.componentType.model.channelHeaderModel.channelProfile.metadata.videosCountText;
})
.catch((err) => {
state.loading = false;
state.error = err;
console.error(err);
2022-05-14 04:16:15 +00:00
});
},
};