<?php
$nosession = true;
$nosecu = true;
include("./includes/common.php");

$scriptpath = str_replace('\\', '/', $_SERVER['SCRIPT_NAME']);
$sitepath = substr($scriptpath, 0, strrpos($scriptpath, '/'));
$baseurl = (is_https() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $sitepath . '/';

$title = 'API接口文档 - ' . $conf['title'];
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?php echo htmlspecialchars($title); ?></title>
    <link rel="stylesheet" href="https://s4.zstatic.net/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://s4.zstatic.net/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <link rel="stylesheet" href="assets/css/api_doc.css?v=2">
</head>
<body>
<div class="api-doc-wrapper">
    <div class="api-header">
        <div class="container">
            <h1><i class="fa fa-code"></i> <?php echo htmlspecialchars($conf['title']); ?> API 接口文档</h1>
            <p class="api-version">版本 v2.0 | 最后更新:2026-5-15 <!-- <?php echo date('Y-m-d'); ?>--></p>
            <!-- <p class="api-base-url">基础URL: <code><?php echo $baseurl; ?></code></p> -->
        </div>
    </div>

    <div class="container">
        <div class="api-doc-body">
            <div class="api-sidebar">
                <div class="sidebar-title">接口目录</div>
                <ul class="sidebar-nav">
                    <li><a href="#overview"><i class="fa fa-info-circle"></i> 概述与认证</a></li>
                    <li><a href="#error-codes"><i class="fa fa-exclamation-triangle"></i> 错误码说明</a></li>
                    <li class="sidebar-divider"></li>
                    <li><a href="#user-auth"><i class="fa fa-user"></i> 用户认证接口</a></li>
                    <li><a href="#upload-api"><i class="fa fa-cloud-upload"></i> 文件上传接口</a></li>
                    <li><a href="#file-manage"><i class="fa fa-files-o"></i> 文件管理接口</a></li>
                    <li><a href="#folder-manage"><i class="fa fa-folder-o"></i> 文件夹管理接口</a></li>
                    <li><a href="#share-manage"><i class="fa fa-share-alt"></i> 分享管理接口</a></li>
                    <li><a href="#stats-api"><i class="fa fa-bar-chart"></i> 统计查询接口</a></li>
                    <li><a href="#redeem-api"><i class="fa fa-gift"></i> 卡密兑换接口</a></li>
                </ul>
            </div>

            <div class="api-content">

                <section id="overview" class="api-section">
                    <h2><i class="fa fa-info-circle"></i> 概述与认证方式</h2>
                    <div class="api-block">
                        <p>本文档描述了<?php echo htmlspecialchars($conf['title']); ?>系统的全部API接口，供开发者集成使用。</p>
                        <p>所有API响应均为<strong>JSON格式</strong>，Content-Type为 <code>application/json; charset=UTF-8</code>。</p>
                    </div>

                    <h3>认证方式</h3>
                    <div class="api-block">
                        <p>本系统支持以下三种认证方式：</p>
                        <table class="api-table">
                            <thead>
                                <tr><th>认证方式</th><th>说明</th><th>适用场景</th></tr>
                            </thead>
                            <tbody>
                                <tr>
                                    <td><strong>Cookie认证</strong></td>
                                    <td>用户通过Web端登录后自动获得Cookie，请求时自动携带</td>
                                    <td>Web前端、同域请求</td>
                                </tr>
                                <tr>
                                    <td><strong>API密钥认证</strong></td>
                                    <td>在请求参数中携带 <code>api_key</code> 参数，值为用户的API密钥</td>
                                    <td>第三方应用、CLI工具</td>
                                </tr>
                                <tr>
                                    <td><strong>Token认证</strong></td>
                                    <td>通过 <code>user_token</code> 参数或 <code>Authorization: Bearer &lt;token&gt;</code> 请求头传递</td>
                                    <td>App开发、跨域请求</td>
                                </tr>
                            </tbody>
                        </table>
                    </div>

                    <h3>通用响应格式</h3>
                    <div class="code-block">
<pre>{
  "code": 0,
  "msg": "操作成功",
  "data": { ... }
}</pre>
                    </div>
                    <p>其中 <code>code=0</code> 表示成功，负数表示各类错误。</p>
                </section>

                <section id="error-codes" class="api-section">
                    <h2><i class="fa fa-exclamation-triangle"></i> 错误码说明</h2>
                    <table class="api-table">
                        <thead>
                            <tr><th>错误码</th><th>含义</th><th>处理建议</th></tr>
                        </thead>
                        <tbody>
                            <tr><td><span class="badge badge-success">0</span></td><td>操作成功</td><td>正常处理响应数据</td></tr>
                            <tr><td><span class="badge badge-danger">-1</span></td><td>通用错误 / 参数错误</td><td>检查请求参数是否符合要求</td></tr>
                            <tr><td><span class="badge badge-danger">-4</span></td><td>功能未开启 / 未知操作</td><td>确认API开关已打开或action参数正确</td></tr>
                            <tr><td><span class="badge badge-danger">-5</span></td><td>账号已被禁用</td><td>联系管理员解封账号</td></tr>
                            <tr><td><span class="badge badge-danger">-6</span></td><td>认证失败</td><td>检查Token或API密钥是否正确</td></tr>
                        </tbody>
                    </table>
                </section>

                <section id="user-auth" class="api-section">
                    <h2><i class="fa fa-user"></i> 用户认证接口</h2>
                    <p class="section-desc">接口文件: <code>api_v2.php</code> | 不需要认证的接口: 登录、注册</p>

                    <div class="api-endpoint">
                        <div class="endpoint-header">
                            <span class="method method-post">POST</span>
                            <span class="endpoint-url">api_v2.php?action=login</span>
                        </div>
                        <h4>用户登录</h4>
                        <p>使用用户名和密码登录，返回用户Token。</p>
                        <table class="api-table">
                            <thead><tr><th>参数名</th><th>类型</th><th>必填</th><th>说明</th></tr></thead>
                            <tbody>
                                <tr><td>username</td><td>String</td><td><span class="badge badge-required">是</span></td><td>用户名，4-20位字母数字下划线</td></tr>
                                <tr><td>password</td><td>String</td><td><span class="badge badge-required">是</span></td><td>登录密码</td></tr>
                            </tbody>
                        </table>
                        <h5>返回示例</h5>
                        <div class="code-block"><pre>{
  "code": 0,
  "msg": "登录成功",
  "data": {
    "uid": 1,
    "username": "demo",
    "nickname": "demo",
    "email": "demo@example.com",
    "level": 0,
    "storage_used_mb": 15.23,
    "storage_limit_mb": 100,
    "traffic_used_mb": 45.6,
    "traffic_limit_mb": 500,
    "api_key": "a1b2c3d4...",
    "user_token": "enc_token_string",
    "token_expire": 1715731200,
    "register_time": "2024-01-01 12:00:00"
  }
}</pre></div>
                    </div>

                    <div class="api-endpoint">
                        <div class="endpoint-header">
                            <span class="method method-post">POST</span>
                            <span class="endpoint-url">api_v2.php?action=register</span>
                        </div>
                        <h4>用户注册</h4>
                        <p>注册新用户账号，成功后自动返回Token。</p>
                        <table class="api-table">
                            <thead><tr><th>参数名</th><th>类型</th><th>必填</th><th>说明</th></tr></thead>
                            <tbody>
                                <tr><td>username</td><td>String</td><td><span class="badge badge-required">是</span></td><td>用户名，4-20位字母数字下划线</td></tr>
                                <tr><td>password</td><td>String</td><td><span class="badge badge-required">是</span></td><td>密码，6-32位</td></tr>
                                <tr><td>nickname</td><td>String</td><td>否</td><td>昵称，不超过20字符，默认同用户名</td></tr>
                                <tr><td>email</td><td>String</td><td>否</td><td>邮箱地址</td></tr>
                            </tbody>
                        </table>
                        <h5>返回示例</h5>
                        <div class="code-block"><pre>{
  "code": 0,
  "msg": "注册成功",
  "data": {
    "uid": 2,
    "username": "newuser",
    "nickname": "新用户",
    "api_key": "a1b2c3d4...",
    "user_token": "enc_token_string",
    "token_expire": 1715731200,
    "storage_limit_mb": 100,
    "traffic_limit_mb": 500
  }
}</pre></div>
                    </div>

                    <div class="api-endpoint">
                        <div class="endpoint-header">
                            <span class="method method-get">GET</span>
                            <span class="endpoint-url">api_v2.php?action=profile</span>
                        </div>
                        <h4>获取用户资料</h4>
                        <p>获取当前登录用户的详细资料信息。需要认证。</p>
                        <h5>返回示例</h5>
                        <div class="code-block"><pre>{
  "code": 0,
  "data": {
    "uid": 1,
    "username": "demo",
    "nickname": "demo",
    "email": "demo@example.com",
    "level": 0,
    "enable": 1,
    "api_key": "a1b2c3d4...",
    "storage_used_mb": 15.23,
    "storage_limit_mb": 100,
    "traffic_used_mb": 45.6,
    "traffic_limit_mb": 500,
    "register_time": "2024-01-01 12:00:00",
    "last_login_time": "2024-05-01 08:30:00"
  }
}</pre></div>
                    </div>

                    <div class="api-endpoint">
                        <div class="endpoint-header">
                            <span class="method method-post">POST</span>
                            <span class="endpoint-url">api_v2.php?action=update_profile</span>
                        </div>
                        <h4>更新用户资料</h4>
                        <p>更新当前用户的昵称和邮箱。需要认证。</p>
                        <table class="api-table">
                            <thead><tr><th>参数名</th><th>类型</th><th>必填</th><th>说明</th></tr></thead>
                            <tbody>
                                <tr><td>nickname</td><td>String</td><td><span class="badge badge-required">是</span></td><td>新昵称，不超过20字符</td></tr>
                                <tr><td>email</td><td>String</td><td>否</td><td>新邮箱地址</td></tr>
                            </tbody>
                        </table>
                    </div>

                    <div class="api-endpoint">
                        <div class="endpoint-header">
                            <span class="method method-post">POST</span>
                            <span class="endpoint-url">api_v2.php?action=change_password</span>
                        </div>
                        <h4>修改密码</h4>
                        <p>修改当前用户的登录密码。需要认证。</p>
                        <table class="api-table">
                            <thead><tr><th>参数名</th><th>类型</th><th>必填</th><th>说明</th></tr></thead>
                            <tbody>
                                <tr><td>old_password</td><td>String</td><td><span class="badge badge-required">是</span></td><td>旧密码</td></tr>
                                <tr><td>new_password</td><td>String</td><td><span class="badge badge-required">是</span></td><td>新密码，6-32位</td></tr>
                            </tbody>
                        </table>
                    </div>

                    <div class="api-endpoint">
                        <div class="endpoint-header">
                            <span class="method method-get">GET</span>
                            <span class="endpoint-url">api_v2.php?action=api_key_info</span>
                        </div>
                        <h4>获取API密钥</h4>
                        <p>获取当前用户的API密钥，如果尚未生成则自动创建。需要认证。</p>
                    </div>

                    <div class="api-endpoint">
                        <div class="endpoint-header">
                            <span class="method method-post">POST</span>
                            <span class="endpoint-url">api_v2.php?action=regenerate_api_key</span>
                        </div>
                        <h4>重新生成API密钥</h4>
                        <p>重新生成API密钥，旧的密钥将立即失效。需要认证。</p>
                    </div>
                </section>

                <section id="upload-api" class="api-section">
                    <h2><i class="fa fa-cloud-upload"></i> 文件上传接口</h2>

                    <div class="api-endpoint">
                        <div class="endpoint-header">
                            <span class="method method-post">POST</span>
                            <span class="endpoint-url">api.php</span>
                        </div>
                        <h4>简单文件上传</h4>
                        <p>通过 multipart/form-data 格式直接上传文件。这是最简单的上传方式。</p>
                        <table class="api-table">
                            <thead><tr><th>参数名</th><th>类型</th><th>必填</th><th>说明</th></tr></thead>
                            <tbody>
                                <tr><td>file</td><td>File</td><td><span class="badge badge-required">是</span></td><td>待上传的文件（multipart格式）</td></tr>
                                <tr><td>show</td><td>Int</td><td>否</td><td>是否首页显示，1显示0隐藏，默认1</td></tr>
                                <tr><td>ispwd</td><td>Int</td><td>否</td><td>是否设置下载密码，1设置0不设置</td></tr>
                                <tr><td>pwd</td><td>String</td><td>否</td><td>下载密码（ispwd=1时必填），仅支持字母和数字</td></tr>
                                <tr><td>folder_id</td><td>Int</td><td>否</td><td>目标文件夹ID（需登录）</td></tr>
                                <tr><td>api_key</td><td>String</td><td>否</td><td>API密钥，用于身份认证</td></tr>
                                <tr><td>format</td><td>String</td><td>否</td><td>返回格式: json(默认) / jsonp / form</td></tr>
                                <tr><td>callback</td><td>String</td><td>否</td><td>JSONP回调函数名（format=jsonp时）</td></tr>
                            </tbody>
                        </table>
                        <h5>返回示例（成功）</h5>
                        <div class="code-block"><pre>{
  "code": 0,
  "msg": "文件上传成功！",
  "hash": "f1e807cb0d6ba52d71bdb02864e6ba8",
  "name": "example.jpg",
  "size": 58937,
  "type": "jpg",
  "id": 123,
  "downurl": "<?php echo $baseurl; ?>down.php?hash=...",
  "viewurl": "<?php echo $baseurl; ?>view.php?hash=...jpg"
}</pre></div>
                        <h5>返回示例（文件已存在）</h5>
                        <div class="code-block"><pre>{
  "code": 0,
  "msg": "本站已存在该文件",
  "exists": 1,
  "hash": "...",
  "name": "example.jpg",
  "size": 58937,
  "type": "jpg",
  "id": 123,
  "downurl": "<?php echo $baseurl; ?>down.php?hash=..."
}</pre></div>
                    </div>

                    <div class="api-endpoint">
                        <div class="endpoint-header">
                            <span class="method method-post">POST</span>
                            <span class="endpoint-url">ajax.php?act=pre_upload</span>
                        </div>
                        <h4>预上传检查（大文件分块上传第一步）</h4>
                        <p>在大文件上传前进行检查，包括文件大小限制、格式限制、配额检查等。需要CSRF Token。</p>
                        <table class="api-table">
                            <thead><tr><th>参数名</th><th>类型</th><th>必填</th><th>说明</th></tr></thead>
                            <tbody>
                                <tr><td>csrf_token</td><td>String</td><td><span class="badge badge-required">是</span></td><td>CSRF Token</td></tr>
                                <tr><td>name</td><td>String</td><td><span class="badge badge-required">是</span></td><td>文件名</td></tr>
                                <tr><td>hash</td><td>String</td><td><span class="badge badge-required">是</span></td><td>文件MD5（32位hex）</td></tr>
                                <tr><td>size</td><td>Int</td><td><span class="badge badge-required">是</span></td><td>文件大小（字节）</td></tr>
                                <tr><td>show</td><td>Int</td><td>否</td><td>是否首页显示</td></tr>
                                <tr><td>ispwd</td><td>Int</td><td>否</td><td>是否设置密码</td></tr>
                                <tr><td>pwd</td><td>String</td><td>否</td><td>下载密码</td></tr>
                                <tr><td>folder_id</td><td>Int</td><td>否</td><td>目标文件夹ID</td></tr>
                            </tbody>
                        </table>
                        <h5>返回示例（需要分块上传）</h5>
                        <div class="code-block"><pre>{
  "code": 0,
  "third": false,
  "hash": "...",
  "chunksize": 8388608,
  "chunks": 3
}</pre></div>
                    </div>

                    <div class="api-endpoint">
                        <div class="endpoint-header">
                            <span class="method method-post">POST</span>
                            <span class="endpoint-url">ajax.php?act=upload_part</span>
                        </div>
                        <h4>分块上传（大文件分块上传第二步）</h4>
                        <p>上传文件的单个分块。每块大小由pre_upload返回的chunksize决定（默认8MB）。</p>
                        <table class="api-table">
                            <thead><tr><th>参数名</th><th>类型</th><th>必填</th><th>说明</th></tr></thead>
                            <tbody>
                                <tr><td>file</td><td>File</td><td><span class="badge badge-required">是</span></td><td>当前分块的文件数据</td></tr>
                                <tr><td>hash</td><td>String</td><td><span class="badge badge-required">是</span></td><td>文件MD5</td></tr>
                                <tr><td>chunk</td><td>Int</td><td><span class="badge badge-required">是</span></td><td>当前分块编号（从1开始）</td></tr>
                            </tbody>
                        </table>
                    </div>

                    <div class="api-endpoint">
                        <div class="endpoint-header">
                            <span class="method method-post">POST</span>
                            <span class="endpoint-url">ajax.php?act=complete_upload</span>
                        </div>
                        <h4>完成上传（通过第三方云存储上传后使用）</h4>
                        <p>当使用第三方云存储直接上传后，调用此接口通知服务端完成数据入库。</p>
                        <table class="api-table">
                            <thead><tr><th>参数名</th><th>类型</th><th>必填</th><th>说明</th></tr></thead>
                            <tbody>
                                <tr><td>hash</td><td>String</td><td><span class="badge badge-required">是</span></td><td>文件MD5</td></tr>
                            </tbody>
                        </table>
                    </div>

                    <div class="api-endpoint">
                        <div class="endpoint-header">
                            <span class="method method-post">POST</span>
                            <span class="endpoint-url">folder_api.php?act=simple_upload</span>
                        </div>
                        <h4>简易上传（文件夹内）</h4>
                        <p>在指定文件夹内快速上传文件。需要认证。</p>
                        <table class="api-table">
                            <thead><tr><th>参数名</th><th>类型</th><th>必填</th><th>说明</th></tr></thead>
                            <tbody>
                                <tr><td>file</td><td>File</td><td><span class="badge badge-required">是</span></td><td>待上传的文件</td></tr>
                                <tr><td>folder_id</td><td>Int</td><td>否</td><td>目标文件夹ID</td></tr>
                            </tbody>
                        </table>
                    </div>
                </section>

                <section id="file-manage" class="api-section">
                    <h2><i class="fa fa-files-o"></i> 文件管理接口</h2>
                    <p class="section-desc">接口文件: <code>api_v2.php</code> | 所有接口需要认证</p>

                    <div class="api-endpoint">
                        <div class="endpoint-header">
                            <span class="method method-get">GET</span>
                            <span class="endpoint-url">api_v2.php?action=file_list</span>
                        </div>
                        <h4>获取文件列表</h4>
                        <p>获取当前用户上传的文件列表，支持分页和排序。</p>
                        <table class="api-table">
                            <thead><tr><th>参数名</th><th>类型</th><th>必填</th><th>说明</th></tr></thead>
                            <tbody>
                                <tr><td>page</td><td>Int</td><td>否</td><td>页码，默认1</td></tr>
                                <tr><td>limit</td><td>Int</td><td>否</td><td>每页数量，默认20，最大100</td></tr>
                                <tr><td>folder_id</td><td>Int</td><td>否</td><td>文件夹ID筛选，0或省略表示全部文件</td></tr>
                                <tr><td>sort</td><td>String</td><td>否</td><td>排序字段: id/name/size/addtime/count，默认id</td></tr>
                                <tr><td>order</td><td>String</td><td>否</td><td>排序方向: ASC/DESC，默认DESC</td></tr>
                            </tbody>
                        </table>
                        <h5>返回示例</h5>
                        <div class="code-block"><pre>{
  "code": 0,
  "data": {
    "page": 1,
    "limit": 20,
    "total": 85,
    "total_page": 5,
    "list": [
      {
        "id": 123,
        "name": "example.jpg",
        "type": "jpg",
        "size": 58937,
        "size_formatted": "57.6 KB",
        "hash": "f1e807cb...",
        "addtime": "2024-05-01 12:00:00",
        "hide": 0,
        "folder_id": 0,
        "download_count": 12,
        "download_url": "<?php echo $baseurl; ?>down.php?hash=...",
        "view_url": "<?php echo $baseurl; ?>view.php?hash=...jpg"
      }
    ]
  }
}</pre></div>
                    </div>

                    <div class="api-endpoint">
                        <div class="endpoint-header">
                            <span class="method method-get">GET</span>
                            <span class="endpoint-url">api_v2.php?action=file_info</span>
                        </div>
                        <h4>获取文件详情</h4>
                        <p>获取单个文件的详细信息，通过ID或Hash查询。</p>
                        <table class="api-table">
                            <thead><tr><th>参数名</th><th>类型</th><th>必填</th><th>说明</th></tr></thead>
                            <tbody>
                                <tr><td>id</td><td>Int</td><td>二选一</td><td>文件ID</td></tr>
                                <tr><td>hash</td><td>String</td><td>二选一</td><td>文件MD5 Hash（32位hex）</td></tr>
                            </tbody>
                        </table>
                    </div>

                    <div class="api-endpoint">
                        <div class="endpoint-header">
                            <span class="method method-get">GET</span>
                            <span class="endpoint-url">api_v2.php?action=file_search</span>
                        </div>
                        <h4>搜索文件</h4>
                        <p>根据关键词搜索用户的文件。</p>
                        <table class="api-table">
                            <thead><tr><th>参数名</th><th>类型</th><th>必填</th><th>说明</th></tr></thead>
                            <tbody>
                                <tr><td>kw</td><td>String</td><td><span class="badge badge-required">是</span></td><td>搜索关键词</td></tr>
                                <tr><td>type</td><td>String</td><td>否</td><td>文件类型筛选，多个用逗号分隔</td></tr>
                                <tr><td>page</td><td>Int</td><td>否</td><td>页码，默认1</td></tr>
                                <tr><td>limit</td><td>Int</td><td>否</td><td>每页数量，默认20，最大100</td></tr>
                            </tbody>
                        </table>
                    </div>

                    <div class="api-endpoint">
                        <div class="endpoint-header">
                            <span class="method method-post">POST</span>
                            <span class="endpoint-url">api_v2.php?action=file_rename</span>
                        </div>
                        <h4>重命名文件</h4>
                        <table class="api-table">
                            <thead><tr><th>参数名</th><th>类型</th><th>必填</th><th>说明</th></tr></thead>
                            <tbody>
                                <tr><td>file_id</td><td>Int</td><td><span class="badge badge-required">是</span></td><td>文件ID</td></tr>
                                <tr><td>new_name</td><td>String</td><td><span class="badge badge-required">是</span></td><td>新文件名</td></tr>
                            </tbody>
                        </table>
                    </div>

                    <div class="api-endpoint">
                        <div class="endpoint-header">
                            <span class="method method-post">POST</span>
                            <span class="endpoint-url">api_v2.php?action=file_delete</span>
                        </div>
                        <h4>删除文件</h4>
                        <table class="api-table">
                            <thead><tr><th>参数名</th><th>类型</th><th>必填</th><th>说明</th></tr></thead>
                            <tbody>
                                <tr><td>file_id</td><td>Int</td><td><span class="badge badge-required">是</span></td><td>文件ID</td></tr>
                            </tbody>
                        </table>
                    </div>

                    <div class="api-endpoint">
                        <div class="endpoint-header">
                            <span class="method method-post">POST</span>
                            <span class="endpoint-url">api_v2.php?action=file_toggle_hide</span>
                        </div>
                        <h4>切换文件显示/隐藏</h4>
                        <table class="api-table">
                            <thead><tr><th>参数名</th><th>类型</th><th>必填</th><th>说明</th></tr></thead>
                            <tbody>
                                <tr><td>file_id</td><td>Int</td><td><span class="badge badge-required">是</span></td><td>文件ID</td></tr>
                            </tbody>
                        </table>
                    </div>
                </section>

                <section id="folder-manage" class="api-section">
                    <h2><i class="fa fa-folder-o"></i> 文件夹管理接口</h2>
                    <p class="section-desc">接口文件: <code>folder_api.php</code> / <code>api_v2.php</code> | 需要认证</p>

                    <div class="api-endpoint">
                        <div class="endpoint-header">
                            <span class="method method-get">GET</span>
                            <span class="endpoint-url">api_v2.php?action=folder_list</span>
                        </div>
                        <h4>获取文件夹列表</h4>
                        <table class="api-table">
                            <thead><tr><th>参数名</th><th>类型</th><th>必填</th><th>说明</th></tr></thead>
                            <tbody>
                                <tr><td>parent_id</td><td>Int</td><td>否</td><td>父文件夹ID，0表示根目录，默认0</td></tr>
                            </tbody>
                        </table>
                    </div>

                    <div class="api-endpoint">
                        <div class="endpoint-header">
                            <span class="method method-post">POST</span>
                            <span class="endpoint-url">api_v2.php?action=folder_create</span>
                        </div>
                        <h4>创建文件夹</h4>
                        <table class="api-table">
                            <thead><tr><th>参数名</th><th>类型</th><th>必填</th><th>说明</th></tr></thead>
                            <tbody>
                                <tr><td>name</td><td>String</td><td><span class="badge badge-required">是</span></td><td>文件夹名称，不超过50字符</td></tr>
                                <tr><td>parent_id</td><td>Int</td><td>否</td><td>父文件夹ID，默认0（根目录）</td></tr>
                            </tbody>
                        </table>
                    </div>

                    <h4>完整文件夹操作（通过 folder_api.php）</h4>
                    <p>以下操作通过 <code>folder_api.php</code> 实现，支持的操作：</p>
                    <table class="api-table">
                        <thead><tr><th>act参数</th><th>说明</th><th>关键参数</th></tr></thead>
                        <tbody>
                            <tr><td>create</td><td>创建文件夹</td><td>name, parent_id</td></tr>
                            <tr><td>rename</td><td>重命名文件夹</td><td>folder_id, new_name</td></tr>
                            <tr><td>delete</td><td>删除文件夹</td><td>folder_id</td></tr>
                            <tr><td>batch_delete</td><td>批量删除</td><td>folder_ids, file_ids</td></tr>
                            <tr><td>sort</td><td>排序文件夹</td><td>folder_id, sort(1-999)</td></tr>
                            <tr><td>move</td><td>移动文件/文件夹</td><td>target_id, folder_ids, file_ids</td></tr>
                            <tr><td>list</td><td>获取文件夹内容</td><td>parent_id, kw</td></tr>
                            <tr><td>get_share_info</td><td>获取文件夹分享信息</td><td>folder_id</td></tr>
                            <tr><td>set_share</td><td>设置文件夹分享</td><td>folder_id, share_need_pwd, share_pwd, share_notice</td></tr>
                            <tr><td>rename_file</td><td>重命名文件</td><td>file_id, new_name</td></tr>
                            <tr><td>get_password</td><td>获取文件密码</td><td>file_id</td></tr>
                            <tr><td>set_password</td><td>设置文件密码</td><td>file_id, password</td></tr>
                            <tr><td>batch_rename</td><td>批量重命名</td><td>file_ids, pattern</td></tr>
                            <tr><td>batch_copy</td><td>批量复制</td><td>file_ids, target_id</td></tr>
                            <tr><td>transfer</td><td>转存文件/文件夹</td><td>url, password, target_folder</td></tr>
                            <tr><td>transfer_preview</td><td>转存预览</td><td>url</td></tr>
                            <tr><td>get_file_share_info</td><td>获取文件分享信息</td><td>file_id</td></tr>
                            <tr><td>set_file_share</td><td>设置文件分享</td><td>file_id, share_type, share_notice</td></tr>
                        </tbody>
                    </table>
                </section>

                <section id="share-manage" class="api-section">
                    <h2><i class="fa fa-share-alt"></i> 分享管理接口</h2>
                    <p class="section-desc">接口文件: <code>api_v2.php</code> | 需要认证</p>

                    <div class="api-endpoint">
                        <div class="endpoint-header">
                            <span class="method method-post">POST</span>
                            <span class="endpoint-url">api_v2.php?action=share_create</span>
                        </div>
                        <h4>创建分享链接</h4>
                        <p>为指定文件生成分享链接。</p>
                        <table class="api-table">
                            <thead><tr><th>参数名</th><th>类型</th><th>必填</th><th>说明</th></tr></thead>
                            <tbody>
                                <tr><td>file_id</td><td>Int</td><td><span class="badge badge-required">是</span></td><td>文件ID</td></tr>
                            </tbody>
                        </table>
                        <h5>返回示例</h5>
                        <div class="code-block"><pre>{
  "code": 0,
  "msg": "分享链接创建成功",
  "data": {
    "share_key": "a1b2c3d4e5f6g7h8",
    "share_link": "<?php echo $baseurl; ?>share.php?key=a1b2c3d4e5f6g7h8",
    "direct_link": "<?php echo $baseurl; ?>file.php?hash=..."
  }
}</pre></div>
                    </div>

                    <div class="api-endpoint">
                        <div class="endpoint-header">
                            <span class="method method-get">GET</span>
                            <span class="endpoint-url">api_v2.php?action=share_info</span>
                        </div>
                        <h4>获取分享信息</h4>
                        <table class="api-table">
                            <thead><tr><th>参数名</th><th>类型</th><th>必填</th><th>说明</th></tr></thead>
                            <tbody>
                                <tr><td>file_id</td><td>Int</td><td><span class="badge badge-required">是</span></td><td>文件ID</td></tr>
                            </tbody>
                        </table>
                    </div>

                    <div class="api-endpoint">
                        <div class="endpoint-header">
                            <span class="method method-post">POST</span>
                            <span class="endpoint-url">api_v2.php?action=share_revoke</span>
                        </div>
                        <h4>撤销分享链接</h4>
                        <table class="api-table">
                            <thead><tr><th>参数名</th><th>类型</th><th>必填</th><th>说明</th></tr></thead>
                            <tbody>
                                <tr><td>file_id</td><td>Int</td><td><span class="badge badge-required">是</span></td><td>文件ID</td></tr>
                            </tbody>
                        </table>
                    </div>
                </section>

                <section id="stats-api" class="api-section">
                    <h2><i class="fa fa-bar-chart"></i> 统计查询接口</h2>
                    <p class="section-desc">接口文件: <code>api_v2.php</code> | 需要认证</p>

                    <div class="api-endpoint">
                        <div class="endpoint-header">
                            <span class="method method-get">GET</span>
                            <span class="endpoint-url">api_v2.php?action=stats_summary</span>
                        </div>
                        <h4>获取综合统计</h4>
                        <p>获取当前用户的存储、流量、文件、文件夹综合统计数据。</p>
                        <h5>返回示例</h5>
                        <div class="code-block"><pre>{
  "code": 0,
  "data": {
    "storage": {
      "used_bytes": 15728640,
      "used_mb": 15.0,
      "limit_mb": 100,
      "limit_bytes": 104857600,
      "is_unlimited": false,
      "usage_percent": 15.0
    },
    "traffic": {
      "used_bytes": 52428800,
      "used_mb": 50.0,
      "limit_mb": 500,
      "limit_bytes": 524288000,
      "is_unlimited": false,
      "usage_percent": 10.0,
      "reset_interval_days": 30
    },
    "files": {
      "total_count": 85,
      "today_uploads": 3,
      "total_downloads": 452
    },
    "folders": {
      "total_count": 5
    }
  }
}</pre></div>
                    </div>

                    <div class="api-endpoint">
                        <div class="endpoint-header">
                            <span class="method method-get">GET</span>
                            <span class="endpoint-url">api_v2.php?action=disk_usage</span>
                        </div>
                        <h4>获取磁盘使用详情</h4>
                        <p>获取存储空间详细使用情况，包含按文件类型的分类统计。</p>
                    </div>

                    <div class="api-endpoint">
                        <div class="endpoint-header">
                            <span class="method method-get">GET</span>
                            <span class="endpoint-url">api_v2.php?action=traffic_logs</span>
                        </div>
                        <h4>获取流量日志</h4>
                        <p>获取用户的流量消耗日志记录。</p>
                        <table class="api-table">
                            <thead><tr><th>参数名</th><th>类型</th><th>必填</th><th>说明</th></tr></thead>
                            <tbody>
                                <tr><td>page</td><td>Int</td><td>否</td><td>页码，默认1</td></tr>
                                <tr><td>limit</td><td>Int</td><td>否</td><td>每页数量，默认20，最大100</td></tr>
                                <tr><td>days</td><td>Int</td><td>否</td><td>查询最近N天，默认7天，最大90天</td></tr>
                            </tbody>
                        </table>
                    </div>
                </section>

                <section id="redeem-api" class="api-section">
                    <h2><i class="fa fa-gift"></i> 卡密兑换接口</h2>
                    <p class="section-desc">接口文件: <code>api_v2.php</code> | 需要认证</p>

                    <div class="api-endpoint">
                        <div class="endpoint-header">
                            <span class="method method-post">POST</span>
                            <span class="endpoint-url">api_v2.php?action=redeem</span>
                        </div>
                        <h4>兑换卡密</h4>
                        <p>使用卡密代码兑换存储空间和流量配额。</p>
                        <table class="api-table">
                            <thead><tr><th>参数名</th><th>类型</th><th>必填</th><th>说明</th></tr></thead>
                            <tbody>
                                <tr><td>card_code</td><td>String</td><td><span class="badge badge-required">是</span></td><td>卡密代码</td></tr>
                            </tbody>
                        </table>
                        <h5>返回示例</h5>
                        <div class="code-block"><pre>{
  "code": 0,
  "msg": "兑换成功",
  "data": {
    "storage_added_mb": 50,
    "traffic_added_mb": 100,
    "resource_info": { ... }
  }
}</pre></div>
                    </div>

                    <div class="api-endpoint">
                        <div class="endpoint-header">
                            <span class="method method-get">GET</span>
                            <span class="endpoint-url">api_v2.php?action=redeem_history</span>
                        </div>
                        <h4>获取兑换记录</h4>
                        <table class="api-table">
                            <thead><tr><th>参数名</th><th>类型</th><th>必填</th><th>说明</th></tr></thead>
                            <tbody>
                                <tr><td>page</td><td>Int</td><td>否</td><td>页码，默认1</td></tr>
                                <tr><td>limit</td><td>Int</td><td>否</td><td>每页数量，默认20，最大100</td></tr>
                            </tbody>
                        </table>
                    </div>
                </section>

                <div class="api-footer">
                    <p><i class="fa fa-file-text-o"></i> <?php echo htmlspecialchars($conf['title']); ?> API 接口文档 v2.0</p>
                    <p>如有疑问请联系管理员</p>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="assets/js/api_doc.js?v=2"></script>
</body>
</html>