diff --git a/platform/Vercel_env.php b/platform/Vercel_env.php index 8b1888d..c0f3607 100644 --- a/platform/Vercel_env.php +++ b/platform/Vercel_env.php @@ -375,34 +375,33 @@ 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') { $tmppath = '/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(['error'=>['code'=>'Git Source input Error!']]); + $tarfile = $tmppath . '/github.tar.gz'; - $githubfile = file_get_contents($url); - if (!$githubfile) return '{"error":{"message":"fail to download from github"}}'; - file_put_contents($tarfile, $githubfile); - $phar = new PharData($tarfile); // need php5.3, 7, 8 - $phar->extractTo($tmppath, null, true);//路径 要解压的文件 是否覆盖 + file_put_contents($tarfile, file_get_contents($url)); + $phar = new PharData($tarfile); + $html = $phar->extractTo($tmppath, null, true);//路径 要解压的文件 是否覆盖 unlink($tarfile); - $outPath = ''; - $tmp = scandir($tmppath); - $name = $auth . '-' . $project; - mkdir($tmppath . "/" . $name, 0777); - foreach ($tmp as $f) { - if ( substr($f, 0, strlen($name)) == $name) { - rename($tmppath . '/' . $f, $tmppath . "/" . $name . '/api'); - $outPath = $tmppath . "/" . $name; - break; - } - } + // 获取解压出的目录名 + $outPath = findIndexPath($tmppath); + + if ($outPath=='') return '{"error":{"message":"no outpath"}}'; + $name = $project . 'CODE'; + mkdir($tmppath . "/" . $name, 0777, 1); + rename($outPath, $tmppath . "/" . $name . '/api'); + $outPath = $tmppath . "/" . $name; //echo $outPath . "
"; //error_log1($outPath); - if ($outPath=='') return '{"error":{"message":"no outpath"}}'; return VercelUpdate(getConfig('HerokuappId'), getConfig('APIKey'), $outPath); }