Files
ipass__ipass/www/apix.html
T
admin 1f548ac953 feat(api-proxy): 新增「API 代理」板块,把外部免费 API 市场挂到网关下
后端(rust/src/apix.rs,新模块)
- /apix/<slug>?<参数> → 市场 POST /api/v1/ai/request;复用 LLM 的 sk_ 鉴权 +
  配额 + 用量统计(slot 带 api/ 前缀,天然归组)
- 请求体由网关从 query 拼:asset_id 服务端决定(调用方只能选参数),堵住
  「客户端自选最贵资产」的口子;GET 经 proxy_method POST + proxy_set_body 转带体
- data/api-proxies.json(含平台真 Key,等同 users.json 敏感度):base+key+items
  shm 写穿 ax:,停用=摘键;平台 Key 不回显(只给掩码)
- 6 个 nginx 变量 + /_apix_probe/<slug>(internal)免费预估探测,复用 $apix_probe_*

前端(www/apix.html + assets/apix.js)
- 市场凭据配置 / 目录直拉(GET /api/v1/assets,跨域已开)/ 代理增删启停 /
  复制地址 / 免费预估测试(带回平台余额)

验证
- 回归 261 条全绿(网关 102 + LLM 159,新增 34 条 apix 断言)
- 涵盖:无/坏 Key→401、不存在/停用 slug→404、GET 改写 POST、换平台 Key、
  体由网关拼、下行 Key 不泄漏、写穿 shm、探测归 api/<slug>

文档
- readme §15.1 API 代理使用 + 变更日志;CLAUDE.md location 表补 ipass_apix
2026-09-13 02:46:35 +08:00

85 lines
4.2 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<base href="/admin/">
<title>API 代理 · 尚数网 山海关</title>
<link rel="stylesheet" href="assets/admin.css">
</head>
<body>
<div id="shell"></div>
<div class="wrap">
<div class="panel">
<h2>API 市场凭据</h2>
<div class="desc">
把外部 API 市场(默认 <code>搜蚁智选 / AIMALL</code>)挂到网关下:调用方用<b>同一把账号 API Key</b>,
访问 <code>/apix/&lt;代理名&gt;?参数=值</code>,网关换成平台 Key 后转发到市场,并返回市场原样结果。
资产由<b>本页面的配置</b>决定(不是调用方在请求里指定),所以管理员能控制"只暴露哪些、不暴露哪些"。
</div>
<form id="platformForm" class="grid-form up-form">
<div><label for="pfBase">市场基址</label><input id="pfBase" class="field-mono" type="text" placeholder="https://souyi.net.cn"></div>
<div><label for="pfKey">平台 API Key(留空 = 不修改)</label><input id="pfKey" class="field-mono" type="text" placeholder="ak_..." autocomplete="off"></div>
<div><button class="btn-primary btn-block" type="submit">保存凭据</button></div>
<div class="span-all muted" id="pfState" style="font-size:12.5px"></div>
</form>
</div>
<div class="panel">
<h2>新建 / 更新代理</h2>
<div class="desc">
<b>slug</b> 是对外的名字(<code>/apix/slug</code>),<b>asset_id</b> 是市场内部的资产标识。
参数只能走 query string(转发决策在 access 阶段,那时读不到请求体),
声明的参数名只用于生成示例地址,实际转发会把全部 query 参数原样带过去。
</div>
<form id="upsertApixForm" class="grid-form up-form">
<div><label for="axSlug">slug(对外名字)</label><input id="axSlug" type="text" placeholder="search" required></div>
<div><label for="axName">展示名</label><input id="axName" type="text" placeholder="SearXNG 免费搜索"></div>
<div class="span-all"><label for="axAsset">asset_id(市场资产标识)</label><input id="axAsset" class="field-mono" type="text" placeholder="searxng-search" required></div>
<div class="span-all"><label for="axParams">参数名(逗号分隔,仅用于生成示例地址)</label><input id="axParams" class="field-mono" type="text" placeholder="q"></div>
<div class="span-all"><label for="axDesc">说明</label><input id="axDesc" type="text" placeholder="可选"></div>
<div><button class="btn-primary btn-block" type="submit">保存代理</button></div>
</form>
</div>
<div class="panel">
<h2>市场资产目录 <span class="muted" style="font-size:12.5px;font-weight:400">(点「接入」自动填表)</span></h2>
<div class="desc">
直接从市场拉取公开目录(<code>GET /api/v1/assets</code>,匿名可读、已开放跨域),
价格是市场侧的实时数字。<b>免费</b>的资产接入后不消耗余额,计费资产请先看自己的余额再开放。
</div>
<div class="row-actions" style="margin-bottom:8px">
<button class="btn-sm" id="refreshCatalog">刷新目录</button>
<span class="muted" id="catalogState" style="font-size:12.5px"></span>
</div>
<table>
<thead><tr>
<th>asset_id</th><th>名称 / 说明</th><th>类型</th><th>单价</th><th>30 天成功率</th><th>操作</th>
</tr></thead>
<tbody id="catalogBody"><tr><td colspan="6" class="empty">点「刷新目录」拉取</td></tr></tbody>
</table>
</div>
<div class="panel">
<h2>代理列表</h2>
<div class="desc">
停用的代理对调用方表现为 404(共享内存里已摘除,立即生效)。
「测试」走市场的<b>免费</b>预估接口,不执行资产、不扣费,顺带把平台余额带回来。
</div>
<table>
<thead><tr>
<th>slug</th><th>asset_id</th><th>调用地址</th><th>单价</th><th>状态</th><th>创建时间</th><th>操作</th>
</tr></thead>
<tbody id="apixBody"></tbody>
</table>
</div>
</div>
<div id="toast"></div>
<script src="assets/core.js"></script>
<script src="assets/apix.js"></script>
</body>
</html>