diff --git a/README.md b/README.md index ebdfc14..b54b7b5 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,65 @@ -本指南将帮助你安装和运行 AList 代理服务。AList 是一个支持多种存储的文件列表程序,提供网页浏览和 WebDAV 服务。 +# AList 代理服务安装指南 -安装步骤 -1. 下载代理脚本 -使用以下命令下载代理脚本到本地: +本指南将指导您如何安装和运行 AList 代理服务。AList 是一个支持多种存储的文件列表程序,提供网页浏览和 WebDAV 服务。 -bash -curl -o index.js https://x-mo.cn:9009/XiaoMo/alist-proxy/raw/branch/master/index.js +## 安装步骤 -2. 安装依赖 -确保你的系统已经安装了 Node.js。如果没有,请访问 Node.js 官网 下载并安装。 +### 使用 Node.js 版本 -3. 运行代理服务 -下载完成后,使用以下命令运行代理服务: +1. **下载代理脚本** + 使用以下命令将代理脚本下载到本地: -bash -node index.js -4. 访问 AList 界面 -代理服务运行后,你可以通过浏览器访问 AList 的 Web 界面。默认情况下,AList 监听在 http://localhost:9001 + ```bash + curl -o index.js https://x-mo.cn:9009/XiaoMo/alist-proxy/raw/branch/master/index.js + ``` +2. **安装 Node.js** + + 确保您的系统已安装 Node.js。如果未安装,请访问 [Node.js 官网](https://nodejs.org)下载并安装。 + +3. **运行代理服务** + + 下载完成后,使用以下命令启动代理服务: + + ```bash + node index.js + ``` + +4. **访问 AList 界面** + + 代理服务启动后,您可以通过浏览器访问 AList 的 Web 界面。默认情况下,AList 监听在 `http://localhost:9001`。 + +### 使用 PHP 版本 + +1. **下载代理脚本** + + 使用以下命令将代理脚本下载到本地: + + ```bash + curl -o index.php https://x-mo.cn:9009/XiaoMo/alist-proxy/raw/branch/master/index.php + ``` + +2. **运行代理服务** + + 使用 Swoole CLI 启动代理服务: + + ```bash + ./swoole-cli ./index.php + ``` + +3. **常驻后台运行** + + 为了让服务在后台持续运行,可以使用 `nohup` 命令: + + ```bash + nohup ./swoole-cli ./index.php > /dev/null 2>&1 & + ``` + +4. **设置自动启动** + + (此部分需要根据您的系统和需求进行具体配置,建议查阅相关文档以设置服务的自动启动。) + +--- + +通过以上步骤,您可以成功安装并运行 AList 代理服务。如需进一步帮助,请参考官方文档或联系技术支持。 \ No newline at end of file diff --git a/go.php b/go.php index 76ccbaf..e4ddffb 100644 --- a/go.php +++ b/go.php @@ -77,8 +77,23 @@ Swoole\Coroutine\run(function () use ($port, $apiEndpoint, $cacheDir, &$pathInde fetchApiData($apiEndpoint, $reqPath, $token, $query['sign'] ?? '', function ($apiData) use ($cacheDir, &$pathIndex, $uniqidhex, $response) { if ($apiData['code'] === 200 && isset($apiData['data']['url'])) { $pathIndex[$uniqidhex] = $uniqidhex; + + if (isCacheValid($cacheDir, $uniqidhex)) { + serveFromCache($cacheDir, $uniqidhex, $response); + return; + } + + // 写入缓存 file_put_contents("$cacheDir/$uniqidhex.meta", json_encode($apiData['data'])); - file_put_contents("$cacheDir/$uniqidhex.content", file_get_contents($apiData['data']['url'])); + + // 获取文件内容, curl + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $apiData['data']['url']); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 50); + $fileContent = curl_exec($ch); + curl_close($ch); + file_put_contents("$cacheDir/$uniqidhex.content", $fileContent); serveFromCache($cacheDir, $uniqidhex, $response); } else { @@ -107,7 +122,11 @@ function serveFromCache($cacheDir, $cacheFile, $response) { $response->header('Connection', 'keep-alive'); $response->header('Date', gmdate('D, d M Y H:i:s') . ' GMT'); $response->header('Last-Modified', gmdate('D, d M Y H:i:s') . ' GMT'); - $response->end(file_get_contents("$cacheDir/$cacheFile.content")); + + // 高效的读取文件 + $file = fopen("$cacheDir/$cacheFile.content", 'r'); + $response->end(fread($file, filesize("$cacheDir/$cacheFile.content"))); + fclose($file); } function fetchApiData($apiEndpoint, $reqPath, $token, $sign, $callback) {