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

Commit 8525e14

Browse files
authored
Merge pull request #12 from AppleBlockTeam/dev
同步 dev
2 parents 54e593b + a6996be commit 8525e14

13 files changed

+702
-185
lines changed

README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
PHP 版本 >= 8.0.0
2828

29-
[Swoole](https://www.swoole.com/) 版本 >= 5.1.
29+
[Swoole](https://www.swoole.com/) 版本 >= 5.1.0
3030

3131
以及对应版本的 [Zstd](https://github.com/kjdev/php-ext-zstd)
3232

@@ -66,13 +66,20 @@ $config=[
6666
"public_port"=> 4000,//服务端口
6767
"CLUSTER_ID"=> "",
6868
"CLUSTER_SECRET"=> "",
69-
"byoc"=>false,
69+
"byoc"=> false,
70+
"certificates"=>[ //如果 byoc 关闭,以下设置默认禁用
71+
"use-cert"=> false, //是否使用自己的证书
72+
"cert"=> "/path/to/cert.crt",
73+
"key"=> "/path/to/key.key",
74+
],
7075
],
7176
"file"=> [
7277
"cache_dir"=> "./cache",//缓存文件夹
7378
"check"=> "size",//检查文件策略(hash:检查文件hash size:检查文件大小 exists:检查文件是否存在)
79+
"database_dir"=> "./database",//访问数据数据库目录
7480
],
7581
"advanced"=> [
82+
"Centerurl"=> "https://openbmclapi.bangbang93.com",//主控链接(不建议调整)
7683
"keepalive"=> 60,//keepalive时间,秒为单位(不建议调整)
7784
"MaxConcurrent"=> 30,//下载使用的线程
7885
"Debug"=> false,//Debug开关
@@ -81,12 +88,13 @@ $config=[
8188
```
8289

8390
## 📍 Todo
84-
- [ ] Web仪表盘(主要)
91+
- [ ] 支持上报错误 url(主要)
8592
- [ ] 支持WebDAV
86-
- [ ] 打包二进制文件
87-
- [ ] 完善Log系统
8893
- [ ] 添加注释
8994
- [x] 可以正常上线使用
95+
- [x] 插件系统
96+
- [x] 完善Log系统
97+
- [ ] 打包二进制文件 (延期:[原因](https://github.com/crazywhalecc/static-php-cli/issues/479))
9098

9199
## ❓ FAQ
92100

config.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,20 @@
77
"public_port"=> 4000,//服务端口
88
"CLUSTER_ID"=> "",
99
"CLUSTER_SECRET"=> "",
10-
"byoc"=>false,
10+
"byoc"=> false,
11+
"certificates"=>[ //如果 byoc 关闭,以下设置默认禁用
12+
"use-cert"=> false, //是否使用自己的证书
13+
"cert"=> "/path/to/cert.crt",
14+
"key"=> "/path/to/key.key",
15+
],
1116
],
1217
"file"=> [
1318
"cache_dir"=> "./cache",//缓存文件夹
1419
"check"=> "size",//检查文件策略(hash:检查文件hash size:检查文件大小 exists:检查文件是否存在)
20+
"database_dir"=> "./database",//访问数据数据库目录
1521
],
1622
"advanced"=> [
23+
"Centerurl"=> "https://openbmclapi.staging.bangbang93.com",//主控链接(不建议调整)
1724
"keepalive"=> 60,//keepalive时间,秒为单位(不建议调整)
1825
"MaxConcurrent"=> 30,//下载使用的线程
1926
"Debug"=> false,//Debug开关

inc/PluginInfoInterface.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
namespace Plugin;
3+
4+
interface PluginInfoInterface {
5+
public function getInfo();
6+
public function main();
7+
}

inc/api.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
class api{
3+
private static $config = [];
4+
private static $info = ['enable'=>false,'isSynchronized'=>false,'uptime'=>0,'token'=>null];
5+
6+
public static function getconfig($newConfig = null) {
7+
if (!is_null($newConfig)) {
8+
self::$config = $newConfig;
9+
}
10+
return self::$config;
11+
}
12+
13+
public static function getinfo($newinfo = null) {
14+
if (!is_null($newinfo)) {
15+
self::$info = $newinfo;
16+
}
17+
return self::$info;
18+
}
19+
}

inc/cluster.php

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -83,27 +83,25 @@ public function __construct($token,$version){
8383
$this->version = $version;
8484
}
8585
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);
8989
}
90-
$client = new Client(OPENBMCLAPIURL,443,true);
90+
$client = new Client(OPENBMCLAPIURL['host'],OPENBMCLAPIURL['port'],OPENBMCLAPIURL['ssl']);
9191
$client->set(['timeout' => -1]);
9292
$client->setHeaders([
93-
'Host' => OPENBMCLAPIURL,
9493
'User-Agent' => 'openbmclapi-cluster/'.$this->version,
9594
'Accept' => '*',
9695
'Authorization' => "Bearer {$this->token}"
9796
]);
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);
101100
$client->close();
102101
}
103102
else{
104-
mlog("FileList Download Success");
103+
$this->compressedData = zstd_uncompress($client->body);
105104
$client->close();
106-
$this->compressedData = file_get_contents("compress.zstd://".$DOWNLOAD_DIR."/filecache/filelist.zstd");
107105
}
108106
$parser = new ParseFileList($this->compressedData);
109107
$files = $parser->parse();
@@ -123,14 +121,14 @@ public function __construct($filesList = [], $maxConcurrent = 1) {
123121
}
124122

125123
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) . '/';
128126
if (!file_exists($filePath)) {
129127
mkdir($filePath, 0777, true);
130128
}
131129
$savePath = $filePath . $file->hash;
132130
$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);
134132
if (!$downloader) {
135133
mlog("Error connecting to the main control:{$client->errMsg}",2);
136134
return false;
@@ -152,7 +150,7 @@ private function downloader(Swoole\Coroutine\Http\Client $client, $file,$bar) {
152150
'User-Agent' => USERAGENT,
153151
'Accept' => '*/*',
154152
]);
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);
156154
if (in_array($client->statusCode, [301, 302])) {
157155
while(in_array($client->statusCode, [301, 302])){
158156
$location_url = parse_url($client->getHeaders()['location']);
@@ -169,7 +167,7 @@ private function downloader(Swoole\Coroutine\Http\Client $client, $file,$bar) {
169167
'User-Agent' => USERAGENT,
170168
'Accept' => '*/*',
171169
]);
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);
173171
}
174172
if (!$downloader) {
175173
echo PHP_EOL;
@@ -192,7 +190,7 @@ private function downloader(Swoole\Coroutine\Http\Client $client, $file,$bar) {
192190
}
193191
elseif($client->statusCode >= 400){
194192
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);
196194
$bar->progress();
197195
return false;
198196
}
@@ -212,7 +210,7 @@ private function downloader(Swoole\Coroutine\Http\Client $client, $file,$bar) {
212210

213211
public function downloadFiles() {
214212
$bar = new CliProgressBar(count($this->filesList));
215-
$bar->setDetails("[Downloader]");
213+
$bar->setDetails("[Downloader][线程数:{$this->maxConcurrent}]");
216214
$bar->display();
217215
foreach ($this->filesList as $file) {
218216
global $shouldExit;
@@ -221,12 +219,11 @@ public function downloadFiles() {
221219
}
222220
$this->semaphore->push(true);
223221
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']);
225223
$client->set([
226224
'timeout' => -1
227225
]);
228226
$client->setHeaders([
229-
'Host' => 'openbmclapi.bangbang93.com',
230227
'User-Agent' => USERAGENT,
231228
'Accept' => '*/*',
232229
]);
@@ -247,24 +244,23 @@ public function downloadFiles() {
247244
}
248245

249246
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) . '/';
253250
if (!file_exists($filePath)) {
254251
mkdir($filePath, 0777, true);
255252
}
256253
$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']);
258255
$client->set([
259256
'timeout' => -1
260257
]);
261258
$client->setHeaders([
262-
'Host' => 'openbmclapi.bangbang93.com',
263259
'User-Agent' => USERAGENT,
264260
'Accept' => '*/*',
265-
'Authorization' => "Bearer {$tokendata['token']}"
261+
'Authorization' => "Bearer {$tokenapi['token']}"
266262
]);
267-
$downloader = $client->download($filepath,$DOWNLOAD_DIR.'/'.substr($hash, 0, 2).'/'.$hash);
263+
$downloader = $client->download($filepath,$download_dir.'/'.substr($hash, 0, 2).'/'.$hash);
268264
if (!$downloader) {
269265
mlog("Error download to the main control:{$client->errMsg}",2);
270266
return false;
@@ -291,14 +287,14 @@ public function FilesCheckerhash() {
291287
$bar = new CliProgressBar(count($this->filesList));
292288
$bar->setDetails("[FileCheck]");
293289
$bar->display();
290+
$download_dir = api::getconfig()['file']['cache_dir'];
294291
foreach ($this->filesList as $file) {
295292
global $shouldExit;
296-
global $DOWNLOAD_DIR;
297293
if ($shouldExit) {
298294
return;
299295
break;
300296
}
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)){
302298
$this->Missfile[] = new BMCLAPIFile(
303299
$file->path,
304300
$file->hash,
@@ -307,7 +303,7 @@ public function FilesCheckerhash() {
307303
);
308304
}
309305
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) {
311307
$this->Missfile[] = new BMCLAPIFile(
312308
$file->path,
313309
$file->hash,
@@ -328,14 +324,14 @@ public function FilesCheckersize() {
328324
$bar = new CliProgressBar(count($this->filesList));
329325
$bar->setDetails("[FileCheck]");
330326
$bar->display();
327+
$download_dir = api::getconfig()['file']['cache_dir'];
331328
foreach ($this->filesList as $file) {
332329
global $shouldExit;
333-
global $DOWNLOAD_DIR;
334330
if ($shouldExit) {
335331
return;
336332
break;
337333
}
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)){
339335
$this->Missfile[] = new BMCLAPIFile(
340336
$file->path,
341337
$file->hash,
@@ -344,7 +340,7 @@ public function FilesCheckersize() {
344340
);
345341
}
346342
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) {
348344
$this->Missfile[] = new BMCLAPIFile(
349345
$file->path,
350346
$file->hash,
@@ -365,14 +361,14 @@ public function FilesCheckerexists() {
365361
$bar = new CliProgressBar(count($this->filesList));
366362
$bar->setDetails("[FileCheck]");
367363
$bar->display();
364+
$download_dir = api::getconfig()['file']['cache_dir'];
368365
foreach ($this->filesList as $file) {
369366
global $shouldExit;
370-
global $DOWNLOAD_DIR;
371367
if ($shouldExit) {
372368
return;
373369
break;
374370
}
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)){
376372
$this->Missfile[] = new BMCLAPIFile(
377373
$file->path,
378374
$file->hash,

0 commit comments

Comments
 (0)