diff --git a/common.php b/common.php index fd601a6..d3c5449 100644 --- a/common.php +++ b/common.php @@ -38,6 +38,7 @@ $EnvConfigs = [ 'useBasicAuth' => 0b010, 'referrer' => 0b011, 'forceHttps' => 0b010, + 'littleFileCacheTime' => 0b010, 'Driver' => 0b100, 'client_id' => 0b100, @@ -392,6 +393,17 @@ function main($path) $url = $files['url']; if ( strtolower(splitlast($files['name'], '.')[1])=='html' ) return output($files['content']['body'], $files['content']['stat']); else { + $littleFileCacheTime = getConfig('littleFileCacheTime'); + if ($files['size']<1024*1024 && !!$littleFileCacheTime) { + if ($littleFileCacheTime>1) $littleFileCacheTime *= 3600; + else $littleFileCacheTime = 3600; + return output( + base64_encode(file_get_contents($files['url'])), + 200, + ['Content-Type' => $files['mime'], 'Cache-Control' => 'max-age=' . $littleFileCacheTime], + true + ); + } if ($_SERVER['HTTP_RANGE']!='') $header['Range'] = $_SERVER['HTTP_RANGE']; $header['Location'] = $url; $domainforproxy = ''; diff --git a/conststr.php b/conststr.php index 00de5af..b3a6db3 100644 --- a/conststr.php +++ b/conststr.php @@ -105,6 +105,7 @@ $constStr = [ 'background' => 'Set an url as background photo.', 'backgroundm' => 'Set an url as background in mobile phone.', 'forceHttps' => 'if 1, force to redirect to https when visit via http.', + 'littleFileCacheTime' => 'Unit is hour, if set this, little file<1M will through program and cache in explorer, otherwise, default 302 to Microsoft', 'theme' => 'Select theme for guest.', 'timezone' => 'Set default timezone.', 'guestup_path' => 'Set guest upload dir, before set this, the files in this dir will show as normal.', @@ -133,6 +134,7 @@ $constStr = [ 'background' => '设置一个url作为背景。', 'backgroundm' => '设置一个url作为手机端用的背景。', 'forceHttps' => '0或1。如果设置为1,会强制跳https', + 'littleFileCacheTime' => '单位是小时,如果设置,小于1M的小文件会从程序通过然后缓存在浏览器,不然,默认302跳微软', 'theme' => '为游客选择一个主题。', 'timezone' => '设置默认时区。', 'guestup_path' => '设置游客上传路径(图床路径),不设置这个值时该目录内容会正常列文件出来,设置后只有上传界面,不显示其中文件(登录后显示)。', diff --git a/index.php b/index.php index a2d9bd1..1c78c03 100644 --- a/index.php +++ b/index.php @@ -30,7 +30,8 @@ if (isset($_SERVER['USER'])&&$_SERVER['USER']==='qcloud') { header($headerName . ': ' . $headerVal, true); } http_response_code($re['statusCode']); - echo $re['body']; + if ($re['isBase64Encoded']) echo base64_decode($re['body']); + else echo $re['body']; } elseif (isset($_SERVER['DOCUMENT_ROOT'])&&$_SERVER['DOCUMENT_ROOT']==='/var/task/user') { if (getenv('ONEMANAGER_CONFIG_SAVE')=='env') include 'platform/Vercel_env.php'; else include 'platform/Vercel.php'; @@ -44,7 +45,8 @@ if (isset($_SERVER['USER'])&&$_SERVER['USER']==='qcloud') { header($headerName . ': ' . $headerVal, true); } http_response_code($re['statusCode']); - echo $re['body']; + if ($re['isBase64Encoded']) echo base64_decode($re['body']); + else echo $re['body']; } else { include 'platform/Normal.php'; $path = getpath(); @@ -58,7 +60,8 @@ if (isset($_SERVER['USER'])&&$_SERVER['USER']==='qcloud') { header($headerName . ': ' . $headerVal, true); } http_response_code($re['statusCode']); - echo $re['body']; + if ($re['isBase64Encoded']) echo base64_decode($re['body']); + else echo $re['body']; } // Tencent SCF