@@ -7,22 +7,23 @@ import CreatePlaylistDialog from './CreatePlaylistDialog.js';
7
7
import type ModalWithTitleAndButton from './ModalWithTitleAndButton.js' ;
8
8
import OpenPopupAction from './actions/OpenPopupAction.js' ;
9
9
10
+ export type Metadata = {
11
+ url ?: string ;
12
+ api_url ?: string ;
13
+ page_type ?: string ;
14
+ send_post ?: boolean ;
15
+ } ;
16
+
10
17
export default class NavigationEndpoint extends YTNode {
11
18
static type = 'NavigationEndpoint' ;
12
19
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 ;
26
27
27
28
constructor ( data : RawNode ) {
28
29
super ( ) ;
@@ -33,13 +34,13 @@ export default class NavigationEndpoint extends YTNode {
33
34
if ( Reflect . has ( data || { } , 'openPopupAction' ) )
34
35
this . open_popup = new OpenPopupAction ( data . openPopupAction ) ;
35
36
36
- const name = Object . keys ( data || { } )
37
+ this . name = Object . keys ( data || { } )
37
38
. find ( ( item ) =>
38
39
item . endsWith ( 'Endpoint' ) ||
39
40
item . endsWith ( 'Command' )
40
41
) ;
41
42
42
- this . payload = name ? Reflect . get ( data , name ) : { } ;
43
+ this . payload = this . name ? Reflect . get ( data , this . name ) : { } ;
43
44
44
45
if ( Reflect . has ( this . payload , 'dialog' ) || Reflect . has ( this . payload , 'content' ) ) {
45
46
this . dialog = Parser . parseItem ( this . payload . dialog || this . payload . content ) ;
@@ -69,8 +70,8 @@ export default class NavigationEndpoint extends YTNode {
69
70
70
71
if ( data ?. commandMetadata ?. webCommandMetadata ?. apiUrl ) {
71
72
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 ) ;
74
75
}
75
76
76
77
if ( data ?. commandMetadata ?. webCommandMetadata ?. sendPost ) {
@@ -87,7 +88,7 @@ export default class NavigationEndpoint extends YTNode {
87
88
/**
88
89
* Sometimes InnerTube does not return an API url, in that case the library should set it based on the name of the payload object.
89
90
*/
90
- getEndpoint ( name : string ) {
91
+ getPath ( name : string ) {
91
92
switch ( name ) {
92
93
case 'browseEndpoint' :
93
94
return '/browse' ;
0 commit comments