@@ -138,18 +138,50 @@ private function downloader(Swoole\Coroutine\Http\Client $client, $file,$bar) {
138
138
'User-Agent ' => 'openbmclapi-cluster/ ' . VERSION . ' ' . 'PHP-OpenBmclApi/0.0.1-dev ' ,
139
139
'Accept ' => '*/* ' ,
140
140
]);
141
- if (!$ client ->download ($ location_url ['path ' ].'? ' .($ location_url ['query ' ]??'' ),DOWNLOAD_DIR .'/ ' .substr ($ file ->hash , 0 , 2 ).'/ ' .$ file ->hash )) {
142
- echo PHP_EOL ;
143
- mlog ("{$ file ->path } Download Failed: {$ client ->errMsg } From Node: {$ location_url ['host ' ]}: {$ location_url ['port ' ]}" ,2 );
144
- $ bar ->progress ();
145
- return false ;
141
+ $ downloadr = $ client ->download ($ location_url ['path ' ].'? ' .($ location_url ['query ' ]??'' ),DOWNLOAD_DIR .'/ ' .substr ($ file ->hash , 0 , 2 ).'/ ' .$ file ->hash );
142
+ if (in_array ($ client ->statusCode , [301 , 302 ])) {
143
+ while (in_array ($ client ->statusCode , [301 , 302 ])){
144
+ $ location_url = parse_url ($ client ->getHeaders ()['location ' ]);
145
+ $ client ->close ();
146
+ if (!isset ($ array ['port ' ])){
147
+ $ location_url ['port ' ] = 443 ;
148
+ }
149
+ $ client = new Swoole \Coroutine \Http \Client ($ location_url ['host ' ], $ location_url ['port ' ], true );
150
+ $ client ->set ([
151
+ 'timeout ' => 60
152
+ ]);
153
+ $ client ->setHeaders ([
154
+ 'Host ' => $ location_url ['host ' ],
155
+ 'User-Agent ' => 'openbmclapi-cluster/ ' . VERSION . ' ' . 'PHP-OpenBmclApi/0.0.1-dev ' ,
156
+ 'Accept ' => '*/* ' ,
157
+ ]);
158
+ $ downloadr = $ client ->download ($ location_url ['path ' ].'? ' .($ location_url ['query ' ]??'' ),DOWNLOAD_DIR .'/ ' .substr ($ file ->hash , 0 , 2 ).'/ ' .$ file ->hash );
159
+ }
160
+ if (!$ downloadr ) {
161
+ echo PHP_EOL ;
162
+ mlog ("{$ file ->path } Download Failed: {$ client ->errMsg } From Node: {$ location_url ['host ' ]}: {$ location_url ['port ' ]}" ,2 );
163
+ $ bar ->progress ();
164
+ return false ;
165
+ }
166
+ else {
167
+ //mlog("Download Success");
168
+ $ bar ->progress ();
169
+ return true ;
170
+ }
146
171
}
147
172
else {
148
- //mlog("Download Success");
149
- $ bar ->progress ();
150
- return true ;
173
+ if (!$ downloadr ) {
174
+ echo PHP_EOL ;
175
+ mlog ("{$ file ->path } Download Failed: {$ client ->errMsg } From Node: {$ location_url ['host ' ]}: {$ location_url ['port ' ]}" ,2 );
176
+ $ bar ->progress ();
177
+ return false ;
178
+ }
179
+ else {
180
+ //mlog("Download Success");
181
+ $ bar ->progress ();
182
+ return true ;
183
+ }
151
184
}
152
- return true ;
153
185
}
154
186
}
155
187
0 commit comments