Skip to content

Commit

Permalink
1. disable Aliyundrive, add AliyundriveOpen.
Browse files Browse the repository at this point in the history
2. change git source from HIT Gitlab to Gitee.
3. remake keys positioning in theme, we can use <!--xxxx--> and /*--xxxx--*/ now, so that the editor never warn.
4. remove too many \n befor input MD content.
  • Loading branch information
root committed Mar 22, 2024
1 parent 1c6b6c6 commit f3bce98
Show file tree
Hide file tree
Showing 21 changed files with 3,648 additions and 2,885 deletions.
854 changes: 303 additions & 551 deletions common.php

Large diffs are not rendered by default.

235 changes: 123 additions & 112 deletions disk/Aliyundrive.php

Large diffs are not rendered by default.

753 changes: 753 additions & 0 deletions disk/AliyundriveOpen.php

Large diffs are not rendered by default.

388 changes: 200 additions & 188 deletions disk/BaiduDisk.php

Large diffs are not rendered by default.

341 changes: 174 additions & 167 deletions disk/Onedrive.php

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions disk/Sharelink.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
if (!class_exists('Onedrive')) require 'Onedrive.php';

class Sharelink extends Onedrive {
private $sharecookie;

function __construct($tag) {
$this->disktag = $tag;
Expand All @@ -12,20 +13,18 @@ function __construct($tag) {
$this->DownurlStrName = '@content.downloadUrl';
}

public function ext_show_innerenv()
{
return [ 'shareurl' ];
public function ext_show_innerenv() {
return ['shareurl'];
}

protected function get_access_token($refresh_token) {
if (!($this->access_token = getcache('access_token', $this->disktag))) {
$shareurl = getConfig('shareurl', $this->disktag);
if (!($this->sharecookie = getcache('sharecookie', $this->disktag))) {
$res = curl('GET', $shareurl, '', [], 1);
error_log1(json_encode($res, JSON_PRETTY_PRINT));
error_log1(json_encode($res, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
if (isset($res['returnhead']['Set-Cookie'])) $this->sharecookie = $res['returnhead']['Set-Cookie'];
if (isset($res['returnhead']['set-cookie'])) $this->sharecookie = $res['returnhead']['set-cookie'];
if ($this->sharecookie=='') {
if ($this->sharecookie == '') {
$this->error = $res;
return false;
}
Expand All @@ -34,19 +33,20 @@ protected function get_access_token($refresh_token) {
$tmp1 = splitlast($shareurl, '/')[0];
$account = splitlast($tmp1, '/')[1];
$domain = splitlast($shareurl, '/:')[0];
$response = curl('POST',
$response = curl(
'POST',
$domain . "/personal/" . $account . "/_api/web/GetListUsingPath(DecodedUrl=@a1)/RenderListDataAsStream?@a1='" . urlencode("/personal/" . $account . "/Documents") . "'&RootFolder=" . urlencode("/personal/" . $account . "/Documents/") . "&TryNewExperienceSingle=TRUE",
'{"parameters":{"__metadata":{"type":"SP.RenderListDataParameters"},"RenderOptions":136967,"AllowMultipleValueFilterForTaxonomyFields":true,"AddRequiredFields":true}}',
[ 'Accept' => 'application/json;odata=verbose', 'Content-Type' => 'application/json;odata=verbose', 'origin' => $domain, 'Cookie' => $this->sharecookie ]
['Accept' => 'application/json;odata=verbose', 'Content-Type' => 'application/json;odata=verbose', 'origin' => $domain, 'Cookie' => $this->sharecookie]
);
if ($response['stat']==200) $ret = json_decode($response['body'], true);
$this->access_token = splitlast($ret['ListSchema']['.driveAccessToken'],'=')[1];
$this->api_url = $ret['ListSchema']['.driveUrl'].'/root';
if ($response['stat'] == 200) $ret = json_decode($response['body'], true);
$this->access_token = splitlast($ret['ListSchema']['.driveAccessToken'], '=')[1];
$this->api_url = $ret['ListSchema']['.driveUrl'] . '/root';
if (!$this->access_token) {
error_log1($domain . "/personal/" . $account . "/_api/web/GetListUsingPath(DecodedUrl=@a1)/RenderListDataAsStream?@a1='" . urlencode("/personal/" . $account . "/Documents") . "'&RootFolder=" . urlencode("/personal/" . $account . "/Documents/") . "&TryNewExperienceSingle=TRUE");
error_log1('failed to get share access_token. response' . json_encode($ret));
//$response['body'] = json_encode(json_decode($response['body']), JSON_PRETTY_PRINT);
$response['body'] .= '<br>' .json_decode($response['body'], true)['error']['message']['value'];
$response['body'] .= '<br>' . json_decode($response['body'], true)['error']['message']['value'];
$response['body'] .= '<br>failed to get shareurl access_token.';
$this->error = $response;
return false;
Expand All @@ -57,7 +57,7 @@ protected function get_access_token($refresh_token) {
//error_log1('['.$this->disktag.'] Get access token:'.json_encode($tmp, JSON_PRETTY_PRINT));
savecache('access_token', $this->access_token, $this->disktag);
$tmp1 = null;
if (getConfig('shareapiurl', $this->disktag)!=$this->api_url) $tmp1['shareapiurl'] = $this->api_url;
if (getConfig('shareapiurl', $this->disktag) != $this->api_url) $tmp1['shareapiurl'] = $this->api_url;
//if (getConfig('sharecookie', $this->disktag)!=$this->sharecookie) $tmp1['sharecookie'] = $this->sharecookie;
if (!!$tmp1) setConfig($tmp1, $this->disktag);
return true;
Expand Down
63 changes: 29 additions & 34 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,43 +12,43 @@
global $platform;
$platform = checkPlatform();
function checkPlatform() {
if (isset($_SERVER['USER'])&&$_SERVER['USER']==='qcloud')
if (isset($_SERVER['USER']) && $_SERVER['USER'] === 'qcloud')
return 'SCF';
if (isset($_SERVER['FC_FUNC_CODE_PATH']))
return 'FC';
if (isset($_SERVER['RUNTIME_LOG_PATH']) && $_SERVER['RUNTIME_LOG_PATH']=='/home/snuser/log')
if (isset($_SERVER['RUNTIME_LOG_PATH']) && $_SERVER['RUNTIME_LOG_PATH'] == '/home/snuser/log')
return 'FG';
if (isset($_SERVER['BCE_CFC_RUNTIME_NAME']) && $_SERVER['BCE_CFC_RUNTIME_NAME']=='php7')
if (isset($_SERVER['BCE_CFC_RUNTIME_NAME']) && $_SERVER['BCE_CFC_RUNTIME_NAME'] == 'php7')
return 'CFC';
if (isset($_SERVER['HEROKU_APP_DIR'])&&$_SERVER['HEROKU_APP_DIR']==='/app')
if (isset($_SERVER['HEROKU_APP_DIR']) && $_SERVER['HEROKU_APP_DIR'] === '/app')
return 'Heroku';
if (isset($_SERVER['DOCUMENT_ROOT'])&&$_SERVER['DOCUMENT_ROOT']==='/var/task/user')
if (isset($_SERVER['DOCUMENT_ROOT']) && $_SERVER['DOCUMENT_ROOT'] === '/var/task/user')
return 'Vercel';
if (isset($_SERVER['DOCUMENT_ROOT'])&&substr($_SERVER['DOCUMENT_ROOT'], 0, 13)==='/home/runner/')
if (isset($_SERVER['DOCUMENT_ROOT']) && substr($_SERVER['DOCUMENT_ROOT'], 0, 13) === '/home/runner/')
return 'Replit';
return 'Normal';
}
function writebackPlatform($p) {
if ('SCF'==$p) $_SERVER['USER']='qcloud';
if ('FC'==$p) $_SERVER['FC_FUNC_CODE_PATH']=getenv('FC_FUNC_CODE_PATH');
if ('FG'==$p) $_SERVER['RUNTIME_LOG_PATH']='/home/snuser/log';
if ('CFC'==$p) $_SERVER['BCE_CFC_RUNTIME_NAME']='php7';
if ('SCF' == $p) $_SERVER['USER'] = 'qcloud';
if ('FC' == $p) $_SERVER['FC_FUNC_CODE_PATH'] = getenv('FC_FUNC_CODE_PATH');
if ('FG' == $p) $_SERVER['RUNTIME_LOG_PATH'] = '/home/snuser/log';
if ('CFC' == $p) $_SERVER['BCE_CFC_RUNTIME_NAME'] = 'php7';
//if ('Heroku'==$p) $_SERVER['HEROKU_APP_DIR']='/app';
if ('Vercel'==$p) $_SERVER['DOCUMENT_ROOT']='/var/task/user';
if ('Vercel' == $p) $_SERVER['DOCUMENT_ROOT'] = '/var/task/user';
//if ('Replit'==$p) $_SERVER['DOCUMENT_ROOT']='/home/runner/';
}
if ('SCF'==$platform) {
if (getenv('ONEMANAGER_CONFIG_SAVE')=='file') include 'platform/TencentSCF_file.php';
if ('SCF' == $platform) {
if (getenv('ONEMANAGER_CONFIG_SAVE') == 'file') include 'platform/TencentSCF_file.php';
else include 'platform/TencentSCF_env.php';
} elseif ('FC'==$platform) {
} elseif ('FC' == $platform) {
include 'platform/AliyunFC.php';
} elseif ('FG'==$platform) {
} elseif ('FG' == $platform) {
//if (getenv('ONEMANAGER_CONFIG_SAVE')=='file') include 'platform/HuaweiFG_file.php';
//else include 'platform/HuaweiFG_env.php';
echo 'FG' . PHP_EOL;
} elseif ('CFC'==$platform) {
} elseif ('CFC' == $platform) {
include 'platform/BaiduCFC.php';
} elseif ('Heroku'==$platform) {
} elseif ('Heroku' == $platform) {
include 'platform/Heroku.php';
$path = getpath();
//echo 'path:'. $path;
Expand All @@ -62,8 +62,8 @@ function writebackPlatform($p) {
http_response_code($re['statusCode']);
if ($re['isBase64Encoded']) echo base64_decode($re['body']);
else echo $re['body'];
} elseif ('Vercel'==$platform) {
if (getenv('ONEMANAGER_CONFIG_SAVE')=='env') include 'platform/Vercel_env.php';
} elseif ('Vercel' == $platform) {
if (getenv('ONEMANAGER_CONFIG_SAVE') == 'env') include 'platform/Vercel_env.php';
else include 'platform/Vercel.php';

writebackPlatform('Vercel');
Expand All @@ -79,7 +79,7 @@ function writebackPlatform($p) {
http_response_code($re['statusCode']);
if ($re['isBase64Encoded']) echo base64_decode($re['body']);
else echo $re['body'];
} elseif ('Replit'==$platform) {
} elseif ('Replit' == $platform) {
include 'platform/Replit.php';

$path = getpath();
Expand Down Expand Up @@ -117,13 +117,12 @@ function writebackPlatform($p) {
}

// Tencent SCF
function main_handler($event, $context)
{
function main_handler($event, $context) {
$event = json_decode(json_encode($event), true);
$context = json_decode(json_encode($context), true);
printInput($event, $context);
if ( $event['requestContext']['serviceId'] === substr($event['headers']['host'], 0, strlen($event['requestContext']['serviceId'])) ) {
if ($event['path']==='/' . $context['function_name']) return output('add / at last.', 308, ['Location'=>'/'.$event['requestContext']['stage'].'/'.$context['function_name'].'/']);
if ($event['requestContext']['serviceId'] === substr($event['headers']['host'], 0, strlen($event['requestContext']['serviceId']))) {
if ($event['path'] === '/' . $context['function_name']) return output('add / at last.', 308, ['Location' => '/' . $event['requestContext']['stage'] . '/' . $context['function_name'] . '/']);
}
unset($_POST);
unset($_GET);
Expand All @@ -138,10 +137,9 @@ function main_handler($event, $context)
}

// Aliyun FC & Huawei FG & Baidu CFC
function handler($event, $context)
{
function handler($event, $context) {
global $platform;
if ('FC'==$platform) {
if ('FC' == $platform) {
// Aliyun FC
set_error_handler("myErrorHandler");
$tmp = array(
Expand All @@ -166,13 +164,12 @@ function handler($event, $context)

$re = main($path);

return new RingCentral\Psr7\Response($re['statusCode'], $re['headers'], ($re['isBase64Encoded']?base64_decode($re['body']):$re['body']));

} elseif ('FG'==$platform) {
return new RingCentral\Psr7\Response($re['statusCode'], $re['headers'], ($re['isBase64Encoded'] ? base64_decode($re['body']) : $re['body']));
} elseif ('FG' == $platform) {
// Huawei FG
global $contextUserData;
$contextUserData = $context;
if ($context->getUserData('ONEMANAGER_CONFIG_SAVE')=='file') include_once 'platform/HuaweiFG_file.php';
if ($context->getUserData('ONEMANAGER_CONFIG_SAVE') == 'file') include_once 'platform/HuaweiFG_file.php';
else include_once 'platform/HuaweiFG_env.php';

$event = json_decode(json_encode($event), true);
Expand All @@ -189,8 +186,7 @@ function handler($event, $context)
$path = GetPathSetting($event, $context);

return main($path);

} elseif ('CFC'==$platform) {
} elseif ('CFC' == $platform) {
// Baidu CFC
//$html = '<pre>'. json_encode($event, JSON_PRETTY_PRINT).'</pre>';
//$html .= '<pre>'. json_encode($context, JSON_PRETTY_PRINT).'</pre>';
Expand All @@ -210,6 +206,5 @@ function handler($event, $context)
$path = GetPathSetting($event, $context);

return json_encode(main($path), JSON_FORCE_OBJECT);

}
}
6 changes: 6 additions & 0 deletions js/bignumber.min.js

Large diffs are not rendered by default.

Empty file modified js/marked.js
100755 → 100644
Empty file.
Empty file modified js/spark-md5.min.js
100755 → 100644
Empty file.
46 changes: 39 additions & 7 deletions platform/AliyunFC.php
Original file line number Diff line number Diff line change
Expand Up @@ -417,17 +417,49 @@ function OnekeyUpate($GitSource = 'Github', $auth = 'qkqpttgf', $project = 'OneM

if ($GitSource == 'Github') {
// 从github下载对应tar.gz,并解压
$url = 'https://github.com/' . $auth . '/' . $project . '/tarball/' . urlencode($branch) . '/';
} elseif ($GitSource == 'HITGitlab') {
//$url = 'https://github.com/' . $auth . '/' . $project . '/tarball/' . urlencode($branch) . '/';
// 从github下载对应zip,并解压
$url = 'https://codeload.github.com/' . $auth . '/' . $project . '/zip/refs/heads/' . urlencode($branch);
} elseif ($GitSource == 'Gitee') {
$url = 'https://gitee.com/' . $auth . '/' . $project . '/repository/archive/' . urlencode($branch) . '.zip';
}/* elseif ($GitSource == 'HITGitlab') {
$url = 'https://git.hit.edu.cn/' . $auth . '/' . $project . '/-/archive/' . urlencode($branch) . '/' . $project . '-' . urlencode($branch) . '.tar.gz';
} else return json_encode(['ErrorMessage' => '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); //路径 要解压的文件 是否覆盖
}*/ else return json_encode(['ErrorMessage' => 'Git Source input Error!']);
$zipfile = '/tmp/github.zip';
$context_options = array(
'http' => array(
'header' => "User-Agent: curl/7.83.1",
)
);
$context = stream_context_create($context_options);
$githubfile = file_get_contents($url, false, $context);
if (!$githubfile) {
$tmp1['ErrorCode'] = "Failed";
$tmp1['ErrorMessage'] = "Download code failed";
return json_encode($tmp1);
}
file_put_contents($zipfile, $githubfile);
$zip = new ZipArchive();
if ($zip->open($zipfile)) {
if (!$zip->extractTo($outPath)) {
$tmp1['ErrorCode'] = "Failed";
$tmp1['ErrorMessage'] = "Extract failed";
return json_encode($tmp1);
}
$zip->close();
} else {
$tmp1['ErrorCode'] = "Failed";
$tmp1['ErrorMessage'] = "Open zip file failed";
return json_encode($tmp1);
}

// 获取解压出的目录名
$outPath = findIndexPath($outPath);
if ($outPath == '') {
$tmp1['ErrorCode'] = "Failed";
$tmp1['ErrorMessage'] = "No index.php in downloaded code";
return json_encode($tmp1);
}

// 将目录中文件打包成zip
$zip = new ZipArchive();
Expand Down
Loading

0 comments on commit f3bce98

Please sign in to comment.