Skip to content
This repository was archived by the owner on Mar 12, 2025. It is now read-only.

Commit 60fa0f2

Browse files
committed
🐛 修复同步时网盘节点多次302无法下载文件
1 parent 54a5860 commit 60fa0f2

File tree

2 files changed

+42
-10
lines changed

2 files changed

+42
-10
lines changed

inc/cluster.php

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,18 +138,50 @@ private function downloader(Swoole\Coroutine\Http\Client $client, $file,$bar) {
138138
'User-Agent' => 'openbmclapi-cluster/' . VERSION . ' ' . 'PHP-OpenBmclApi/0.0.1-dev',
139139
'Accept' => '*/*',
140140
]);
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+
}
146171
}
147172
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+
}
151184
}
152-
return true;
153185
}
154186
}
155187

main.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function registerSigintHandler() {
5858
if (is_array($Missfile)){
5959
mlog("缺失/损坏".count($Missfile)."个文件");
6060
while(is_array($Missfile)){
61-
$download = new download($Missfile,$config['maxConcurrent']);
61+
$download = new download($Missfile,$config['MaxConcurrent']);
6262
$download->downloadFiles();
6363
$FilesCheck = new FilesCheck($Missfile);
6464
$Missfile = $FilesCheck->FilesCheckerhash();

0 commit comments

Comments
 (0)