Skip to content

Commit bdebb9f

Browse files
committed
feat(NavigationEndpoint): Add name property
Sometimes you can make assumptions based on the endpoint's object name.
1 parent 2940f7b commit bdebb9f

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

src/parser/classes/NavigationEndpoint.ts

+19-18
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,23 @@ import CreatePlaylistDialog from './CreatePlaylistDialog.js';
77
import type ModalWithTitleAndButton from './ModalWithTitleAndButton.js';
88
import OpenPopupAction from './actions/OpenPopupAction.js';
99

10+
export type Metadata = {
11+
url?: string;
12+
api_url?: string;
13+
page_type?: string;
14+
send_post?: boolean;
15+
};
16+
1017
export default class NavigationEndpoint extends YTNode {
1118
static type = 'NavigationEndpoint';
1219

13-
payload;
14-
dialog?: CreatePlaylistDialog | YTNode | null;
15-
modal?: ModalWithTitleAndButton | YTNode | null;
16-
open_popup?: OpenPopupAction | null;
17-
18-
next_endpoint?: NavigationEndpoint;
19-
20-
metadata: {
21-
url?: string;
22-
api_url?: string;
23-
page_type?: string;
24-
send_post?: boolean;
25-
};
20+
public name?: string;
21+
public payload: any;
22+
public dialog?: CreatePlaylistDialog | YTNode | null;
23+
public modal?: ModalWithTitleAndButton | YTNode | null;
24+
public open_popup?: OpenPopupAction | null;
25+
public next_endpoint?: NavigationEndpoint;
26+
public metadata: Metadata;
2627

2728
constructor(data: RawNode) {
2829
super();
@@ -33,13 +34,13 @@ export default class NavigationEndpoint extends YTNode {
3334
if (Reflect.has(data || {}, 'openPopupAction'))
3435
this.open_popup = new OpenPopupAction(data.openPopupAction);
3536

36-
const name = Object.keys(data || {})
37+
this.name = Object.keys(data || {})
3738
.find((item) =>
3839
item.endsWith('Endpoint') ||
3940
item.endsWith('Command')
4041
);
4142

42-
this.payload = name ? Reflect.get(data, name) : {};
43+
this.payload = this.name ? Reflect.get(data, this.name) : {};
4344

4445
if (Reflect.has(this.payload, 'dialog') || Reflect.has(this.payload, 'content')) {
4546
this.dialog = Parser.parseItem(this.payload.dialog || this.payload.content);
@@ -69,8 +70,8 @@ export default class NavigationEndpoint extends YTNode {
6970

7071
if (data?.commandMetadata?.webCommandMetadata?.apiUrl) {
7172
this.metadata.api_url = data.commandMetadata.webCommandMetadata.apiUrl.replace('/youtubei/v1/', '');
72-
} else if (name) {
73-
this.metadata.api_url = this.getEndpoint(name);
73+
} else if (this.name) {
74+
this.metadata.api_url = this.getPath(this.name);
7475
}
7576

7677
if (data?.commandMetadata?.webCommandMetadata?.sendPost) {
@@ -87,7 +88,7 @@ export default class NavigationEndpoint extends YTNode {
8788
/**
8889
* Sometimes InnerTube does not return an API url, in that case the library should set it based on the name of the payload object.
8990
*/
90-
getEndpoint(name: string) {
91+
getPath(name: string) {
9192
switch (name) {
9293
case 'browseEndpoint':
9394
return '/browse';

0 commit comments

Comments
 (0)