@@ -83,8 +83,9 @@ public function __construct($token,$version){
83
83
$ this ->version = $ version ;
84
84
}
85
85
public function getFileList () {
86
- if (!file_exists ("./cache/filecache " )) {
87
- mkdir ("./cache/filecache " ,0777 ,true );
86
+ global $ DOWNLOAD_DIR ;
87
+ if (!file_exists ($ DOWNLOAD_DIR ."/filecache " )) {
88
+ mkdir ($ DOWNLOAD_DIR ."/filecache " ,0777 ,true );
88
89
}
89
90
$ client = new Client (OPENBMCLAPI ,443 ,true );
90
91
$ client ->set (['timeout ' => -1 ]);
@@ -95,14 +96,14 @@ public function getFileList() {
95
96
'Authorization ' => "Bearer {$ this ->token }"
96
97
]);
97
98
mlog ("Start FileList Download " );
98
- if (!$ client ->download ('/openbmclapi/files ' ,DOWNLOAD_DIR .'/filecache/filelist.zstd ' )) {
99
+ if (!$ client ->download ('/openbmclapi/files ' ,$ DOWNLOAD_DIR .'/filecache/filelist.zstd ' )) {
99
100
mlog ("FileList Download Failed " ,2 );
100
101
$ client ->close ();
101
102
}
102
103
else {
103
104
mlog ("FileList Download Success " );
104
105
$ client ->close ();
105
- $ this ->compressedData = file_get_contents ("compress.zstd:// " .DOWNLOAD_DIR ."/filecache/filelist.zstd " );
106
+ $ this ->compressedData = file_get_contents ("compress.zstd:// " .$ DOWNLOAD_DIR ."/filecache/filelist.zstd " );
106
107
}
107
108
$ parser = new ParseFileList ($ this ->compressedData );
108
109
$ files = $ parser ->parse ();
@@ -122,7 +123,8 @@ public function __construct($filesList, $maxConcurrent) {
122
123
}
123
124
124
125
private function downloader (Swoole \Coroutine \Http \Client $ client , $ file ,$ bar ) {
125
- $ filePath = DOWNLOAD_DIR . '/ ' . substr ($ file ->hash , 0 , 2 ) . '/ ' ;
126
+ global $ DOWNLOAD_DIR ;
127
+ $ filePath = $ DOWNLOAD_DIR . '/ ' . substr ($ file ->hash , 0 , 2 ) . '/ ' ;
126
128
if (!file_exists ($ filePath )) {
127
129
mkdir ($ filePath , 0777 , true );
128
130
}
@@ -139,10 +141,10 @@ private function downloader(Swoole\Coroutine\Http\Client $client, $file,$bar) {
139
141
]);
140
142
$ client ->setHeaders ([
141
143
'Host ' => $ location_url ['host ' ],
142
- 'User-Agent ' => ' openbmclapi-cluster/ ' . VERSION . ' ' . ' PHP-OpenBmclApi/0.0.1-dev ' ,
144
+ 'User-Agent ' => USERAGENT ,
143
145
'Accept ' => '*/* ' ,
144
146
]);
145
- $ downloadr = $ client ->download ($ location_url ['path ' ].'? ' .($ location_url ['query ' ]??'' ),DOWNLOAD_DIR .'/ ' .substr ($ file ->hash , 0 , 2 ).'/ ' .$ file ->hash );
147
+ $ downloadr = $ client ->download ($ location_url ['path ' ].'? ' .($ location_url ['query ' ]??'' ),$ DOWNLOAD_DIR .'/ ' .substr ($ file ->hash , 0 , 2 ).'/ ' .$ file ->hash );
146
148
if (in_array ($ client ->statusCode , [301 , 302 ])) {
147
149
while (in_array ($ client ->statusCode , [301 , 302 ])){
148
150
$ location_url = parse_url ($ client ->getHeaders ()['location ' ]);
@@ -156,10 +158,10 @@ private function downloader(Swoole\Coroutine\Http\Client $client, $file,$bar) {
156
158
]);
157
159
$ client ->setHeaders ([
158
160
'Host ' => $ location_url ['host ' ],
159
- 'User-Agent ' => ' openbmclapi-cluster/ ' . VERSION . ' ' . ' PHP-OpenBmclApi/0.0.1-dev ' ,
161
+ 'User-Agent ' => USERAGENT ,
160
162
'Accept ' => '*/* ' ,
161
163
]);
162
- $ downloadr = $ client ->download ($ location_url ['path ' ].'? ' .($ location_url ['query ' ]??'' ),DOWNLOAD_DIR .'/ ' .substr ($ file ->hash , 0 , 2 ).'/ ' .$ file ->hash );
164
+ $ downloadr = $ client ->download ($ location_url ['path ' ].'? ' .($ location_url ['query ' ]??'' ),$ DOWNLOAD_DIR .'/ ' .substr ($ file ->hash , 0 , 2 ).'/ ' .$ file ->hash );
163
165
}
164
166
if (!$ downloadr ) {
165
167
echo PHP_EOL ;
@@ -206,7 +208,7 @@ public function downloadFiles() {
206
208
]);
207
209
$ client ->setHeaders ([
208
210
'Host ' => 'openbmclapi.bangbang93.com ' ,
209
- 'User-Agent ' => ' openbmclapi-cluster/ ' . VERSION . ' ' . ' PHP-OpenBmclApi/0.0.1-dev ' ,
211
+ 'User-Agent ' => USERAGENT ,
210
212
'Accept ' => '*/* ' ,
211
213
]);
212
214
if ($ this ->downloader ($ client , $ file ,$ bar )) {
@@ -237,10 +239,11 @@ public function FilesCheckerhash() {
237
239
$ bar ->display ();
238
240
foreach ($ this ->filesList as $ file ) {
239
241
global $ shouldExit ;
242
+ global $ DOWNLOAD_DIR ;
240
243
if ($ shouldExit ) {
241
244
break ;
242
245
}
243
- if (!file_exists (DOWNLOAD_DIR .'/ ' .substr ($ file ->hash , 0 , 2 ).'/ ' .$ file ->hash )){
246
+ if (!file_exists ($ DOWNLOAD_DIR .'/ ' .substr ($ file ->hash , 0 , 2 ).'/ ' .$ file ->hash )){
244
247
$ this ->Missfile [] = new BMCLAPIFile (
245
248
$ file ->path ,
246
249
$ file ->hash ,
@@ -249,7 +252,7 @@ public function FilesCheckerhash() {
249
252
);
250
253
}
251
254
else {
252
- if (hash_file ('sha1 ' ,DOWNLOAD_DIR .'/ ' .substr ($ file ->hash , 0 , 2 ).'/ ' .$ file ->hash ) != $ file ->hash ) {
255
+ if (hash_file ('sha1 ' ,$ DOWNLOAD_DIR .'/ ' .substr ($ file ->hash , 0 , 2 ).'/ ' .$ file ->hash ) != $ file ->hash ) {
253
256
$ this ->Missfile [] = new BMCLAPIFile (
254
257
$ file ->path ,
255
258
$ file ->hash ,
0 commit comments