@@ -121,6 +121,7 @@ public static function getLatestGithubRelease(string $name, array $source, bool
121
121
retries: self ::getRetryAttempts ()
122
122
), true );
123
123
$ url = null ;
124
+ $ filename = null ;
124
125
foreach ($ data as $ release ) {
125
126
if (($ source ['prefer-stable ' ] ?? false ) === true && $ release ['prerelease ' ] === true ) {
126
127
continue ;
@@ -131,16 +132,16 @@ public static function getLatestGithubRelease(string $name, array $source, bool
131
132
}
132
133
foreach ($ release ['assets ' ] as $ asset ) {
133
134
if (preg_match ('| ' . $ source ['match ' ] . '| ' , $ asset ['name ' ])) {
134
- $ url = $ asset ['browser_download_url ' ];
135
+ $ url = "https://api.github.com/repos/ {$ source ['repo ' ]}/releases/assets/ {$ asset ['id ' ]}" ;
136
+ $ filename = $ asset ['name ' ];
135
137
break 2 ;
136
138
}
137
139
}
138
140
}
139
141
140
- if (!$ url ) {
142
+ if (!$ url || ! $ filename ) {
141
143
throw new DownloaderException ("failed to find {$ name } release metadata " );
142
144
}
143
- $ filename = basename ($ url );
144
145
145
146
return [$ url , $ filename ];
146
147
}
@@ -191,7 +192,7 @@ public static function getFromFileList(string $name, array $source): array
191
192
* @throws RuntimeException
192
193
* @throws WrongUsageException
193
194
*/
194
- public static function downloadFile (string $ name , string $ url , string $ filename , ?string $ move_path = null , int $ download_as = SPC_DOWNLOAD_SOURCE ): void
195
+ public static function downloadFile (string $ name , string $ url , string $ filename , ?string $ move_path = null , int $ download_as = SPC_DOWNLOAD_SOURCE , array $ headers = [], array $ hooks = [] ): void
195
196
{
196
197
logger ()->debug ("Downloading {$ url }" );
197
198
$ cancel_func = function () use ($ filename ) {
@@ -201,7 +202,7 @@ public static function downloadFile(string $name, string $url, string $filename,
201
202
}
202
203
};
203
204
self ::registerCancelEvent ($ cancel_func );
204
- self ::curlDown (url: $ url , path: FileSystem::convertPath (DOWNLOAD_PATH . "/ {$ filename }" ), retries: self ::getRetryAttempts ());
205
+ self ::curlDown (url: $ url , path: FileSystem::convertPath (DOWNLOAD_PATH . "/ {$ filename }" ), headers: $ headers , hooks: $ hooks , retries: self ::getRetryAttempts ());
205
206
self ::unregisterCancelEvent ();
206
207
logger ()->debug ("Locking {$ filename }" );
207
208
if ($ download_as === SPC_DOWNLOAD_PRE_BUILT ) {
@@ -341,15 +342,15 @@ public static function downloadPackage(string $name, ?array $pkg = null, bool $f
341
342
break ;
342
343
case 'ghtar ' : // GitHub Release (tar)
343
344
[$ url , $ filename ] = self ::getLatestGithubTarball ($ name , $ pkg );
344
- self ::downloadFile ($ name , $ url , $ filename , $ pkg ['extract ' ] ?? null , SPC_DOWNLOAD_PACKAGE );
345
+ self ::downloadFile ($ name , $ url , $ filename , $ pkg ['extract ' ] ?? null , SPC_DOWNLOAD_PACKAGE , hooks: [[CurlHook::class, ' setupGithubToken ' ]] );
345
346
break ;
346
347
case 'ghtagtar ' : // GitHub Tag (tar)
347
348
[$ url , $ filename ] = self ::getLatestGithubTarball ($ name , $ pkg , 'tags ' );
348
- self ::downloadFile ($ name , $ url , $ filename , $ pkg ['extract ' ] ?? null , SPC_DOWNLOAD_PACKAGE );
349
+ self ::downloadFile ($ name , $ url , $ filename , $ pkg ['extract ' ] ?? null , SPC_DOWNLOAD_PACKAGE , hooks: [[CurlHook::class, ' setupGithubToken ' ]] );
349
350
break ;
350
351
case 'ghrel ' : // GitHub Release (uploaded)
351
352
[$ url , $ filename ] = self ::getLatestGithubRelease ($ name , $ pkg );
352
- self ::downloadFile ($ name , $ url , $ filename , $ pkg ['extract ' ] ?? null , SPC_DOWNLOAD_PACKAGE );
353
+ self ::downloadFile ($ name , $ url , $ filename , $ pkg ['extract ' ] ?? null , SPC_DOWNLOAD_PACKAGE , [ ' Accept: application/octet-stream ' ], [[CurlHook::class, ' setupGithubToken ' ]] );
353
354
break ;
354
355
case 'filelist ' : // Basic File List (regex based crawler)
355
356
[$ url , $ filename ] = self ::getFromFileList ($ name , $ pkg );
@@ -447,15 +448,15 @@ public static function downloadSource(string $name, ?array $source = null, bool
447
448
break ;
448
449
case 'ghtar ' : // GitHub Release (tar)
449
450
[$ url , $ filename ] = self ::getLatestGithubTarball ($ name , $ source );
450
- self ::downloadFile ($ name , $ url , $ filename , $ source ['path ' ] ?? null , $ download_as );
451
+ self ::downloadFile ($ name , $ url , $ filename , $ source ['path ' ] ?? null , $ download_as, hooks: [[CurlHook::class, ' setupGithubToken ' ]] );
451
452
break ;
452
453
case 'ghtagtar ' : // GitHub Tag (tar)
453
454
[$ url , $ filename ] = self ::getLatestGithubTarball ($ name , $ source , 'tags ' );
454
- self ::downloadFile ($ name , $ url , $ filename , $ source ['path ' ] ?? null , $ download_as );
455
+ self ::downloadFile ($ name , $ url , $ filename , $ source ['path ' ] ?? null , $ download_as, hooks: [[CurlHook::class, ' setupGithubToken ' ]] );
455
456
break ;
456
457
case 'ghrel ' : // GitHub Release (uploaded)
457
458
[$ url , $ filename ] = self ::getLatestGithubRelease ($ name , $ source );
458
- self ::downloadFile ($ name , $ url , $ filename , $ source ['path ' ] ?? null , $ download_as );
459
+ self ::downloadFile ($ name , $ url , $ filename , $ source ['path ' ] ?? null , $ download_as, [ ' Accept: application/octet-stream ' ], [[CurlHook::class, ' setupGithubToken ' ]] );
459
460
break ;
460
461
case 'filelist ' : // Basic File List (regex based crawler)
461
462
[$ url , $ filename ] = self ::getFromFileList ($ name , $ source );
0 commit comments