From acb046907ccdb3e977c3683c6eb63fb9f893c501 Mon Sep 17 00:00:00 2001 From: "CATERPILLAR\\Braxen" Date: Fri, 10 Nov 2023 12:33:51 +0100 Subject: [PATCH] client channel inheritance --- .../src/core/Providers/Base/BaseChannel.ts | 24 +++++++++++++++- .../core/Providers/Twitch/TwitchChannel.ts | 27 ++++++++---------- .../core/Providers/YouTube/YouTubeChannel.ts | 28 +++---------------- 3 files changed, 39 insertions(+), 40 deletions(-) diff --git a/client-vue/src/core/Providers/Base/BaseChannel.ts b/client-vue/src/core/Providers/Base/BaseChannel.ts index cb12c671..1d361751 100644 --- a/client-vue/src/core/Providers/Base/BaseChannel.ts +++ b/client-vue/src/core/Providers/Base/BaseChannel.ts @@ -10,6 +10,7 @@ import type { Providers } from "@common/Defs"; export default class BaseChannel { provider: Providers = "base"; + uuid = ""; // userid = ""; // display_name = ""; // login = ""; @@ -51,7 +52,28 @@ export default class BaseChannel { profilePictureUrl = ""; public static makeFromApiResponse(apiResponse: ApiBaseChannel): BaseChannel { - throw new Error("Not for base channel"); + + const channel = new BaseChannel(); + + channel.provider = apiResponse.provider; + channel.uuid = apiResponse.uuid; + channel.displayName = apiResponse.displayName; + channel.internalName = apiResponse.internalName; + channel.internalId = apiResponse.internalId; + channel.url = apiResponse.url; + channel.profilePictureUrl = apiResponse.profilePictureUrl; + channel.description = apiResponse.description; + // channel.quality = apiResponse.quality || []; + channel.vods_raw = apiResponse.vods_raw; + channel.clips_list = apiResponse.clips_list; + channel.video_list = apiResponse.video_list; + channel.no_capture = apiResponse.no_capture; + channel.is_live = apiResponse.is_live ?? false; + channel.current_stream_number = apiResponse.current_stream_number ?? 0; + channel.current_season = apiResponse.current_season ?? ""; + + return channel; + } get current_vod(): BaseVOD | undefined { diff --git a/client-vue/src/core/Providers/Twitch/TwitchChannel.ts b/client-vue/src/core/Providers/Twitch/TwitchChannel.ts index 377644ab..be8fc73d 100644 --- a/client-vue/src/core/Providers/Twitch/TwitchChannel.ts +++ b/client-vue/src/core/Providers/Twitch/TwitchChannel.ts @@ -9,7 +9,6 @@ import BaseChannel from "../Base/BaseChannel"; export default class TwitchChannel extends BaseChannel { readonly provider = "twitch"; - uuid = ""; quality: VideoQuality[] = []; broadcaster_type: BroadcasterType = ""; @@ -30,32 +29,30 @@ export default class TwitchChannel extends BaseChannel { declare chapter_data?: TwitchVODChapterJSON; public static makeFromApiResponse(apiResponse: ApiTwitchChannel): TwitchChannel { + + const { provider, ...baseChannel } = BaseChannel.makeFromApiResponse(apiResponse); // remove provider from baseChannel to avoid overwriting it const channel = new TwitchChannel(); - channel.uuid = apiResponse.uuid; - channel.description = apiResponse.description; + Object.assign(channel, baseChannel); + + // channel.uuid = apiResponse.uuid; + // channel.description = apiResponse.description; channel.quality = apiResponse.quality || []; - channel.vods_raw = apiResponse.vods_raw; + // channel.vods_raw = apiResponse.vods_raw; channel.vods_list = apiResponse.vods_list.map((vod) => TwitchVOD.makeFromApiResponse(vod)); channel.profile_image_url = apiResponse.profile_image_url; channel.offline_image_url = apiResponse.offline_image_url; channel.banner_image_url = apiResponse.banner_image_url; channel.api_getSubscriptionStatus = apiResponse.api_getSubscriptionStatus; - channel.clips_list = apiResponse.clips_list; - channel.video_list = apiResponse.video_list; channel.broadcaster_type = apiResponse.broadcaster_type; - channel.no_capture = apiResponse.no_capture; channel.channel_data = apiResponse.channel_data; - channel.current_stream_number = apiResponse.current_stream_number ?? 0; - channel.current_season = apiResponse.current_season ?? ""; // channel.is_capturing = apiResponse.is_capturing ?? false; - channel.is_live = apiResponse.is_live ?? false; channel.chapter_data = apiResponse.chapter_data as TwitchVODChapterJSON; // temp channel.saves_vods = apiResponse.saves_vods ?? false; - channel.displayName = apiResponse.displayName; - channel.internalName = apiResponse.internalName; - channel.internalId = apiResponse.internalId; - channel.url = apiResponse.url; - channel.profilePictureUrl = apiResponse.profilePictureUrl; + // channel.displayName = apiResponse.displayName; + // channel.internalName = apiResponse.internalName; + // channel.internalId = apiResponse.internalId; + // channel.url = apiResponse.url; + // channel.profilePictureUrl = apiResponse.profilePictureUrl; return channel; } diff --git a/client-vue/src/core/Providers/YouTube/YouTubeChannel.ts b/client-vue/src/core/Providers/YouTube/YouTubeChannel.ts index b06149f7..d870d697 100644 --- a/client-vue/src/core/Providers/YouTube/YouTubeChannel.ts +++ b/client-vue/src/core/Providers/YouTube/YouTubeChannel.ts @@ -23,36 +23,16 @@ export default class YouTubeChannel extends BaseChannel { // declare chapter_data?: BaseVODChapterJSON; public static makeFromApiResponse(apiResponse: ApiYouTubeChannel): YouTubeChannel { + + const { provider, ...baseChannel } = BaseChannel.makeFromApiResponse(apiResponse); // remove provider from baseChannel to avoid overwriting it const channel = new YouTubeChannel(); - // channel.provider = apiResponse.provider; - channel.uuid = apiResponse.uuid; - channel.channel_id = apiResponse.channel_id; - channel.display_name = apiResponse.display_name; - // channel.login = apiResponse.login; - channel.description = apiResponse.description; - // channel.quality = apiResponse.quality || []; - channel.vods_raw = apiResponse.vods_raw; + Object.assign(channel, baseChannel); + channel.vods_list = apiResponse.vods_list.map((vod) => YouTubeVOD.makeFromApiResponse(vod)); channel.profile_image_url = apiResponse.profile_image_url; - // channel.offline_image_url = apiResponse.offline_image_url; - // channel.banner_image_url = apiResponse.banner_image_url; channel.api_getSubscriptionStatus = apiResponse.api_getSubscriptionStatus; - channel.clips_list = apiResponse.clips_list; - channel.video_list = apiResponse.video_list; - // channel.broadcaster_type = apiResponse.broadcaster_type; - channel.no_capture = apiResponse.no_capture; - // channel.channel_data = apiResponse.channel_data; - channel.current_stream_number = apiResponse.current_stream_number ?? 0; - channel.current_season = apiResponse.current_season ?? ""; - // channel.is_capturing = apiResponse.is_capturing ?? false; - channel.is_live = apiResponse.is_live ?? false; channel.chapter_data = apiResponse.chapter_data as BaseVODChapterJSON; // temp // channel.saves_vods = apiResponse.saves_vods ?? false; - channel.displayName = apiResponse.displayName; - channel.internalName = apiResponse.internalName; - channel.internalId = apiResponse.internalId; - channel.url = apiResponse.url; - channel.profilePictureUrl = apiResponse.profilePictureUrl; return channel; } }