@@ -83,27 +83,25 @@ public function __construct($token,$version){
8383 $ this ->version = $ version ;
8484 }
8585 public function getFileList () {
86- global $ DOWNLOAD_DIR ;
87- if (!file_exists ($ DOWNLOAD_DIR ."/filecache " )) {
88- mkdir ($ DOWNLOAD_DIR ."/filecache " ,0777 ,true );
86+ $ download_dir = api:: getconfig ()[ ' file ' ][ ' cache_dir ' ] ;
87+ if (!file_exists ($ download_dir ."/filecache " )) {
88+ mkdir ($ download_dir ."/filecache " ,0777 ,true );
8989 }
90- $ client = new Client (OPENBMCLAPIURL , 443 , true );
90+ $ client = new Client (OPENBMCLAPIURL [ ' host ' ], OPENBMCLAPIURL [ ' port ' ], OPENBMCLAPIURL [ ' ssl ' ] );
9191 $ client ->set (['timeout ' => -1 ]);
9292 $ client ->setHeaders ([
93- 'Host ' => OPENBMCLAPIURL ,
9493 'User-Agent ' => 'openbmclapi-cluster/ ' .$ this ->version ,
9594 'Accept ' => '* ' ,
9695 'Authorization ' => "Bearer {$ this ->token }"
9796 ]);
98- mlog ("Start FileList Download " );
99- if (!$ client ->download ('/openbmclapi/files ' , $ DOWNLOAD_DIR . ' /filecache/filelist.zstd ' )) {
100- mlog ("FileList Download Failed " ,2 );
97+ mlog ("Starting to download fileList " );
98+ if (!$ client ->get ('/openbmclapi/files ' )) {
99+ mlog ("Failed to download fileList " ,2 );
101100 $ client ->close ();
102101 }
103102 else {
104- mlog ( " FileList Download Success " );
103+ $ this -> compressedData = zstd_uncompress ( $ client -> body );
105104 $ client ->close ();
106- $ this ->compressedData = file_get_contents ("compress.zstd:// " .$ DOWNLOAD_DIR ."/filecache/filelist.zstd " );
107105 }
108106 $ parser = new ParseFileList ($ this ->compressedData );
109107 $ files = $ parser ->parse ();
@@ -123,14 +121,14 @@ public function __construct($filesList = [], $maxConcurrent = 1) {
123121 }
124122
125123 private function downloader (Swoole \Coroutine \Http \Client $ client , $ file ,$ bar ) {
126- global $ DOWNLOAD_DIR ;
127- $ filePath = $ DOWNLOAD_DIR . '/ ' . substr ($ file ->hash , 0 , 2 ) . '/ ' ;
124+ $ download_dir = api:: getconfig ()[ ' file ' ][ ' cache_dir ' ] ;
125+ $ filePath = $ download_dir . '/ ' . substr ($ file ->hash , 0 , 2 ) . '/ ' ;
128126 if (!file_exists ($ filePath )) {
129127 mkdir ($ filePath , 0777 , true );
130128 }
131129 $ savePath = $ filePath . $ file ->hash ;
132130 $ file ->path = str_replace (' ' , '%20 ' , $ file ->path );
133- $ downloader = $ client ->download ($ file ->path ,$ DOWNLOAD_DIR .'/ ' .substr ($ file ->hash , 0 , 2 ).'/ ' .$ file ->hash );
131+ $ downloader = $ client ->download ($ file ->path ,$ download_dir .'/ ' .substr ($ file ->hash , 0 , 2 ).'/ ' .$ file ->hash );
134132 if (!$ downloader ) {
135133 mlog ("Error connecting to the main control: {$ client ->errMsg }" ,2 );
136134 return false ;
@@ -152,7 +150,7 @@ private function downloader(Swoole\Coroutine\Http\Client $client, $file,$bar) {
152150 'User-Agent ' => USERAGENT ,
153151 'Accept ' => '*/* ' ,
154152 ]);
155- $ downloader = $ client ->download ($ location_url ['path ' ].'? ' .($ location_url ['query ' ]??'' ),$ DOWNLOAD_DIR .'/ ' .substr ($ file ->hash , 0 , 2 ).'/ ' .$ file ->hash );
153+ $ downloader = $ client ->download ($ location_url ['path ' ].'? ' .($ location_url ['query ' ]??'' ),$ download_dir .'/ ' .substr ($ file ->hash , 0 , 2 ).'/ ' .$ file ->hash );
156154 if (in_array ($ client ->statusCode , [301 , 302 ])) {
157155 while (in_array ($ client ->statusCode , [301 , 302 ])){
158156 $ location_url = parse_url ($ client ->getHeaders ()['location ' ]);
@@ -169,7 +167,7 @@ private function downloader(Swoole\Coroutine\Http\Client $client, $file,$bar) {
169167 'User-Agent ' => USERAGENT ,
170168 'Accept ' => '*/* ' ,
171169 ]);
172- $ downloader = $ client ->download ($ location_url ['path ' ].'? ' .($ location_url ['query ' ]??'' ),$ DOWNLOAD_DIR .'/ ' .substr ($ file ->hash , 0 , 2 ).'/ ' .$ file ->hash );
170+ $ downloader = $ client ->download ($ location_url ['path ' ].'? ' .($ location_url ['query ' ]??'' ),$ download_dir .'/ ' .substr ($ file ->hash , 0 , 2 ).'/ ' .$ file ->hash );
173171 }
174172 if (!$ downloader ) {
175173 echo PHP_EOL ;
@@ -192,7 +190,7 @@ private function downloader(Swoole\Coroutine\Http\Client $client, $file,$bar) {
192190 }
193191 elseif ($ client ->statusCode >= 400 ){
194192 echo PHP_EOL ;
195- mlog ("Download Failed: { $ client -> statusCode } | { $ file -> path } | {$ location_url ['host ' ]}: {$ location_url ['port ' ]}" ,2 );
193+ mlog ("{ $ file -> path } Download Failed: { $ client -> statusCode } | {$ location_url ['host ' ]}: {$ location_url ['port ' ]}" ,2 );
196194 $ bar ->progress ();
197195 return false ;
198196 }
@@ -212,7 +210,7 @@ private function downloader(Swoole\Coroutine\Http\Client $client, $file,$bar) {
212210
213211 public function downloadFiles () {
214212 $ bar = new CliProgressBar (count ($ this ->filesList ));
215- $ bar ->setDetails ("[Downloader] " );
213+ $ bar ->setDetails ("[Downloader][线程数: { $ this -> maxConcurrent } ] " );
216214 $ bar ->display ();
217215 foreach ($ this ->filesList as $ file ) {
218216 global $ shouldExit ;
@@ -221,12 +219,11 @@ public function downloadFiles() {
221219 }
222220 $ this ->semaphore ->push (true );
223221 go (function () use ($ file ,$ bar ) {
224- $ client = new Swoole \Coroutine \Http \Client (' openbmclapi.bangbang93.com ' , 443 , true );
222+ $ client = new Swoole \Coroutine \Http \Client (OPENBMCLAPIURL [ ' host ' ], OPENBMCLAPIURL [ ' port ' ], OPENBMCLAPIURL [ ' ssl ' ] );
225223 $ client ->set ([
226224 'timeout ' => -1
227225 ]);
228226 $ client ->setHeaders ([
229- 'Host ' => 'openbmclapi.bangbang93.com ' ,
230227 'User-Agent ' => USERAGENT ,
231228 'Accept ' => '*/* ' ,
232229 ]);
@@ -247,24 +244,23 @@ public function downloadFiles() {
247244 }
248245
249246 public function downloadnopoen ($ hash ) {
250- global $ DOWNLOAD_DIR ;
251- global $ tokendata ;
252- $ filePath = $ DOWNLOAD_DIR . '/ ' . substr ($ hash , 0 , 2 ) . '/ ' ;
247+ $ download_dir = api:: getconfig ()[ ' file ' ][ ' cache_dir ' ] ;
248+ $ tokenapi = api:: getinfo () ;
249+ $ filePath = $ download_dir . '/ ' . substr ($ hash , 0 , 2 ) . '/ ' ;
253250 if (!file_exists ($ filePath )) {
254251 mkdir ($ filePath , 0777 , true );
255252 }
256253 $ filepath = "/openbmclapi/download/ {$ hash }?noopen=1 " ;
257- $ client = new Swoole \Coroutine \Http \Client (' openbmclapi.bangbang93.com ' , 443 , true );
254+ $ client = new Swoole \Coroutine \Http \Client (OPENBMCLAPIURL [ ' host ' ], OPENBMCLAPIURL [ ' port ' ], OPENBMCLAPIURL [ ' ssl ' ] );
258255 $ client ->set ([
259256 'timeout ' => -1
260257 ]);
261258 $ client ->setHeaders ([
262- 'Host ' => 'openbmclapi.bangbang93.com ' ,
263259 'User-Agent ' => USERAGENT ,
264260 'Accept ' => '*/* ' ,
265- 'Authorization ' => "Bearer {$ tokendata ['token ' ]}"
261+ 'Authorization ' => "Bearer {$ tokenapi ['token ' ]}"
266262 ]);
267- $ downloader = $ client ->download ($ filepath ,$ DOWNLOAD_DIR .'/ ' .substr ($ hash , 0 , 2 ).'/ ' .$ hash );
263+ $ downloader = $ client ->download ($ filepath ,$ download_dir .'/ ' .substr ($ hash , 0 , 2 ).'/ ' .$ hash );
268264 if (!$ downloader ) {
269265 mlog ("Error download to the main control: {$ client ->errMsg }" ,2 );
270266 return false ;
@@ -291,14 +287,14 @@ public function FilesCheckerhash() {
291287 $ bar = new CliProgressBar (count ($ this ->filesList ));
292288 $ bar ->setDetails ("[FileCheck] " );
293289 $ bar ->display ();
290+ $ download_dir = api::getconfig ()['file ' ]['cache_dir ' ];
294291 foreach ($ this ->filesList as $ file ) {
295292 global $ shouldExit ;
296- global $ DOWNLOAD_DIR ;
297293 if ($ shouldExit ) {
298294 return ;
299295 break ;
300296 }
301- if (!file_exists ($ DOWNLOAD_DIR .'/ ' .substr ($ file ->hash , 0 , 2 ).'/ ' .$ file ->hash )){
297+ if (!file_exists ($ download_dir .'/ ' .substr ($ file ->hash , 0 , 2 ).'/ ' .$ file ->hash )){
302298 $ this ->Missfile [] = new BMCLAPIFile (
303299 $ file ->path ,
304300 $ file ->hash ,
@@ -307,7 +303,7 @@ public function FilesCheckerhash() {
307303 );
308304 }
309305 else {
310- if (hash_file ('sha1 ' ,$ DOWNLOAD_DIR .'/ ' .substr ($ file ->hash , 0 , 2 ).'/ ' .$ file ->hash ) != $ file ->hash ) {
306+ if (hash_file ('sha1 ' ,$ download_dir .'/ ' .substr ($ file ->hash , 0 , 2 ).'/ ' .$ file ->hash ) != $ file ->hash ) {
311307 $ this ->Missfile [] = new BMCLAPIFile (
312308 $ file ->path ,
313309 $ file ->hash ,
@@ -328,14 +324,14 @@ public function FilesCheckersize() {
328324 $ bar = new CliProgressBar (count ($ this ->filesList ));
329325 $ bar ->setDetails ("[FileCheck] " );
330326 $ bar ->display ();
327+ $ download_dir = api::getconfig ()['file ' ]['cache_dir ' ];
331328 foreach ($ this ->filesList as $ file ) {
332329 global $ shouldExit ;
333- global $ DOWNLOAD_DIR ;
334330 if ($ shouldExit ) {
335331 return ;
336332 break ;
337333 }
338- if (!file_exists ($ DOWNLOAD_DIR .'/ ' .substr ($ file ->hash , 0 , 2 ).'/ ' .$ file ->hash )){
334+ if (!file_exists ($ download_dir .'/ ' .substr ($ file ->hash , 0 , 2 ).'/ ' .$ file ->hash )){
339335 $ this ->Missfile [] = new BMCLAPIFile (
340336 $ file ->path ,
341337 $ file ->hash ,
@@ -344,7 +340,7 @@ public function FilesCheckersize() {
344340 );
345341 }
346342 else {
347- if (filesize ($ DOWNLOAD_DIR .'/ ' .substr ($ file ->hash , 0 , 2 ).'/ ' .$ file ->hash ) != $ file ->size ) {
343+ if (filesize ($ download_dir .'/ ' .substr ($ file ->hash , 0 , 2 ).'/ ' .$ file ->hash ) != $ file ->size ) {
348344 $ this ->Missfile [] = new BMCLAPIFile (
349345 $ file ->path ,
350346 $ file ->hash ,
@@ -365,14 +361,14 @@ public function FilesCheckerexists() {
365361 $ bar = new CliProgressBar (count ($ this ->filesList ));
366362 $ bar ->setDetails ("[FileCheck] " );
367363 $ bar ->display ();
364+ $ download_dir = api::getconfig ()['file ' ]['cache_dir ' ];
368365 foreach ($ this ->filesList as $ file ) {
369366 global $ shouldExit ;
370- global $ DOWNLOAD_DIR ;
371367 if ($ shouldExit ) {
372368 return ;
373369 break ;
374370 }
375- if (!file_exists ($ DOWNLOAD_DIR .'/ ' .substr ($ file ->hash , 0 , 2 ).'/ ' .$ file ->hash )){
371+ if (!file_exists ($ download_dir .'/ ' .substr ($ file ->hash , 0 , 2 ).'/ ' .$ file ->hash )){
376372 $ this ->Missfile [] = new BMCLAPIFile (
377373 $ file ->path ,
378374 $ file ->hash ,
0 commit comments