From 68c07943e610c31d506d11b0cb695c39a2c45ebb Mon Sep 17 00:00:00 2001 From: qkqpttgf <45693631+qkqpttgf@users.noreply.github.com> Date: Mon, 20 Dec 2021 10:46:44 +0800 Subject: [PATCH] add git source: HIT --- platform/TencentSCF_env.php | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/platform/TencentSCF_env.php b/platform/TencentSCF_env.php index eae113d..492a081 100644 --- a/platform/TencentSCF_env.php +++ b/platform/TencentSCF_env.php @@ -560,29 +560,24 @@ function updateProgram($function_name, $Region, $Namespace, $SecretId, $SecretKe return curl('POST', 'https://'.$host, $payload, $headers)['body']; } -function OnekeyUpate($auth = 'qkqpttgf', $project = 'OneManager-php', $branch = 'master') +function OnekeyUpate($GitSource = 'Github', $auth = 'qkqpttgf', $project = 'OneManager-php', $branch = 'master') { $source = '/tmp/code.zip'; $outPath = '/tmp/'; - // 从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 json_encode(['Response'=>['Error'=>['code'=>'Git Source input Error!']]]); $tarfile = '/tmp/github.tar.gz'; file_put_contents($tarfile, file_get_contents($url)); $phar = new PharData($tarfile); $html = $phar->extractTo($outPath, null, true);//路径 要解压的文件 是否覆盖 - // 获取包中目录名 - $tmp = scandir('phar://'.$tarfile); - $name = $auth.'-'.$project; - foreach ($tmp as $f) { - if ( substr($f, 0, strlen($name)) == $name) { - $outPath .= $f; - break; - } - } - // 放入配置文件 - file_put_contents($outPath . '/.data/config.php', file_get_contents(__DIR__ . '/../.data/config.php')); + // 获取解压出的目录名 + $outPath = findIndexPath($outPath); // 将目录中文件打包成zip //$zip=new ZipArchive(); @@ -614,7 +609,7 @@ function addFileToZip($zip, $rootpath, $path = '') } } } - @closedir($path); + @closedir($handler); } function changeAuthKey() {