Skip to content

Commit

Permalink
fix(DecoratedAvatarView): Fix parsing and optional properties (#584)
Browse files Browse the repository at this point in the history
  • Loading branch information
absidue authored Jan 18, 2024
1 parent 6dd03e1 commit fed3512
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
20 changes: 8 additions & 12 deletions src/parser/classes/AvatarView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,20 @@ import { Thumbnail } from '../misc.js';
export default class AvatarView extends YTNode {
static type = 'AvatarView';

image: {
sources: Thumbnail[],
processor: {
border_image_processor: {
circular: boolean
}
image: Thumbnail[];
image_processor: {
border_image_processor: {
circular: boolean
}
};
avatar_image_size: string;

constructor(data: RawNode) {
super();
this.image = {
sources: data.image.sources.map((x: any) => new Thumbnail(x)).sort((a: Thumbnail, b: Thumbnail) => b.width - a.width),
processor: {
border_image_processor: {
circular: data.image.processor.borderImageProcessor.circular
}
this.image = Thumbnail.fromResponse(data.image);
this.image_processor = {
border_image_processor: {
circular: data.image.processor.borderImageProcessor.circular
}
};
this.avatar_image_size = data.avatarImageSize;
Expand Down
12 changes: 7 additions & 5 deletions src/parser/classes/DecoratedAvatarView.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import { YTNode } from '../helpers.js';
import type { RawNode } from '../index.js';
import { Parser, type RawNode } from '../index.js';
import NavigationEndpoint from './NavigationEndpoint.js';
import AvatarView from './AvatarView.js';

export default class DecoratedAvatarView extends YTNode {
static type = 'DecoratedAvatarView';

avatar: AvatarView;
avatar: AvatarView | null;
a11y_label: string;
on_tap_endpoint: NavigationEndpoint;
on_tap_endpoint?: NavigationEndpoint;

constructor(data: RawNode) {
super();
this.avatar = new AvatarView(data.avatar.avatarViewModel);
this.avatar = Parser.parseItem(data.avatar, AvatarView);
this.a11y_label = data.a11yLabel;
this.on_tap_endpoint = new NavigationEndpoint(data.rendererContext.commandContext.onTap.innertubeCommand);
if (data.rendererContext?.commandContext?.onTap) {
this.on_tap_endpoint = new NavigationEndpoint(data.rendererContext.commandContext.onTap);
}
}
}

0 comments on commit fed3512

Please sign in to comment.