@@ -100,41 +100,25 @@ public function register_endpoints() {
100
100
]
101
101
);
102
102
103
- register_rest_route (
104
- self ::$ namespace ,
105
- 'plugins-api ' ,
106
- [
107
- 'show_in_index ' => true ,
108
- 'methods ' => \WP_REST_Server::READABLE ,
109
- 'callback ' => [ $ this , 'get_api_data ' ],
110
- 'permission_callback ' => '__return_true ' ,
111
- 'args ' => [
112
- 'slug ' => [
113
- 'default ' => false ,
114
- 'required ' => true ,
115
- 'validate_callback ' => 'sanitize_title_with_dashes ' ,
116
- ],
117
- ],
118
- ]
119
- );
120
-
121
- register_rest_route (
122
- self ::$ namespace ,
123
- 'themes-api ' ,
124
- [
125
- 'show_in_index ' => true ,
126
- 'methods ' => \WP_REST_Server::READABLE ,
127
- 'callback ' => [ $ this , 'get_api_data ' ],
128
- 'permission_callback ' => '__return_true ' ,
129
- 'args ' => [
130
- 'slug ' => [
131
- 'default ' => false ,
132
- 'required ' => true ,
133
- 'validate_callback ' => 'sanitize_title_with_dashes ' ,
103
+ foreach ( [ 'plugins-api ' , 'themes-api ' , 'update-api ' ] as $ route ) {
104
+ register_rest_route (
105
+ self ::$ namespace ,
106
+ $ route ,
107
+ [
108
+ 'show_in_index ' => true ,
109
+ 'methods ' => \WP_REST_Server::READABLE ,
110
+ 'callback ' => [ $ this , 'get_api_data ' ],
111
+ 'permission_callback ' => '__return_true ' ,
112
+ 'args ' => [
113
+ 'slug ' => [
114
+ 'default ' => false ,
115
+ 'required ' => true ,
116
+ 'validate_callback ' => 'sanitize_title_with_dashes ' ,
117
+ ],
134
118
],
135
- ],
136
- ]
137
- );
119
+ ]
120
+ );
121
+ }
138
122
139
123
$ update_args = [
140
124
'key ' => [
@@ -404,16 +388,20 @@ public function get_api_data( \WP_REST_Request $request ) {
404
388
];
405
389
406
390
$ repo_cache = $ this ->get_repo_cache ( $ slug );
391
+ Singleton::get_instance ( 'Fragen\Git_Updater\API\API ' , $ this )->response = $ repo_cache ;
407
392
408
- if ( $ repo_api_data ['download_link ' ] && $ repo_api_data ['is_private ' ] || in_array ( $ repo_api_data ['git ' ], [ 'gitlab ' , 'gitea ' ], true )
393
+ if ( $ repo_api_data ['download_link ' ]
394
+ && ( $ repo_api_data ['is_private ' ] || in_array ( $ repo_api_data ['git ' ], [ 'gitlab ' , 'gitea ' ], true ) )
409
395
) {
410
396
$ repo_api_data ['auth_header ' ] = Singleton::get_instance ( 'Fragen\Git_Updater\API\API ' , $ this )->add_auth_header ( [], $ repo_api_data ['download_link ' ] );
411
397
$ repo_api_data ['auth_header ' ] = Singleton::get_instance ( 'Fragen\Git_Updater\API\API ' , $ this )->unset_release_asset_auth ( $ repo_api_data ['auth_header ' ], $ repo_api_data ['download_link ' ] );
412
398
}
413
399
414
400
if ( $ download && $ repo_data ->release_asset ) {
415
- if ( isset ( $ repo_cache ['release_asset_redirect ' ] ) ) {
416
- $ repo_api_data ['download_link ' ] = $ repo_cache ['release_asset_redirect ' ];
401
+ if ( isset ( $ repo_cache ['release_asset_download ' ] )
402
+ && 'bitbucket ' !== $ repo_api_data ['git ' ]
403
+ ) {
404
+ $ repo_api_data ['download_link ' ] = $ repo_cache ['release_asset_download ' ];
417
405
} elseif ( $ repo_cache ['release_asset ' ] ) {
418
406
$ _REQUEST ['override ' ] = true ;
419
407
$ repo_api_data ['download_link ' ] = Singleton::get_instance ( 'Fragen\Git_Updater\API\API ' , $ this )->get_release_asset_redirect ( $ repo_cache ['release_asset ' ], true );
0 commit comments