Update Vercel-php to 0.6.0

pull/700/head
qkqpttgf 2023-08-20 17:08:48 +08:00 committed by GitHub
parent ef70b6bcb5
commit 596955ffe0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 102 additions and 108 deletions

View File

@ -1,8 +1,7 @@
<?php
// https://vercel.com/docs/api#endpoints/deployments/create-a-new-deployment
function getpath()
{
function getpath() {
$_SERVER['firstacceptlanguage'] = strtolower(splitfirst(splitfirst($_SERVER['HTTP_ACCEPT_LANGUAGE'], ';')[0], ',')[0]);
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_FORWARDED_FOR'];
if (isset($_SERVER['HTTP_FLY_CLIENT_IP'])) $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_FLY_CLIENT_IP'];
@ -24,8 +23,7 @@ function getpath()
return $path;
}
function getGET()
{
function getGET() {
if (!$_POST) {
if (!!$HTTP_RAW_POST_DATA) {
$tmpdata = $HTTP_RAW_POST_DATA;
@ -64,8 +62,7 @@ function getGET()
}
}
function getConfig($str, $disktag = '')
{
function getConfig($str, $disktag = '') {
$projectPath = splitlast(__DIR__, '/')[0];
$configPath = $projectPath . '/.data/config.php';
$s = file_get_contents($configPath);
@ -88,8 +85,7 @@ function getConfig($str, $disktag = '')
return '';
}
function setConfig($arr, $disktag = '')
{
function setConfig($arr, $disktag = '') {
if ($disktag == '') $disktag = $_SERVER['disktag'];
$projectPath = splitlast(__DIR__, '/')[0];
$configPath = $projectPath . '/.data/config.php';
@ -143,6 +139,7 @@ function setConfig($arr, $disktag = '')
$envs[$arr['disktag_rename']] = '';
} else {
$disktags = array_unique($disktags);
$disktag_s = "";
foreach ($disktags as $disktag) if ($disktag != '') $disktag_s .= $disktag . '|';
if ($disktag_s != '') $envs['disktag'] = substr($disktag_s, 0, -1);
else $envs['disktag'] = '';
@ -156,8 +153,7 @@ function setConfig($arr, $disktag = '')
return setVercelConfig($envs, getConfig('HerokuappId'), getConfig('APIKey'));
}
function install()
{
function install() {
global $constStr;
if ($_GET['install1']) {
if ($_POST['admin'] != '') {
@ -181,7 +177,7 @@ function install()
if ($host == $aliase["alias"]) $projectId = $aliase["projectId"];
}
if (!$projectId) {
$html = 'Please visit from: ' . json_encode($aliases1);
$html = 'Please visit from one of: ' . json_encode($aliases1, JSON_PRETTY_PRINT);
return message($html, 'Error', 400);
}
$tmp['HerokuappId'] = $projectId;
@ -209,12 +205,13 @@ function install()
}
}, 1000);
</script>';
$title = "Success";
return message($html, $title, 201, 1);
}
}
}
if ($_GET['install0']) {
$html .= '
$html = '
<form action="?install1" method="post" onsubmit="return notnull(this);">
language:<br>';
foreach ($constStr['languages'] as $key1 => $value1) {
@ -264,7 +261,7 @@ language:<br>';
}
//if (substr($_SERVER["host"], -10)=="vercel.app") {
$html .= '<a href="?install0">' . getconstStr('ClickInstall') . '</a>, ' . getconstStr('LogintoBind');
$html = '<a href="?install0">' . getconstStr('ClickInstall') . '</a>, ' . getconstStr('LogintoBind');
$html .= "<br>Remember: you MUST wait 30-60s after each operate / do some change, that make sure Vercel has done the building<br>";
//} else {
// $html.= "Please visit form *.vercel.app";
@ -273,8 +270,7 @@ language:<br>';
return message($html, $title, 201);
}
function copyFolder($from, $to)
{
function copyFolder($from, $to) {
if (substr($from, -1) == '/') $from = substr($from, 0, -1);
if (substr($to, -1) == '/') $to = substr($to, 0, -1);
if (!file_exists($to)) mkdir($to, 0777, 1);
@ -294,8 +290,7 @@ function copyFolder($from, $to)
return 1;
}
function setVercelConfig($envs, $appId, $token)
{
function setVercelConfig($envs, $appId, $token) {
sortConfig($envs);
$outPath = '/tmp/code/';
$outPath_Api = $outPath . 'api/';
@ -310,8 +305,7 @@ function setVercelConfig($envs, $appId, $token)
return VercelUpdate($appId, $token, $outPath);
}
function VercelUpdate($appId, $token, $sourcePath = "")
{
function VercelUpdate($appId, $token, $sourcePath = "") {
if (checkBuilding($appId, $token)) return '{"error":{"message":"Another building is in progress."}}';
$url = "https://api.vercel.com/v13/deployments";
$header["Authorization"] = "Bearer " . $token;
@ -321,7 +315,7 @@ function VercelUpdate($appId, $token, $sourcePath = "")
$data["target"] = "production";
$data["routes"][0]["src"] = "/(.*)";
$data["routes"][0]["dest"] = "/api/index.php";
$data["functions"]["api/index.php"]["runtime"] = "vercel-php@0.5.2";
$data["functions"]["api/index.php"]["runtime"] = "vercel-php@0.6.0";
if ($sourcePath == "") $sourcePath = splitlast(splitlast(__DIR__, "/")[0], "/")[0];
//echo $sourcePath . "<br>";
getEachFiles($file, $sourcePath);
@ -335,8 +329,7 @@ function VercelUpdate($appId, $token, $sourcePath = "")
return json_encode($result);
}
function checkBuilding($projectId, $token)
{
function checkBuilding($projectId, $token) {
$r = 0;
$url = "https://api.vercel.com/v6/deployments/?projectId=" . $projectId;
$header["Authorization"] = "Bearer " . $token;
@ -352,8 +345,7 @@ function checkBuilding($projectId, $token)
//else return false;
}
function getEachFiles(&$file, $base, $path = "")
{
function getEachFiles(&$file, $base, $path = "") {
//if (substr($base, -1)=="/") $base = substr($base, 0, -1);
//if (substr($path, -1)=="/") $path = substr($path, 0, -1);
$handler = opendir(path_format($base . "/" . $path));
@ -376,25 +368,21 @@ function getEachFiles(&$file, $base, $path = "")
return json_encode(['response' => 'success']);
}
function api_error($response)
{
function api_error($response) {
return isset($response['error']);
}
function api_error_msg($response)
{
function api_error_msg($response) {
return $response['error']['code'] . '<br>
' . $response['error']['message'] . '<br>
<button onclick="location.href = location.href;">' . getconstStr('Refresh') . '</button>';
}
function setConfigResponse($response)
{
function setConfigResponse($response) {
return json_decode($response, true);
}
function OnekeyUpate($GitSource = 'Github', $auth = 'qkqpttgf', $project = 'OneManager-php', $branch = 'master')
{
function OnekeyUpate($GitSource = 'Github', $auth = 'qkqpttgf', $project = 'OneManager-php', $branch = 'master') {
$tmppath = '/tmp';
if ($GitSource == 'Github') {
@ -430,12 +418,14 @@ function OnekeyUpate($GitSource = 'Github', $auth = 'qkqpttgf', $project = 'OneM
}
function WaitFunction($deployid = '') {
if ($buildId=='1') {
if ($deployid == '1') {
$tmp['stat'] = 400;
$tmp['body'] = 'id must provided.';
return $tmp;
}
$header["Authorization"] = "Bearer " . getConfig('APIKey');
$token = getConfig('APIKey');
if ($token != '') {
$header["Authorization"] = "Bearer " . $token;
$header["Content-Type"] = "application/json";
$url = "https://api.vercel.com/v13/deployments/" . $deployid;
$response = curl("GET", $url, "", $header);
@ -448,6 +438,9 @@ function WaitFunction($deployid = '') {
$response['body'] .= $url;
return $response;
}
} else {
return false;
}
}
function changeAuthKey() {
@ -473,6 +466,7 @@ function changeAuthKey() {
}
}, 1000);
</script>';
$title = "Success";
return message($html, $title, 201, 1);
}
}