Skip to content

Commit

Permalink
client channel inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
MrBrax committed Nov 10, 2023
1 parent 431bbe3 commit acb0469
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 40 deletions.
24 changes: 23 additions & 1 deletion client-vue/src/core/Providers/Base/BaseChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type { Providers } from "@common/Defs";

export default class BaseChannel {
provider: Providers = "base";
uuid = "";
// userid = "";
// display_name = "";
// login = "";
Expand Down Expand Up @@ -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 {
Expand Down
27 changes: 12 additions & 15 deletions client-vue/src/core/Providers/Twitch/TwitchChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import BaseChannel from "../Base/BaseChannel";

export default class TwitchChannel extends BaseChannel {
readonly provider = "twitch";
uuid = "";

quality: VideoQuality[] = [];
broadcaster_type: BroadcasterType = "";
Expand All @@ -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;
}

Expand Down
28 changes: 4 additions & 24 deletions client-vue/src/core/Providers/YouTube/YouTubeChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit acb0469

Please sign in to comment.