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