From b91245904cca2fc25314cbb21fa3c54d7c0a9a4e Mon Sep 17 00:00:00 2001 From: qkqpttgf <45693631+qkqpttgf@users.noreply.github.com> Date: Mon, 20 Dec 2021 10:44:51 +0800 Subject: [PATCH] add git source: HIT --- platform/Normal.php | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/platform/Normal.php b/platform/Normal.php index aea9c10..2cb9e4c 100644 --- a/platform/Normal.php +++ b/platform/Normal.php @@ -312,19 +312,23 @@ function setConfigResponse($response) return json_decode($response, true); } -function OnekeyUpate($auth = 'qkqpttgf', $project = 'OneManager-php', $branch = 'master') +function OnekeyUpate($GitSource = 'Github', $auth = 'qkqpttgf', $project = 'OneManager-php', $branch = 'master') { - $slash = '/'; - if (strpos(__DIR__, ':')) $slash = '\\'; + global $slash; // __DIR__ is xxx/platform $projectPath = splitlast(__DIR__, $slash)[0]; - // 从github下载对应tar.gz,并解压 - $url = 'https://github.com/' . $auth . '/' . $project . '/tarball/' . urlencode($branch) . '/'; + if ($GitSource=='Github') { + // 从github下载对应tar.gz,并解压 + $url = 'https://github.com/' . $auth . '/' . $project . '/tarball/' . urlencode($branch) . '/'; + } elseif ($GitSource=='HITGitlab') { + $url = 'https://git.hit.edu.cn/' . $auth . '/' . $project . '/-/archive/' . urlencode($branch) . '/' . $project . '-' . urlencode($branch) . '.tar.gz'; + } else return 0; $tarfile = $projectPath . $slash .'github.tar.gz'; $githubfile = file_get_contents($url); if (!$githubfile) return 0; file_put_contents($tarfile, $githubfile); + if (splitfirst(PHP_VERSION, '.')[0] > '5') { $phar = new PharData($tarfile); // need php5.3, 7, 8 $phar->extractTo($projectPath, null, true);//路径 要解压的文件 是否覆盖 @@ -336,14 +340,7 @@ function OnekeyUpate($auth = 'qkqpttgf', $project = 'OneManager-php', $branch = unlink($tarfile); $outPath = ''; - $tmp = scandir($projectPath); - $name = $auth . '-' . $project; - foreach ($tmp as $f) { - if ( substr($f, 0, strlen($name)) == $name) { - $outPath = $projectPath . $slash . $f; - break; - } - } + $outPath = findIndexPath($projectPath); //error_log1($outPath); if ($outPath=='') return 0; @@ -354,11 +351,12 @@ function OnekeyUpate($auth = 'qkqpttgf', $project = 'OneManager-php', $branch = $tmp1['message'] = "Can not move " . $projectPath . $slash . '.data' . $slash . 'config.php' . " to " . $outPath . $slash . '.data' . $slash . 'config.php'; return json_encode($tmp1); } - return moveFolder($outPath, $projectPath, $slash); + return moveFolder($outPath, $projectPath); } -function moveFolder($from, $to, $slash) +function moveFolder($from, $to) { + global $slash; if (substr($from, -1)==$slash) $from = substr($from, 0, -1); if (substr($to, -1)==$slash) $to = substr($to, 0, -1); if (!file_exists($to)) mkdir($to, 0777); @@ -368,7 +366,7 @@ function moveFolder($from, $to, $slash) $fromfile = $from . $slash . $filename; $tofile = $to . $slash . $filename; if(is_dir($fromfile)){// 如果读取的某个对象是文件夹,则递归 - $response = moveFolder($fromfile, $tofile, $slash); + $response = moveFolder($fromfile, $tofile); if (api_error(setConfigResponse($response))) return $response; }else{ //if (file_exists($tofile)) unlink($tofile);