@@ -83,9 +83,9 @@ public function __construct($token,$version){
83
83
$ this ->version = $ version ;
84
84
}
85
85
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 );
89
89
}
90
90
$ client = new Client (OPENBMCLAPIURL ,443 ,true );
91
91
$ client ->set (['timeout ' => -1 ]);
@@ -122,14 +122,14 @@ public function __construct($filesList = [], $maxConcurrent = 1) {
122
122
}
123
123
124
124
private function downloader (Swoole \Coroutine \Http \Client $ client , $ file ,$ bar ) {
125
- global $ DOWNLOAD_DIR ;
126
- $ filePath = $ DOWNLOAD_DIR . '/ ' . substr ($ file ->hash , 0 , 2 ) . '/ ' ;
125
+ $ download_dir = api:: getconfig ()[ ' file ' ][ ' cache_dir ' ] ;
126
+ $ filePath = $ download_dir . '/ ' . substr ($ file ->hash , 0 , 2 ) . '/ ' ;
127
127
if (!file_exists ($ filePath )) {
128
128
mkdir ($ filePath , 0777 , true );
129
129
}
130
130
$ savePath = $ filePath . $ file ->hash ;
131
131
$ file ->path = str_replace (' ' , '%20 ' , $ file ->path );
132
- $ downloader = $ client ->download ($ file ->path ,$ DOWNLOAD_DIR .'/ ' .substr ($ file ->hash , 0 , 2 ).'/ ' .$ file ->hash );
132
+ $ downloader = $ client ->download ($ file ->path ,$ download_dir .'/ ' .substr ($ file ->hash , 0 , 2 ).'/ ' .$ file ->hash );
133
133
if (!$ downloader ) {
134
134
mlog ("Error connecting to the main control: {$ client ->errMsg }" ,2 );
135
135
return false ;
@@ -151,7 +151,7 @@ private function downloader(Swoole\Coroutine\Http\Client $client, $file,$bar) {
151
151
'User-Agent ' => USERAGENT ,
152
152
'Accept ' => '*/* ' ,
153
153
]);
154
- $ downloader = $ client ->download ($ location_url ['path ' ].'? ' .($ location_url ['query ' ]??'' ),$ DOWNLOAD_DIR .'/ ' .substr ($ file ->hash , 0 , 2 ).'/ ' .$ file ->hash );
154
+ $ downloader = $ client ->download ($ location_url ['path ' ].'? ' .($ location_url ['query ' ]??'' ),$ download_dir .'/ ' .substr ($ file ->hash , 0 , 2 ).'/ ' .$ file ->hash );
155
155
if (in_array ($ client ->statusCode , [301 , 302 ])) {
156
156
while (in_array ($ client ->statusCode , [301 , 302 ])){
157
157
$ location_url = parse_url ($ client ->getHeaders ()['location ' ]);
@@ -168,7 +168,7 @@ private function downloader(Swoole\Coroutine\Http\Client $client, $file,$bar) {
168
168
'User-Agent ' => USERAGENT ,
169
169
'Accept ' => '*/* ' ,
170
170
]);
171
- $ downloader = $ client ->download ($ location_url ['path ' ].'? ' .($ location_url ['query ' ]??'' ),$ DOWNLOAD_DIR .'/ ' .substr ($ file ->hash , 0 , 2 ).'/ ' .$ file ->hash );
171
+ $ downloader = $ client ->download ($ location_url ['path ' ].'? ' .($ location_url ['query ' ]??'' ),$ download_dir .'/ ' .substr ($ file ->hash , 0 , 2 ).'/ ' .$ file ->hash );
172
172
}
173
173
if (!$ downloader ) {
174
174
echo PHP_EOL ;
@@ -191,7 +191,7 @@ private function downloader(Swoole\Coroutine\Http\Client $client, $file,$bar) {
191
191
}
192
192
elseif ($ client ->statusCode >= 400 ){
193
193
echo PHP_EOL ;
194
- mlog ("Download Failed: { $ client -> statusCode } | { $ file -> path } | {$ location_url ['host ' ]}: {$ location_url ['port ' ]}" ,2 );
194
+ mlog ("{ $ file -> path } Download Failed: { $ client -> statusCode } | {$ location_url ['host ' ]}: {$ location_url ['port ' ]}" ,2 );
195
195
$ bar ->progress ();
196
196
return false ;
197
197
}
@@ -211,7 +211,7 @@ private function downloader(Swoole\Coroutine\Http\Client $client, $file,$bar) {
211
211
212
212
public function downloadFiles () {
213
213
$ bar = new CliProgressBar (count ($ this ->filesList ));
214
- $ bar ->setDetails ("[Downloader] " );
214
+ $ bar ->setDetails ("[Downloader][线程数: { $ this -> maxConcurrent } ] " );
215
215
$ bar ->display ();
216
216
foreach ($ this ->filesList as $ file ) {
217
217
global $ shouldExit ;
@@ -246,9 +246,9 @@ public function downloadFiles() {
246
246
}
247
247
248
248
public function downloadnopoen ($ hash ) {
249
- global $ DOWNLOAD_DIR ;
249
+ $ download_dir = api:: getconfig ()[ ' file ' ][ ' cache_dir ' ] ;
250
250
global $ tokendata ;
251
- $ filePath = $ DOWNLOAD_DIR . '/ ' . substr ($ hash , 0 , 2 ) . '/ ' ;
251
+ $ filePath = $ download_dir . '/ ' . substr ($ hash , 0 , 2 ) . '/ ' ;
252
252
if (!file_exists ($ filePath )) {
253
253
mkdir ($ filePath , 0777 , true );
254
254
}
@@ -263,7 +263,7 @@ public function downloadnopoen($hash) {
263
263
'Accept ' => '*/* ' ,
264
264
'Authorization ' => "Bearer {$ tokendata ['token ' ]}"
265
265
]);
266
- $ downloader = $ client ->download ($ filepath ,$ DOWNLOAD_DIR .'/ ' .substr ($ hash , 0 , 2 ).'/ ' .$ hash );
266
+ $ downloader = $ client ->download ($ filepath ,$ download_dir .'/ ' .substr ($ hash , 0 , 2 ).'/ ' .$ hash );
267
267
if (!$ downloader ) {
268
268
mlog ("Error download to the main control: {$ client ->errMsg }" ,2 );
269
269
return false ;
@@ -290,14 +290,14 @@ public function FilesCheckerhash() {
290
290
$ bar = new CliProgressBar (count ($ this ->filesList ));
291
291
$ bar ->setDetails ("[FileCheck] " );
292
292
$ bar ->display ();
293
+ $ download_dir = api::getconfig ()['file ' ]['cache_dir ' ];
293
294
foreach ($ this ->filesList as $ file ) {
294
295
global $ shouldExit ;
295
- global $ DOWNLOAD_DIR ;
296
296
if ($ shouldExit ) {
297
297
return ;
298
298
break ;
299
299
}
300
- if (!file_exists ($ DOWNLOAD_DIR .'/ ' .substr ($ file ->hash , 0 , 2 ).'/ ' .$ file ->hash )){
300
+ if (!file_exists ($ download_dir .'/ ' .substr ($ file ->hash , 0 , 2 ).'/ ' .$ file ->hash )){
301
301
$ this ->Missfile [] = new BMCLAPIFile (
302
302
$ file ->path ,
303
303
$ file ->hash ,
@@ -306,7 +306,7 @@ public function FilesCheckerhash() {
306
306
);
307
307
}
308
308
else {
309
- if (hash_file ('sha1 ' ,$ DOWNLOAD_DIR .'/ ' .substr ($ file ->hash , 0 , 2 ).'/ ' .$ file ->hash ) != $ file ->hash ) {
309
+ if (hash_file ('sha1 ' ,$ download_dir .'/ ' .substr ($ file ->hash , 0 , 2 ).'/ ' .$ file ->hash ) != $ file ->hash ) {
310
310
$ this ->Missfile [] = new BMCLAPIFile (
311
311
$ file ->path ,
312
312
$ file ->hash ,
@@ -327,14 +327,14 @@ public function FilesCheckersize() {
327
327
$ bar = new CliProgressBar (count ($ this ->filesList ));
328
328
$ bar ->setDetails ("[FileCheck] " );
329
329
$ bar ->display ();
330
+ $ download_dir = api::getconfig ()['file ' ]['cache_dir ' ];
330
331
foreach ($ this ->filesList as $ file ) {
331
332
global $ shouldExit ;
332
- global $ DOWNLOAD_DIR ;
333
333
if ($ shouldExit ) {
334
334
return ;
335
335
break ;
336
336
}
337
- if (!file_exists ($ DOWNLOAD_DIR .'/ ' .substr ($ file ->hash , 0 , 2 ).'/ ' .$ file ->hash )){
337
+ if (!file_exists ($ download_dir .'/ ' .substr ($ file ->hash , 0 , 2 ).'/ ' .$ file ->hash )){
338
338
$ this ->Missfile [] = new BMCLAPIFile (
339
339
$ file ->path ,
340
340
$ file ->hash ,
@@ -343,7 +343,7 @@ public function FilesCheckersize() {
343
343
);
344
344
}
345
345
else {
346
- if (filesize ($ DOWNLOAD_DIR .'/ ' .substr ($ file ->hash , 0 , 2 ).'/ ' .$ file ->hash ) != $ file ->size ) {
346
+ if (filesize ($ download_dir .'/ ' .substr ($ file ->hash , 0 , 2 ).'/ ' .$ file ->hash ) != $ file ->size ) {
347
347
$ this ->Missfile [] = new BMCLAPIFile (
348
348
$ file ->path ,
349
349
$ file ->hash ,
@@ -364,14 +364,14 @@ public function FilesCheckerexists() {
364
364
$ bar = new CliProgressBar (count ($ this ->filesList ));
365
365
$ bar ->setDetails ("[FileCheck] " );
366
366
$ bar ->display ();
367
+ $ download_dir = api::getconfig ()['file ' ]['cache_dir ' ];
367
368
foreach ($ this ->filesList as $ file ) {
368
369
global $ shouldExit ;
369
- global $ DOWNLOAD_DIR ;
370
370
if ($ shouldExit ) {
371
371
return ;
372
372
break ;
373
373
}
374
- if (!file_exists ($ DOWNLOAD_DIR .'/ ' .substr ($ file ->hash , 0 , 2 ).'/ ' .$ file ->hash )){
374
+ if (!file_exists ($ download_dir .'/ ' .substr ($ file ->hash , 0 , 2 ).'/ ' .$ file ->hash )){
375
375
$ this ->Missfile [] = new BMCLAPIFile (
376
376
$ file ->path ,
377
377
$ file ->hash ,
0 commit comments