cache in comm or disk

pull/128/head
qkqpttgf 2020-09-15 15:00:19 +08:00 committed by GitHub
parent efc2d0d0f5
commit 6162f2e3c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 51 additions and 51 deletions

View File

@ -303,7 +303,7 @@ function main($path)
if (!$refresh_token) {
return render_list();
} else {
if (!($_SERVER['access_token'] = getcache('access_token'))) {
if (!($_SERVER['access_token'] = getcache('access_token', $_SERVER['disktag']))) {
$response = get_access_token($refresh_token);
if (isset($response['stat'])) return message($response['body'], 'Error', $response['stat']);
}
@ -322,7 +322,7 @@ function main($path)
$tmp = MSAPI('DELETE', $filename, '', $_SERVER['access_token']);
$path1 = path_format($_SERVER['list_path'] . path_format($path));
if ($path1!='/'&&substr($path1,-1)=='/') $path1=substr($path1,0,-1);
savecache('path_' . $path1, json_decode('{}',true), 1);
savecache('path_' . $path1, json_decode('{}',true), $_SERVER['disktag'], 1);
return output($tmp['body'],$tmp['stat']);
}
if ($_GET['action']=='uploaded_rename') {
@ -344,7 +344,7 @@ function main($path)
}
$path1 = path_format($_SERVER['list_path'] . path_format($path));
if ($path1!='/'&&substr($path1,-1)=='/') $path1=substr($path1,0,-1);
savecache('path_' . $path1, json_decode('{}',true), 1);
savecache('path_' . $path1, json_decode('{}',true), $_SERVER['disktag'], 1);
return output($tmp['body'],$tmp['stat']);
}
if ($_GET['action']=='upbigfile') return bigfileupload($path);
@ -354,7 +354,7 @@ function main($path)
if ($tmp['statusCode'] > 0) {
$path1 = path_format($_SERVER['list_path'] . path_format($path));
if ($path1!='/'&&substr($path1,-1)=='/') $path1=substr($path1,0,-1);
savecache('path_' . $path1, json_decode('{}',true), 1);
savecache('path_' . $path1, json_decode('{}',true), $_SERVER['disktag'], 1);
return $tmp;
}
} else {
@ -504,7 +504,7 @@ function get_access_token($refresh_token)
$tmp = $ret;
$tmp['access_token'] = '******';
error_log('['.$_SERVER['disktag'].'] Get access token:'.json_encode($tmp, JSON_PRETTY_PRINT));
savecache('access_token', $_SERVER['access_token']);
savecache('access_token', $_SERVER['access_token'], $_SERVER['disktag']);
$tmp1 = [];
$tmp1['shareapiurl'] = $_SERVER['api_url'];
if (getConfig('shareapiurl')=='') setConfig($tmp1);
@ -527,7 +527,7 @@ function get_access_token($refresh_token)
$tmp['refresh_token'] = '******';
error_log('['.$_SERVER['disktag'].'] Get access token:'.json_encode($tmp, JSON_PRETTY_PRINT));
$_SERVER['access_token'] = $ret['access_token'];
savecache('access_token', $_SERVER['access_token'], $ret['expires_in'] - 300);
savecache('access_token', $_SERVER['access_token'], $_SERVER['disktag'], $ret['expires_in'] - 300);
if (time()>getConfig('token_expires')) setConfig([ 'refresh_token' => $ret['refresh_token'], 'token_expires' => time()+7*24*60*60 ]);
}
return 0;
@ -564,19 +564,19 @@ function isHideFile($name)
return false;
}
function getcache($str)
function getcache($str, $disktag = '')
{
$cache = filecache();
$cache = filecache($disktag);
return $cache->fetch($str);
}
function savecache($key, $value, $exp = 1800)
function savecache($key, $value, $disktag = '', $exp = 1800)
{
$cache = filecache();
$cache = filecache($disktag);
return $cache->save($key, $value, $exp);
}
function filecache()
function filecache($disktag)
{
$dir = sys_get_temp_dir();
if (!is_writable($dir)) {
@ -585,11 +585,11 @@ function filecache()
if ( is_writable($tmp) ) $dir = $tmp;
} elseif ( mkdir($tmp) ) $dir = $tmp;
}
$tag = __DIR__ . '/OneManager/' . $_SERVER['disktag'];
$tag = __DIR__ . '/OneManager/' . $disktag;
while (strpos($tag, '/')>-1) $tag = str_replace('/', '_', $tag);
if (strpos($tag, ':')>-1) {
while (strpos($tag, ':')>-1) $tag = str_replace(':', '_', $tag);
while (strpos($tag, '\\')>-1) $tag = str_replace('\\', '_', $tag);
$tag = str_replace(':', '_', $tag);
$tag = str_replace('\\', '_', $tag);
}
// error_log('DIR:' . $dir . ' TAG: ' . $tag);
$cache = new \Doctrine\Common\Cache\FilesystemCache($dir, $tag);
@ -872,7 +872,7 @@ function gethiddenpass($path,$passfile)
{
$path1 = path_format($_SERVER['list_path'] . path_format($path));
if ($path1!='/'&&substr($path1,-1)=='/') $path1=substr($path1,0,-1);
$password=getcache('path_' . $path1 . '/?password');
$password=getcache('path_' . $path1 . '/?password', $_SERVER['disktag']);
if ($password=='') {
$ispassfile = fetch_files(path_format($path . '/' . urlencode($passfile)));
//echo $path . '<pre>' . json_encode($ispassfile, JSON_PRETTY_PRINT) . '</pre>';
@ -882,14 +882,14 @@ function gethiddenpass($path,$passfile)
$passwordf=explode("\n",$arr['body']);
$password=$passwordf[0];
if ($password!='') $password=md5($password);
savecache('path_' . $path1 . '/?password', $password);
savecache('path_' . $path1 . '/?password', $password, $_SERVER['disktag']);
return $password;
} else {
//return md5('DefaultP@sswordWhenNetworkError');
return md5( md5(time()).rand(1000,9999) );
}
} else {
savecache('path_' . $path1 . '/?password', 'null');
savecache('path_' . $path1 . '/?password', 'null', $_SERVER['disktag']);
if ($path !== '' ) {
$path = substr($path,0,strrpos($path,'/'));
return gethiddenpass($path,$passfile);
@ -1014,7 +1014,7 @@ function get_thumbnails_url($path = '/', $location = 0)
$path1 = path_format($path);
$path = path_format($_SERVER['list_path'] . path_format($path));
if ($path!='/'&&substr($path,-1)=='/') $path=substr($path,0,-1);
$thumb_url = getcache('thumb_'.$path);
$thumb_url = getcache('thumb_'.$path, $_SERVER['disktag']);
if ($thumb_url=='') {
$url = $_SERVER['api_url'];
if ($path !== '/') {
@ -1024,7 +1024,7 @@ function get_thumbnails_url($path = '/', $location = 0)
$url .= ':/thumbnails/0/medium';
$files = json_decode(curl_request($url, false, ['Authorization' => 'Bearer ' . $_SERVER['access_token']])['body'], true);
if (isset($files['url'])) {
savecache('thumb_'.$path, $files['url']);
savecache('thumb_'.$path, $files['url'], $_SERVER['disktag']);
$thumb_url = $files['url'];
}
}
@ -1088,7 +1088,7 @@ function adminform($name = '', $pass = '', $path = '')
$statusCode = 201;
date_default_timezone_set('UTC');
$header = [
'Set-Cookie' => $name . '=' . $pass . '; path=/; expires=' . date(DATE_COOKIE, strtotime('+1hour')),
'Set-Cookie' => $name . '=' . $pass . '; path=/; expires=' . date(DATE_COOKIE, strtotime('+7day')),
//'Location' => $path,
'Content-Type' => 'text/html'
];
@ -1124,7 +1124,7 @@ function adminoperate($path)
$data = '{"name":"' . $_GET['rename_newname'] . '"}';
//echo $oldname;
$result = MSAPI('PATCH',$oldname,$data,$_SERVER['access_token']);
//savecache('path_' . $path1, json_decode('{}',true), 1);
//savecache('path_' . $path1, json_decode('{}',true), $_SERVER['disktag'], 1);
return output($result['body'], $result['stat']);
}
if (isset($_GET['delete_name'])) {
@ -1133,7 +1133,7 @@ function adminoperate($path)
$filename = path_format($path1 . '/' . $filename);
//echo $filename;
$result = MSAPI('DELETE', $filename, '', $_SERVER['access_token']);
//savecache('path_' . $path1, json_decode('{}',true), 1);
//savecache('path_' . $path1, json_decode('{}',true), $_SERVER['disktag'], 1);
return output($result['body'], $result['stat']);
}
if (isset($_GET['operate_action'])&&$_GET['operate_action']==getconstStr('Encrypt')) {
@ -1146,7 +1146,7 @@ function adminoperate($path)
$result = MSAPI('PUT', $filename, $_GET['encrypt_newpass'], $_SERVER['access_token']);
$path1 = path_format($path1 . '/' . $foldername );
if ($path1!='/'&&substr($path1,-1)=='/') $path1=substr($path1,0,-1);
savecache('path_' . $path1 . '/?password', '', 1);
savecache('path_' . $path1 . '/?password', '', $_SERVER['disktag'], 1);
return output($result['body'], $result['stat']);
}
if (isset($_GET['move_folder'])) {
@ -1160,11 +1160,11 @@ function adminoperate($path)
$foldername = path_format('/'.urldecode($path1).'/'.$_GET['move_folder']);
$data = '{"parentReference":{"path": "/drive/root:'.$foldername.'"}}';
$result = MSAPI('PATCH', $filename, $data, $_SERVER['access_token']);
//savecache('path_' . $path1, json_decode('{}',true), 1);
//savecache('path_' . $path1, json_decode('{}',true), $_SERVER['disktag'], 1);
if ($_GET['move_folder'] == '/../') $path2 = path_format( substr($path1, 0, strrpos($path1, '/')) . '/' );
else $path2 = path_format( $path1 . '/' . $_GET['move_folder'] . '/' );
if ($path2!='/'&&substr($path2,-1)=='/') $path2=substr($path2,0,-1);
savecache('path_' . $path2, json_decode('{}',true), 1);
savecache('path_' . $path2, json_decode('{}',true), $_SERVER['disktag'], 1);
return output($result['body'], $result['stat']);
} else {
return output('{"error":"'.getconstStr('CannotMove').'"}', 403);
@ -1200,10 +1200,10 @@ function adminoperate($path)
$result = MSAPI('copy', $filename, $data, $_SERVER['access_token']);
}
//echo $result['stat'].$result['body'];
//savecache('path_' . $path1, json_decode('{}',true), 1);
//savecache('path_' . $path1, json_decode('{}',true), $_SERVER['disktag'], 1);
//if ($_GET['move_folder'] == '/../') $path2 = path_format( substr($path1, 0, strrpos($path1, '/')) . '/' );
//else $path2 = path_format( $path1 . '/' . $_GET['move_folder'] . '/' );
//savecache('path_' . $path2, json_decode('{}',true), 1);
//savecache('path_' . $path2, json_decode('{}',true), $_SERVER['disktag'], 1);
return output($result['body'], $result['stat']);
}
if (isset($_POST['editfile'])) {
@ -1230,14 +1230,14 @@ function adminoperate($path)
$data = '{ "name": "' . $_GET['create_name'] . '", "folder": { }, "@microsoft.graph.conflictBehavior": "rename" }';
$result = MSAPI('children', $path1, $data, $_SERVER['access_token']);
}
//savecache('path_' . $path1, json_decode('{}',true), 1);
//savecache('path_' . $path1, json_decode('{}',true), $_SERVER['disktag'], 1);
return output($result['body'], $result['stat']);
}
if (isset($_GET['RefreshCache'])) {
$path1 = path_format($_SERVER['list_path'] . path_format($path));
if ($path1!='/'&&substr($path1,-1)=='/') $path1=substr($path1,0,-1);
savecache('path_' . $path1 . '/?password', '', 1);
savecache('customTheme', '', 1);
savecache('path_' . $path1 . '/?password', '', $_SERVER['disktag'], 1);
savecache('customTheme', '', '', 1);
return message('<meta http-equiv="refresh" content="2;URL=./">', getconstStr('RefreshCache'), 302);
}
return $tmparr;
@ -1351,7 +1351,7 @@ function fetch_files($path = '/')
$path1 = path_format($path);
$path = path_format($_SERVER['list_path'] . path_format($path));
if ($path!='/'&&substr($path,-1)=='/') $path=substr($path,0,-1);
if (!($files = getcache('path_' . $path))) {
if (!($files = getcache('path_' . $path, $_SERVER['disktag']))) {
// https://docs.microsoft.com/en-us/graph/api/driveitem-get?view=graph-rest-1.0
// https://docs.microsoft.com/zh-cn/graph/api/driveitem-put-content?view=graph-rest-1.0&tabs=http
// https://developer.microsoft.com/zh-cn/graph/graph-explorer
@ -1359,13 +1359,13 @@ function fetch_files($path = '/')
$parentpath = $pos[0];
if ($parentpath=='') $parentpath = '/';
$filename = $pos[1];
if ($parentfiles = getcache('path_' . $parentpath)) {
if ($parentfiles = getcache('path_' . $parentpath, $_SERVER['disktag'])) {
if (isset($parentfiles['children'][$filename][$_SERVER['DownurlStrName']])) {
if (in_array(splitlast($filename,'.')[1], $exts['txt'])) {
if (!(isset($parentfiles['children'][$filename]['content'])&&$parentfiles['children'][$filename]['content']['stat']==200)) {
$content1 = curl_request($parentfiles['children'][$filename][$_SERVER['DownurlStrName']]);
$parentfiles['children'][$filename]['content'] = $content1;
savecache('path_' . $parentpath, $parentfiles);
savecache('path_' . $parentpath, $parentfiles, $_SERVER['disktag']);
}
}
return $parentfiles['children'][$filename];
@ -1408,7 +1408,7 @@ function fetch_files($path = '/')
//if (isset($files['children'])) {
$files['children'] = children_name($files['children']);
//}
savecache('path_' . $path, $files);
savecache('path_' . $path, $files, $_SERVER['disktag']);
}
}
if (isset($files['file'])) {
@ -1416,7 +1416,7 @@ function fetch_files($path = '/')
if (!(isset($files['content'])&&$files['content']['stat']==200)) {
$content1 = curl_request($files[$_SERVER['DownurlStrName']]);
$files['content'] = $content1;
savecache('path_' . $path, $files);
savecache('path_' . $path, $files, $_SERVER['disktag']);
}
}
}
@ -1457,21 +1457,21 @@ function fetch_files_children($files, $path, $page)
if ($path!='/'&&substr($path,-1)=='/') $path=substr($path,0,-1);
$cachefilename = '.SCFcache_'.$_SERVER['function_name'];
$maxpage = ceil($files['folder']['childCount']/200);
if (!($files['children'] = getcache('files_' . $path . '_page_' . $page))) {
if (!($files['children'] = getcache('files_' . $path . '_page_' . $page, $_SERVER['disktag']))) {
// down cache file get jump info. 下载cache文件获取跳页链接
$cachefile = fetch_files(path_format($path1 . '/' .$cachefilename));
if ($cachefile['size']>0) {
$pageinfo = curl_request($cachefile[$_SERVER['DownurlStrName']])['body'];
$pageinfo = json_decode($pageinfo,true);
for ($page4=1;$page4<$maxpage;$page4++) {
savecache('nextlink_' . $path . '_page_' . $page4, $pageinfo['nextlink_' . $path . '_page_' . $page4]);
savecache('nextlink_' . $path . '_page_' . $page4, $pageinfo['nextlink_' . $path . '_page_' . $page4], $_SERVER['disktag']);
$pageinfocache['nextlink_' . $path . '_page_' . $page4] = $pageinfo['nextlink_' . $path . '_page_' . $page4];
}
}
$pageinfochange=0;
for ($page1=$page;$page1>=1;$page1--) {
$page3=$page1-1;
$url = getcache('nextlink_' . $path . '_page_' . $page3);
$url = getcache('nextlink_' . $path . '_page_' . $page3, $_SERVER['disktag']);
if ($url == '') {
if ($page1==1) {
$url = $_SERVER['api_url'];
@ -1484,10 +1484,10 @@ function fetch_files_children($files, $path, $page)
}
$children = json_decode(curl_request($url, false, ['Authorization' => 'Bearer ' . $_SERVER['access_token']])['body'], true);
// echo $url . '<br><pre>' . json_encode($children, JSON_PRETTY_PRINT) . '</pre>';
savecache('files_' . $path . '_page_' . $page1, $children['value']);
$nextlink=getcache('nextlink_' . $path . '_page_' . $page1);
savecache('files_' . $path . '_page_' . $page1, $children['value'], $_SERVER['disktag']);
$nextlink=getcache('nextlink_' . $path . '_page_' . $page1, $_SERVER['disktag']);
if ($nextlink!=$children['@odata.nextLink']) {
savecache('nextlink_' . $path . '_page_' . $page1, $children['@odata.nextLink']);
savecache('nextlink_' . $path . '_page_' . $page1, $children['@odata.nextLink'], $_SERVER['disktag']);
$pageinfocache['nextlink_' . $path . '_page_' . $page1] = $children['@odata.nextLink'];
$pageinfocache = clearbehindvalue($path,$page1,$maxpage,$pageinfocache);
$pageinfochange = 1;
@ -1496,10 +1496,10 @@ function fetch_files_children($files, $path, $page)
for ($page2=$page1+1;$page2<=$page;$page2++) {
sleep(1);
$children = json_decode(curl_request($url, false, ['Authorization' => 'Bearer ' . $_SERVER['access_token']])['body'], true);
savecache('files_' . $path . '_page_' . $page2, $children['value']);
$nextlink=getcache('nextlink_' . $path . '_page_' . $page2);
savecache('files_' . $path . '_page_' . $page2, $children['value'], $_SERVER['disktag']);
$nextlink=getcache('nextlink_' . $path . '_page_' . $page2, $_SERVER['disktag']);
if ($nextlink!=$children['@odata.nextLink']) {
savecache('nextlink_' . $path . '_page_' . $page2, $children['@odata.nextLink']);
savecache('nextlink_' . $path . '_page_' . $page2, $children['@odata.nextLink'], $_SERVER['disktag']);
$pageinfocache['nextlink_' . $path . '_page_' . $page2] = $children['@odata.nextLink'];
$pageinfocache = clearbehindvalue($path,$page2,$maxpage,$pageinfocache);
$pageinfochange = 1;
@ -1520,10 +1520,10 @@ function fetch_files_children($files, $path, $page)
for ($page2=$page3+1;$page2<=$page;$page2++) {
sleep(1);
$children = json_decode(curl_request($url, false, ['Authorization' => 'Bearer ' . $_SERVER['access_token']])['body'], true);
savecache('files_' . $path . '_page_' . $page2, $children['value'], 3300);
$nextlink=getcache('nextlink_' . $path . '_page_' . $page2);
savecache('files_' . $path . '_page_' . $page2, $children['value'], $_SERVER['disktag'], 3300);
$nextlink=getcache('nextlink_' . $path . '_page_' . $page2, $_SERVER['disktag']);
if ($nextlink!=$children['@odata.nextLink']) {
savecache('nextlink_' . $path . '_page_' . $page2, $children['@odata.nextLink'], 3300);
savecache('nextlink_' . $path . '_page_' . $page2, $children['@odata.nextLink'], $_SERVER['disktag'], 3300);
$pageinfocache['nextlink_' . $path . '_page_' . $page2] = $children['@odata.nextLink'];
$pageinfocache = clearbehindvalue($path,$page2,$maxpage,$pageinfocache);
$pageinfochange = 1;
@ -1544,8 +1544,8 @@ function fetch_files_children($files, $path, $page)
} else {
$files['folder']['page']=$page;
for ($page4=1;$page4<=$maxpage;$page4++) {
if (!($url = getcache('nextlink_' . $path . '_page_' . $page4))) {
if ($files['folder'][$path.'_'.$page4]!='') savecache('nextlink_' . $path . '_page_' . $page4, $files['folder'][$path.'_'.$page4]);
if (!($url = getcache('nextlink_' . $path . '_page_' . $page4, $_SERVER['disktag']))) {
if ($files['folder'][$path.'_'.$page4]!='') savecache('nextlink_' . $path . '_page_' . $page4, $files['folder'][$path.'_'.$page4], $_SERVER['disktag']);
} else {
$files['folder'][$path.'_'.$page4] = $url;
}
@ -1595,7 +1595,7 @@ function get_refresh_token()
$title = 'Error';
return message($html, $title, 201);
} else {
savecache('access_token', $ret['access_token'], $ret['expires_in'] - 60);
savecache('access_token', $ret['access_token'], $_SERVER['disktag'], $ret['expires_in'] - 60);
$str .= '
<meta http-equiv="refresh" content="5;URL=' . $url . '">';
return message($str, getconstStr('WaitJumpIndex'));
@ -2072,7 +2072,7 @@ function render_list($path = '', $files = '')
$tmp = curl_request($tmp["returnhead"]["Location"]);
}
if (!!$tmp['body']) $html = $tmp['body'];
savecache('customTheme', $html, 9999);
savecache('customTheme', $html, '', 9999);
}
}