fix && style

This commit is contained in:
小新
2021-01-19 09:59:09 +08:00
parent 48d5278907
commit 2170b22806
3 changed files with 48 additions and 37 deletions
@@ -7,45 +7,42 @@ $task_worker = new Worker('text://127.0.0.1:16345');
$task_worker->count = 10;
$task_worker->name = 'TaskWorker_github';
$datatime = date("Ymd");
$webDir = dirname(dirname(dirname(dirname(__FILE__)))) . "/staticweb/source/".$datatime;
$webDir = dirname(dirname(dirname(dirname(__FILE__)))) . "/staticweb/source/" . $datatime;
$task_worker->onMessage = function ($connection, $task_data) use ($webDir,$datatime) {
$task_worker->onMessage = function ($connection, $task_data) use ($webDir, $datatime) {
$dataArr = json_decode($task_data, true);
if(!$dataArr){
if (!$dataArr) {
return;
}
if(isset($dataArr['type'])){
switch($dataArr['type']){
if (isset($dataArr['type'])) {
switch ($dataArr['type']) {
case "1":
$pdo = new PDO('sqlite:' . dirname(dirname(dirname(__FILE__))) . '/sql');
$pdo->exec("UPDATE statistics SET down_num=down_num+1 where id=1");
$connection->send("true");
$pdo = null;
return true;
break;
case "2":
$pdo = new PDO('sqlite:' . dirname(dirname(dirname(__FILE__))) . '/sql');
$data = $pdo->query("select down_num from statistics where id=1")->fetch();
$down_num = $data[0];
$connection->send(json_encode([
'status' => 0,
'msg' =>"完成",
'data' =>[
'sta' => 4,
'down_num' => $down_num
]
],JSON_UNESCAPED_UNICODE) . "\r\n");
'status' => 0,
'msg' => "完成",
'data' => [
'sta' => 4,
'down_num' => $down_num
]
], JSON_UNESCAPED_UNICODE) . "\r\n");
$pdo = null;
$connection->send("true");
return true;
break;
}
}
if (preg_match("/%|\"|\.\.|\\\|\?|\||`|&|reboot|rm |mv |shutdown|<|>|sh |;|'/",$dataArr['url'])
if (preg_match("/%|\"|\.\.|\\\|\?|\||`|&|reboot|rm |mv |shutdown|<|>|sh |;|'/", $dataArr['url'])
||
(
!preg_match("/^((https|http):\/\/)?([\w\.\s\S\/\-\_^]+?)\.(tar\.gz|gz|tgz|tar\.bz2|bz2|msi|tar|zip|tar\.xz|tar\.z|rpm|deb|exe|apk|dmg|7z|rar)$/iu",$dataArr['url'],$ext)
!preg_match("/^((https|http):\/\/)?([\w\.\s\S\/\-\_^]+?)\.(tar\.gz|gz|tgz|tar\.bz2|bz2|msi|tar|zip|tar\.xz|tar\.z|rpm|deb|exe|apk|dmg|7z|rar)$/iu", $dataArr['url'], $ext)
&& !preg_match("/^https:\/\/github.com\/([\w\/\-\.\_]+)$/iu", $dataArr['url']
)
)
@@ -57,7 +54,7 @@ $task_worker->onMessage = function ($connection, $task_data) use ($webDir,$datat
if (!is_dir($webDir)) {
mkdir($webDir, 0777);
}
if(stristr($dataArr['url'],'github') && (!isset($ext) || !$ext)) {
if (stristr($dataArr['url'], 'github') && (!isset($ext) || !$ext)) {
//github的检出、打包
$connection->send(json_encode([
'status' => 0,
@@ -68,7 +65,7 @@ $task_worker->onMessage = function ($connection, $task_data) use ($webDir,$datat
], JSON_UNESCAPED_UNICODE) . "\r\n");
$git_dir_path = md5($dataArr['url']);
if (!is_dir($webDir . "/" . $git_dir_path) && !is_file($webDir . "/{$git_dir_path}.tar")) {
system('cd ' . $webDir . ';git clone --depth=50 "' . $dataArr['url'] . '" ' . $git_dir_path);
system('cd ' . $webDir . ';git clone --depth=50 "' . $dataArr['url'] . '" ' . $git_dir_path);
}
$connection->send(json_encode([
'status' => 0,
@@ -78,7 +75,7 @@ $task_worker->onMessage = function ($connection, $task_data) use ($webDir,$datat
]
], JSON_UNESCAPED_UNICODE) . "\r\n");
if (!is_file($webDir . "/{$git_dir_path}.tar")) {
if(!is_dir($webDir."/".$git_dir_path)){
if (!is_dir($webDir . "/" . $git_dir_path)) {
$connection->send(json_encode([
'status' => 1,
'msg' => "您输入的链接可能是不支持的后缀,如果是git仓储,请确认链接正确",
@@ -102,7 +99,7 @@ $task_worker->onMessage = function ($connection, $task_data) use ($webDir,$datat
]
], JSON_UNESCAPED_UNICODE) . "\r\n");
$connection->send("true");
}else{
} else {
//普通的压缩包下载处理
$connection->send(json_encode([
'status' => 0,
@@ -113,7 +110,7 @@ $task_worker->onMessage = function ($connection, $task_data) use ($webDir,$datat
], JSON_UNESCAPED_UNICODE) . "\r\n");
$fileExt = end($ext);
$fileName = md5($dataArr['url']) . ".{$fileExt}";
system('cd ' . $webDir . '; wget "'.$dataArr['url'] . '" -O '.$fileName);
system('cd ' . $webDir . '; wget "' . $dataArr['url'] . '" -O ' . $fileName);
$pdo = new PDO('sqlite:' . dirname(dirname(dirname(__FILE__))) . '/sql');
$pdo->exec("insert into file_info ('path', 'addtime') VALUES ('" . $webDir . "/{$fileName}" . "','" . time() . "')");
$pdo = null;
@@ -130,7 +127,6 @@ $task_worker->onMessage = function ($connection, $task_data) use ($webDir,$datat
}
};
if (!defined('GLOBAL_START')) {
Worker::runAll();