@@ -83,27 +83,25 @@ 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
- $ client = new Client (OPENBMCLAPIURL , 443 , true );
90
+ $ client = new Client (OPENBMCLAPIURL [ ' host ' ], OPENBMCLAPIURL [ ' port ' ], OPENBMCLAPIURL [ ' ssl ' ] );
91
91
$ client ->set (['timeout ' => -1 ]);
92
92
$ client ->setHeaders ([
93
- 'Host ' => OPENBMCLAPIURL ,
94
93
'User-Agent ' => 'openbmclapi-cluster/ ' .$ this ->version ,
95
94
'Accept ' => '* ' ,
96
95
'Authorization ' => "Bearer {$ this ->token }"
97
96
]);
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 );
101
100
$ client ->close ();
102
101
}
103
102
else {
104
- mlog ( " FileList Download Success " );
103
+ $ this -> compressedData = zstd_uncompress ( $ client -> body );
105
104
$ client ->close ();
106
- $ this ->compressedData = file_get_contents ("compress.zstd:// " .$ DOWNLOAD_DIR ."/filecache/filelist.zstd " );
107
105
}
108
106
$ parser = new ParseFileList ($ this ->compressedData );
109
107
$ files = $ parser ->parse ();
@@ -123,14 +121,14 @@ public function __construct($filesList = [], $maxConcurrent = 1) {
123
121
}
124
122
125
123
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 ) . '/ ' ;
128
126
if (!file_exists ($ filePath )) {
129
127
mkdir ($ filePath , 0777 , true );
130
128
}
131
129
$ savePath = $ filePath . $ file ->hash ;
132
130
$ 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 );
134
132
if (!$ downloader ) {
135
133
mlog ("Error connecting to the main control: {$ client ->errMsg }" ,2 );
136
134
return false ;
@@ -152,7 +150,7 @@ private function downloader(Swoole\Coroutine\Http\Client $client, $file,$bar) {
152
150
'User-Agent ' => USERAGENT ,
153
151
'Accept ' => '*/* ' ,
154
152
]);
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 );
156
154
if (in_array ($ client ->statusCode , [301 , 302 ])) {
157
155
while (in_array ($ client ->statusCode , [301 , 302 ])){
158
156
$ location_url = parse_url ($ client ->getHeaders ()['location ' ]);
@@ -169,7 +167,7 @@ private function downloader(Swoole\Coroutine\Http\Client $client, $file,$bar) {
169
167
'User-Agent ' => USERAGENT ,
170
168
'Accept ' => '*/* ' ,
171
169
]);
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 );
173
171
}
174
172
if (!$ downloader ) {
175
173
echo PHP_EOL ;
@@ -192,7 +190,7 @@ private function downloader(Swoole\Coroutine\Http\Client $client, $file,$bar) {
192
190
}
193
191
elseif ($ client ->statusCode >= 400 ){
194
192
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 );
196
194
$ bar ->progress ();
197
195
return false ;
198
196
}
@@ -212,7 +210,7 @@ private function downloader(Swoole\Coroutine\Http\Client $client, $file,$bar) {
212
210
213
211
public function downloadFiles () {
214
212
$ bar = new CliProgressBar (count ($ this ->filesList ));
215
- $ bar ->setDetails ("[Downloader] " );
213
+ $ bar ->setDetails ("[Downloader][线程数: { $ this -> maxConcurrent } ] " );
216
214
$ bar ->display ();
217
215
foreach ($ this ->filesList as $ file ) {
218
216
global $ shouldExit ;
@@ -221,12 +219,11 @@ public function downloadFiles() {
221
219
}
222
220
$ this ->semaphore ->push (true );
223
221
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 ' ] );
225
223
$ client ->set ([
226
224
'timeout ' => -1
227
225
]);
228
226
$ client ->setHeaders ([
229
- 'Host ' => 'openbmclapi.bangbang93.com ' ,
230
227
'User-Agent ' => USERAGENT ,
231
228
'Accept ' => '*/* ' ,
232
229
]);
@@ -247,24 +244,23 @@ public function downloadFiles() {
247
244
}
248
245
249
246
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 ) . '/ ' ;
253
250
if (!file_exists ($ filePath )) {
254
251
mkdir ($ filePath , 0777 , true );
255
252
}
256
253
$ 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 ' ] );
258
255
$ client ->set ([
259
256
'timeout ' => -1
260
257
]);
261
258
$ client ->setHeaders ([
262
- 'Host ' => 'openbmclapi.bangbang93.com ' ,
263
259
'User-Agent ' => USERAGENT ,
264
260
'Accept ' => '*/* ' ,
265
- 'Authorization ' => "Bearer {$ tokendata ['token ' ]}"
261
+ 'Authorization ' => "Bearer {$ tokenapi ['token ' ]}"
266
262
]);
267
- $ downloader = $ client ->download ($ filepath ,$ DOWNLOAD_DIR .'/ ' .substr ($ hash , 0 , 2 ).'/ ' .$ hash );
263
+ $ downloader = $ client ->download ($ filepath ,$ download_dir .'/ ' .substr ($ hash , 0 , 2 ).'/ ' .$ hash );
268
264
if (!$ downloader ) {
269
265
mlog ("Error download to the main control: {$ client ->errMsg }" ,2 );
270
266
return false ;
@@ -291,14 +287,14 @@ public function FilesCheckerhash() {
291
287
$ bar = new CliProgressBar (count ($ this ->filesList ));
292
288
$ bar ->setDetails ("[FileCheck] " );
293
289
$ bar ->display ();
290
+ $ download_dir = api::getconfig ()['file ' ]['cache_dir ' ];
294
291
foreach ($ this ->filesList as $ file ) {
295
292
global $ shouldExit ;
296
- global $ DOWNLOAD_DIR ;
297
293
if ($ shouldExit ) {
298
294
return ;
299
295
break ;
300
296
}
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 )){
302
298
$ this ->Missfile [] = new BMCLAPIFile (
303
299
$ file ->path ,
304
300
$ file ->hash ,
@@ -307,7 +303,7 @@ public function FilesCheckerhash() {
307
303
);
308
304
}
309
305
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 ) {
311
307
$ this ->Missfile [] = new BMCLAPIFile (
312
308
$ file ->path ,
313
309
$ file ->hash ,
@@ -328,14 +324,14 @@ public function FilesCheckersize() {
328
324
$ bar = new CliProgressBar (count ($ this ->filesList ));
329
325
$ bar ->setDetails ("[FileCheck] " );
330
326
$ bar ->display ();
327
+ $ download_dir = api::getconfig ()['file ' ]['cache_dir ' ];
331
328
foreach ($ this ->filesList as $ file ) {
332
329
global $ shouldExit ;
333
- global $ DOWNLOAD_DIR ;
334
330
if ($ shouldExit ) {
335
331
return ;
336
332
break ;
337
333
}
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 )){
339
335
$ this ->Missfile [] = new BMCLAPIFile (
340
336
$ file ->path ,
341
337
$ file ->hash ,
@@ -344,7 +340,7 @@ public function FilesCheckersize() {
344
340
);
345
341
}
346
342
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 ) {
348
344
$ this ->Missfile [] = new BMCLAPIFile (
349
345
$ file ->path ,
350
346
$ file ->hash ,
@@ -365,14 +361,14 @@ public function FilesCheckerexists() {
365
361
$ bar = new CliProgressBar (count ($ this ->filesList ));
366
362
$ bar ->setDetails ("[FileCheck] " );
367
363
$ bar ->display ();
364
+ $ download_dir = api::getconfig ()['file ' ]['cache_dir ' ];
368
365
foreach ($ this ->filesList as $ file ) {
369
366
global $ shouldExit ;
370
- global $ DOWNLOAD_DIR ;
371
367
if ($ shouldExit ) {
372
368
return ;
373
369
break ;
374
370
}
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 )){
376
372
$ this ->Missfile [] = new BMCLAPIFile (
377
373
$ file ->path ,
378
374
$ file ->hash ,
0 commit comments