Files
media-parser/templates/components/api_docs.html
T

1284 lines
83 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.
{# 统一 API 接入文档与在线调试抽屉 (Stripe / OpenAPI Style Documentation & Drawer) #}
<div class="space-y-6 max-w-7xl mx-auto">
<!-- 纯净文档画布卡片 (Seamless Canvas) -->
<div class="bg-white rounded-xl border border-slate-200/80 shadow-sm p-6 sm:p-8">
<!-- 接口核心 Hero 头部 -->
<div class="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 pb-6 mb-8 border-b border-slate-100">
<div class="flex flex-wrap items-center gap-3">
<span class="inline-flex items-center px-2.5 py-1 rounded-md text-xs font-bold font-mono bg-emerald-50 text-emerald-700 border border-emerald-200">GET</span>
<code class="text-base sm:text-lg font-mono font-semibold text-slate-800 bg-slate-50 px-3 py-1 rounded-lg border border-slate-200/70" id="api-hero-full-path">/api/v1/parse</code>
</div>
<div class="flex items-center gap-3">
<button type="button" class="inline-flex items-center gap-2 px-4 py-2 bg-brand-600 hover:bg-brand-700 active:bg-brand-800 text-white font-medium text-sm rounded-lg shadow-sm shadow-brand-500/20 transition-colors" onclick="openPlaygroundDrawer()">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polygon points="5 3 19 12 5 21 5 3"/></svg>
<span>在线接口调试</span>
</button>
</div>
</div>
<!-- 正文阅读流与固定目录布局 (Layout: Article + Sticky TOC) -->
<div class="grid grid-cols-1 lg:grid-cols-[1fr_200px] gap-10 items-start">
<article class="space-y-10 min-w-0">
<!-- 1. 鉴权机制 -->
<section id="sec-auth" class="api-doc-section scroll-mt-24 space-y-4">
<h2 class="text-base font-bold text-slate-900 flex items-center gap-2 pb-2 border-b border-slate-100">1. 接口鉴权机制</h2>
<p class="text-sm leading-relaxed text-slate-600">
解析接口调用必须携带有效的 API Key 凭证。为了避免访问日志或浏览器记录泄露密钥,<strong class="text-slate-800 font-semibold">强烈推荐使用标准 HTTP Header 鉴权方式</strong>。
</p>
<div class="overflow-x-auto rounded-lg border border-slate-200 bg-white">
<table class="w-full text-left text-xs border-collapse">
<thead class="bg-slate-50/80 border-b border-slate-200 text-slate-700 font-semibold">
<tr>
<th class="px-3.5 py-3" style="width:200px">鉴权项</th>
<th class="px-3.5 py-3" style="width:130px">传递位置</th>
<th class="px-3.5 py-3">语法示例 / 填写说明</th>
</tr>
</thead>
<tbody class="divide-y divide-slate-100 font-normal">
<tr>
<td class="px-3.5 py-2.5">
<code class="font-mono text-xs font-semibold text-slate-800 bg-slate-100/90 px-2 py-0.5 rounded border border-slate-200/60">Authorization</code>
</td>
<td class="px-3.5 py-2.5 text-slate-500 font-mono">HTTP Header</td>
<td class="px-3.5 py-2.5 text-slate-600">
你的 API Key 凭证。<code class="font-mono text-xs px-2 py-0.5 rounded bg-slate-100 text-slate-800 border border-slate-200/50">Authorization: Bearer &lt;API_KEY&gt;</code> <span class="ml-2 inline-flex items-center px-1.5 py-0.5 rounded text-[11px] font-medium bg-emerald-50 text-emerald-700 border border-emerald-200/60">推荐</span>
</td>
</tr>
<tr>
<td class="px-3.5 py-2.5">
<code class="font-mono text-xs font-semibold text-slate-800 bg-slate-100/90 px-2 py-0.5 rounded border border-slate-200/60">key</code>
</td>
<td class="px-3.5 py-2.5 text-slate-500 font-mono">URL Query</td>
<td class="px-3.5 py-2.5 text-slate-600">
URL 查询参数。<code class="font-mono text-xs px-2 py-0.5 rounded bg-slate-100 text-slate-800 border border-slate-200/50">?key=&lt;API_KEY&gt;</code> <span class="ml-2 inline-flex items-center px-1.5 py-0.5 rounded text-[11px] font-medium bg-slate-100 text-slate-600 border border-slate-200/60">兼容模式</span>
</td>
</tr>
</tbody>
</table>
</div>
</section>
<!-- 2. 请求参数规范 -->
<section id="sec-params" class="api-doc-section scroll-mt-24 space-y-4">
<h2 class="text-base font-bold text-slate-900 flex items-center gap-2 pb-2 border-b border-slate-100">2. 请求参数规范</h2>
<p class="text-sm leading-relaxed text-slate-600">接口采用 HTTP GET 方法请求,参数如下:</p>
<div class="overflow-x-auto rounded-lg border border-slate-200 bg-white">
<table class="w-full text-left text-xs border-collapse">
<thead class="bg-slate-50/80 border-b border-slate-200 text-slate-700 font-semibold">
<tr>
<th class="px-3.5 py-3" style="width:180px">参数名</th>
<th class="px-3.5 py-3" style="width:90px">位置</th>
<th class="px-3.5 py-3" style="width:80px">类型</th>
<th class="px-3.5 py-3" style="width:80px">是否必选</th>
<th class="px-3.5 py-3">说明与填写规范</th>
</tr>
</thead>
<tbody class="divide-y divide-slate-100 font-normal">
<tr>
<td class="px-3.5 py-2.5">
<code class="font-mono text-xs font-semibold text-slate-800 bg-slate-100/90 px-2 py-0.5 rounded border border-slate-200/60">url</code>
</td>
<td class="px-3.5 py-2.5 text-slate-500 font-mono">Query</td>
<td class="px-3.5 py-2.5 text-slate-500">String</td>
<td class="px-3.5 py-2.5"><span class="inline-flex items-center px-1.5 py-0.5 rounded text-[11px] font-medium bg-rose-50 text-rose-700 border border-rose-200/60">必选</span></td>
<td class="px-3.5 py-2.5 text-slate-600 leading-relaxed">目标分享链接或包含分享文本的完整字符串(系统将自动提取文案中的 http/https 链接,长度限 2000 字符内)。</td>
</tr>
<tr>
<td class="px-3.5 py-2.5">
<code class="font-mono text-xs font-semibold text-slate-800 bg-slate-100/90 px-2 py-0.5 rounded border border-slate-200/60">Authorization</code>
</td>
<td class="px-3.5 py-2.5 text-slate-500 font-mono">Header</td>
<td class="px-3.5 py-2.5 text-slate-500">String</td>
<td class="px-3.5 py-2.5"><span class="inline-flex items-center px-1.5 py-0.5 rounded text-[11px] font-medium bg-emerald-50 text-emerald-700 border border-emerald-200/60">推荐</span></td>
<td class="px-3.5 py-2.5 text-slate-600 leading-relaxed">标准 Bearer 授权凭据。格式:<code class="font-mono text-xs px-1.5 py-0.5 rounded bg-slate-100 text-slate-800 border border-slate-200/50">Bearer mp-xxxxxxxxxxxx</code></td>
</tr>
<tr>
<td class="px-3.5 py-2.5">
<code class="font-mono text-xs font-semibold text-slate-800 bg-slate-100/90 px-2 py-0.5 rounded border border-slate-200/60">key</code>
</td>
<td class="px-3.5 py-2.5 text-slate-500 font-mono">Query</td>
<td class="px-3.5 py-2.5 text-slate-500">String</td>
<td class="px-3.5 py-2.5"><span class="inline-flex items-center px-1.5 py-0.5 rounded text-[11px] font-medium bg-slate-100 text-slate-600 border border-slate-200/60">可选</span></td>
<td class="px-3.5 py-2.5 text-slate-600 leading-relaxed">未携带 Authorization Header 时的兼容授权参数。</td>
</tr>
</tbody>
</table>
</div>
</section>
<!-- 3. 返回数据字典 -->
<section id="sec-schema" class="api-doc-section scroll-mt-24 space-y-4">
<h2 class="text-base font-bold text-slate-900 flex items-center gap-2 pb-2 border-b border-slate-100">3. 返回 JSON 数据字典</h2>
<p class="text-sm leading-relaxed text-slate-600">所有接口返回标准的 JSON 结构,包含全局状态标识与媒体详情数据:</p>
<h3 class="text-xs font-semibold text-slate-700 pt-2">3.1 基础返回格式</h3>
<div class="overflow-x-auto rounded-lg border border-slate-200 bg-white">
<table class="w-full text-left text-xs border-collapse">
<thead class="bg-slate-50/80 border-b border-slate-200 text-slate-700 font-semibold">
<tr>
<th class="px-3.5 py-3" style="width:160px">字段名</th>
<th class="px-3.5 py-3" style="width:120px">类型</th>
<th class="px-3.5 py-3">业务含义与说明</th>
</tr>
</thead>
<tbody class="divide-y divide-slate-100 font-normal">
<tr>
<td class="px-3.5 py-2.5"><code class="font-mono text-xs font-semibold text-slate-800 bg-slate-100/90 px-2 py-0.5 rounded border border-slate-200/60">succ</code></td>
<td class="px-3.5 py-2.5 text-slate-500">Boolean</td>
<td class="px-3.5 py-2.5 text-slate-600">请求是否成功:<code class="text-emerald-700 bg-emerald-50 px-1.5 py-0.5 rounded font-mono border border-emerald-200/60">true</code> 成功;<code class="text-rose-700 bg-rose-50 px-1.5 py-0.5 rounded font-mono border border-rose-200/60">false</code> 失败。</td>
</tr>
<tr>
<td class="px-3.5 py-2.5"><code class="font-mono text-xs font-semibold text-slate-800 bg-slate-100/90 px-2 py-0.5 rounded border border-slate-200/60">retcode</code></td>
<td class="px-3.5 py-2.5 text-slate-500">Integer</td>
<td class="px-3.5 py-2.5 text-slate-600">业务响应状态码。成功时为 <code class="font-mono text-xs px-1.5 py-0.5 rounded bg-slate-100 text-slate-800 border border-slate-200/50">200</code>,失败时为对应 HTTP 状态(如 400, 401, 402, 429, 503 等)。</td>
</tr>
<tr>
<td class="px-3.5 py-2.5"><code class="font-mono text-xs font-semibold text-slate-800 bg-slate-100/90 px-2 py-0.5 rounded border border-slate-200/60">retdesc</code></td>
<td class="px-3.5 py-2.5 text-slate-500">String</td>
<td class="px-3.5 py-2.5 text-slate-600">提示信息或官方/系统异常原因说明。</td>
</tr>
<tr>
<td class="px-3.5 py-2.5"><code class="font-mono text-xs font-semibold text-slate-800 bg-slate-100/90 px-2 py-0.5 rounded border border-slate-200/60">error_code</code></td>
<td class="px-3.5 py-2.5 text-slate-500">String</td>
<td class="px-3.5 py-2.5 text-slate-600">失败时返回的机器可读标准错误标识(如 <code class="font-mono text-[11px]">MEDIA_DELETED_OR_PRIVATE</code>、<code class="font-mono text-[11px]">NO_MEDIA_IN_CONTENT</code>、<code class="font-mono text-[11px]">RATE_LIMITED</code> 等,详见第 5 节)。</td>
</tr>
<tr>
<td class="px-3.5 py-2.5"><code class="font-mono text-xs font-semibold text-slate-800 bg-slate-100/90 px-2 py-0.5 rounded border border-slate-200/60">data</code></td>
<td class="px-3.5 py-2.5 text-slate-500">Object / null</td>
<td class="px-3.5 py-2.5 text-slate-600">解析成功返回的媒体实体数据对象,失败时为 <code class="font-mono text-xs text-slate-400">null</code>。</td>
</tr>
</tbody>
</table>
</div>
<h3 class="text-xs font-semibold text-slate-700 pt-3">3.2 媒体数据主体 (data 字段)</h3>
<div class="overflow-x-auto rounded-lg border border-slate-200 bg-white">
<table class="w-full text-left text-xs border-collapse">
<thead class="bg-slate-50/80 border-b border-slate-200 text-slate-700 font-semibold">
<tr>
<th class="px-3.5 py-3" style="width:160px">字段名</th>
<th class="px-3.5 py-3" style="width:120px">类型</th>
<th class="px-3.5 py-3">说明与数据含义</th>
</tr>
</thead>
<tbody class="divide-y divide-slate-100 font-normal">
<tr>
<td class="px-3.5 py-2.5"><code class="font-mono text-xs font-semibold text-slate-800 bg-slate-100/90 px-2 py-0.5 rounded border border-slate-200/60">platform</code></td>
<td class="px-3.5 py-2.5 text-slate-500">String</td>
<td class="px-3.5 py-2.5 text-slate-600">自动识别出的平台名称(如:<code class="bg-slate-100 px-1.5 py-0.5 rounded text-slate-800">抖音</code>、<code class="bg-slate-100 px-1.5 py-0.5 rounded text-slate-800">哔哩哔哩</code>、<code class="bg-slate-100 px-1.5 py-0.5 rounded text-slate-800">快手</code>、<code class="bg-slate-100 px-1.5 py-0.5 rounded text-slate-800">小红书</code> 等)。</td>
</tr>
<tr>
<td class="px-3.5 py-2.5"><code class="font-mono text-xs font-semibold text-slate-800 bg-slate-100/90 px-2 py-0.5 rounded border border-slate-200/60">video_id</code></td>
<td class="px-3.5 py-2.5 text-slate-500">String</td>
<td class="px-3.5 py-2.5 text-slate-600">源平台作品的全局唯一 ID。</td>
</tr>
<tr>
<td class="px-3.5 py-2.5"><code class="font-mono text-xs font-semibold text-slate-800 bg-slate-100/90 px-2 py-0.5 rounded border border-slate-200/60">title</code></td>
<td class="px-3.5 py-2.5 text-slate-500">String</td>
<td class="px-3.5 py-2.5 text-slate-600">作品标题或文案摘要。</td>
</tr>
<tr>
<td class="px-3.5 py-2.5"><code class="font-mono text-xs font-semibold text-slate-800 bg-slate-100/90 px-2 py-0.5 rounded border border-slate-200/60">desc</code></td>
<td class="px-3.5 py-2.5 text-slate-500">String</td>
<td class="px-3.5 py-2.5 text-slate-600">作品完整文本描述。</td>
</tr>
<tr>
<td class="px-3.5 py-2.5"><code class="font-mono text-xs font-semibold text-slate-800 bg-slate-100/90 px-2 py-0.5 rounded border border-slate-200/60">cover_url</code></td>
<td class="px-3.5 py-2.5 text-slate-500">String</td>
<td class="px-3.5 py-2.5 text-slate-600">作品高清主封面图 HTTPS 直链。</td>
</tr>
<tr>
<td class="px-3.5 py-2.5"><code class="font-mono text-xs font-semibold text-slate-800 bg-slate-100/90 px-2 py-0.5 rounded border border-slate-200/60">video_url</code></td>
<td class="px-3.5 py-2.5 text-slate-500">String</td>
<td class="px-3.5 py-2.5 text-slate-600">无水印视频 MP4 直链(纯图集作品时为空字符串)。</td>
</tr>
<tr>
<td class="px-3.5 py-2.5"><code class="font-mono text-xs font-semibold text-slate-800 bg-slate-100/90 px-2 py-0.5 rounded border border-slate-200/60">video_list</code></td>
<td class="px-3.5 py-2.5 text-slate-500">Array</td>
<td class="px-3.5 py-2.5 text-slate-600">可选。包含多清晰度(1080P/720P)或备用播放源直链数组。</td>
</tr>
<tr>
<td class="px-3.5 py-2.5"><code class="font-mono text-xs font-semibold text-slate-800 bg-slate-100/90 px-2 py-0.5 rounded border border-slate-200/60">image_list</code></td>
<td class="px-3.5 py-2.5 text-slate-500">Array</td>
<td class="px-3.5 py-2.5 text-slate-600">高清图集直链数组(支持 LivePhoto 动态图片)。</td>
</tr>
<tr>
<td class="px-3.5 py-2.5"><code class="font-mono text-xs font-semibold text-slate-800 bg-slate-100/90 px-2 py-0.5 rounded border border-slate-200/60">audio_url</code></td>
<td class="px-3.5 py-2.5 text-slate-500">String</td>
<td class="px-3.5 py-2.5 text-slate-600">提取出的背景音乐或纯音频直链(MP3 / M4A)。</td>
</tr>
<tr>
<td class="px-3.5 py-2.5"><code class="font-mono text-xs font-semibold text-slate-800 bg-slate-100/90 px-2 py-0.5 rounded border border-slate-200/60">author</code></td>
<td class="px-3.5 py-2.5 text-slate-500">Object</td>
<td class="px-3.5 py-2.5 text-slate-600">创作者信息对象:<code class="font-mono text-xs px-1.5 py-0.5 rounded bg-slate-100 text-slate-800 border border-slate-200/50">{ "name": "作者名", "avatar": "头像URL", "uid": "ID" }</code></td>
</tr>
</tbody>
</table>
</div>
</section>
<!-- 4. 多语言代码集成 -->
<section id="sec-snippets" class="api-doc-section scroll-mt-24 space-y-4">
<h2 class="text-base font-bold text-slate-900 flex items-center gap-2 pb-2 border-b border-slate-100">4. 多语言对接代码示例</h2>
<p class="text-sm leading-relaxed text-slate-600">一键复制并直接集成至您的客户端或服务端项目中:</p>
<div class="rounded-xl overflow-hidden bg-slate-50/70 border border-slate-200">
<div class="flex flex-wrap items-center justify-between gap-3 px-4 py-2.5 bg-slate-100/70 border-b border-slate-200/80">
<div class="doc-code-tabs flex items-center gap-1">
<button type="button" class="doc-code-tab active px-2.5 py-1 text-xs font-semibold rounded-md transition-colors bg-white text-slate-800 shadow-xs border border-slate-200/80" data-lang="curl" onclick="switchSnippetTab('curl')">cURL</button>
<button type="button" class="doc-code-tab px-2.5 py-1 text-xs font-medium rounded-md transition-colors text-slate-500 hover:text-slate-800" data-lang="python" onclick="switchSnippetTab('python')">Python</button>
<button type="button" class="doc-code-tab px-2.5 py-1 text-xs font-medium rounded-md transition-colors text-slate-500 hover:text-slate-800" data-lang="js" onclick="switchSnippetTab('js')">Node.js</button>
<button type="button" class="doc-code-tab px-2.5 py-1 text-xs font-medium rounded-md transition-colors text-slate-500 hover:text-slate-800" data-lang="go" onclick="switchSnippetTab('go')">Go</button>
<button type="button" class="doc-code-tab px-2.5 py-1 text-xs font-medium rounded-md transition-colors text-slate-500 hover:text-slate-800" data-lang="php" onclick="switchSnippetTab('php')">PHP</button>
<button type="button" class="doc-code-tab px-2.5 py-1 text-xs font-medium rounded-md transition-colors text-slate-500 hover:text-slate-800" data-lang="java" onclick="switchSnippetTab('java')">Java</button>
</div>
<button type="button" id="copy-snippet-btn" class="inline-flex items-center gap-1.5 px-2.5 py-1 rounded-md text-xs font-medium bg-white hover:bg-slate-50 text-slate-600 hover:text-slate-900 transition-all border border-slate-200 shadow-xs" onclick="copyActiveCodeSnippet()" title="复制代码">
<svg id="copy-snippet-btn-icon" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>
<span id="copy-snippet-btn-text">复制代码</span>
</button>
</div>
<pre id="snippet-code-display" class="p-4 text-xs font-mono text-slate-800 overflow-x-auto leading-relaxed max-h-[420px] custom-scroll bg-slate-50/40"></pre>
</div>
</section>
<!-- 5. 错误码与排障指南 -->
<section id="sec-errors" class="api-doc-section scroll-mt-24 space-y-4">
<h2 class="text-base font-bold text-slate-900 flex items-center gap-2 pb-2 border-b border-slate-100">5. 标准错误码与排错指南</h2>
<p class="text-sm leading-relaxed text-slate-600">当请求处理发生异常时,接口返回 <code class="bg-slate-100 px-1.5 py-0.5 rounded text-xs font-mono">{"succ": false, "code": "...", "message": "..."}</code>:</p>
<div class="overflow-x-auto rounded-lg border border-slate-200 bg-white">
<table class="w-full text-left text-xs border-collapse">
<thead class="bg-slate-50/80 border-b border-slate-200 text-slate-700 font-semibold">
<tr>
<th class="px-3.5 py-3" style="width:100px">HTTP 状态</th>
<th class="px-3.5 py-3" style="width:230px">错误标识 (Code)</th>
<th class="px-3.5 py-3">原因分析与排查指引</th>
</tr>
</thead>
<tbody class="divide-y divide-slate-100 font-normal">
<tr>
<td class="px-3.5 py-2.5"><span class="inline-flex items-center px-1.5 py-0.5 rounded text-xs font-mono font-medium bg-rose-50 text-rose-700 border border-rose-200/60">400</span></td>
<td class="px-3.5 py-2.5"><code class="font-mono text-xs font-semibold text-slate-800 bg-slate-100/90 px-2 py-0.5 rounded border border-slate-200/60">INVALID_TEXT</code></td>
<td class="px-3.5 py-2.5 text-slate-600 leading-relaxed">请求 URL 参数为空,或文案长度超过了 2000 个字符限制。</td>
</tr>
<tr>
<td class="px-3.5 py-2.5"><span class="inline-flex items-center px-1.5 py-0.5 rounded text-xs font-mono font-medium bg-rose-50 text-rose-700 border border-rose-200/60">400</span></td>
<td class="px-3.5 py-2.5"><code class="font-mono text-xs font-semibold text-slate-800 bg-slate-100/90 px-2 py-0.5 rounded border border-slate-200/60">URL_NOT_FOUND</code></td>
<td class="px-3.5 py-2.5 text-slate-600 leading-relaxed">文本中未提取到合法的 http/https 链接,请检查分享文本是否完整。</td>
</tr>
<tr>
<td class="px-3.5 py-2.5"><span class="inline-flex items-center px-1.5 py-0.5 rounded text-xs font-mono font-medium bg-rose-50 text-rose-700 border border-rose-200/60">400</span></td>
<td class="px-3.5 py-2.5"><code class="font-mono text-xs font-semibold text-slate-800 bg-slate-100/90 px-2 py-0.5 rounded border border-slate-200/60">REDIRECT_FAILED</code></td>
<td class="px-3.5 py-2.5 text-slate-600 leading-relaxed">短链接重定向解析失败或网络超时不可达,请检查原链接是否可正常打开。</td>
</tr>
<tr>
<td class="px-3.5 py-2.5"><span class="inline-flex items-center px-1.5 py-0.5 rounded text-xs font-mono font-medium bg-rose-50 text-rose-700 border border-rose-200/60">400</span></td>
<td class="px-3.5 py-2.5"><code class="font-mono text-xs font-semibold text-slate-800 bg-slate-100/90 px-2 py-0.5 rounded border border-slate-200/60">PLATFORM_NOT_SUPPORTED</code></td>
<td class="px-3.5 py-2.5 text-slate-600 leading-relaxed">目标平台域名不在支持列表中。</td>
</tr>
<tr>
<td class="px-3.5 py-2.5"><span class="inline-flex items-center px-1.5 py-0.5 rounded text-xs font-mono font-medium bg-rose-50 text-rose-700 border border-rose-200/60">400</span></td>
<td class="px-3.5 py-2.5"><code class="font-mono text-xs font-semibold text-slate-800 bg-slate-100/90 px-2 py-0.5 rounded border border-slate-200/60">MEDIA_DELETED_OR_PRIVATE</code></td>
<td class="px-3.5 py-2.5 text-slate-600 leading-relaxed">目标内容为私密作品、仅好友可见的日常/动态,或已被作者删除下架。</td>
</tr>
<tr>
<td class="px-3.5 py-2.5"><span class="inline-flex items-center px-1.5 py-0.5 rounded text-xs font-mono font-medium bg-rose-50 text-rose-700 border border-rose-200/60">400</span></td>
<td class="px-3.5 py-2.5"><code class="font-mono text-xs font-semibold text-slate-800 bg-slate-100/90 px-2 py-0.5 rounded border border-slate-200/60">NO_MEDIA_IN_CONTENT</code></td>
<td class="px-3.5 py-2.5 text-slate-600 leading-relaxed">目标分享内容(如 AI 问答对话)仅包含文本,未包含图片或视频多媒体资源。</td>
</tr>
<tr>
<td class="px-3.5 py-2.5"><span class="inline-flex items-center px-1.5 py-0.5 rounded text-xs font-mono font-medium bg-rose-50 text-rose-700 border border-rose-200/60">400</span></td>
<td class="px-3.5 py-2.5"><code class="font-mono text-xs font-semibold text-slate-800 bg-slate-100/90 px-2 py-0.5 rounded border border-slate-200/60">MEDIA_NOT_FOUND</code></td>
<td class="px-3.5 py-2.5 text-slate-600 leading-relaxed">未能从该链接提取到媒体内容,请检查链接有效性或稍后重试。</td>
</tr>
<tr>
<td class="px-3.5 py-2.5"><span class="inline-flex items-center px-1.5 py-0.5 rounded text-xs font-mono font-medium bg-rose-50 text-rose-700 border border-rose-200/60">400</span></td>
<td class="px-3.5 py-2.5"><code class="font-mono text-xs font-semibold text-slate-800 bg-slate-100/90 px-2 py-0.5 rounded border border-slate-200/60">COOKIE_REQUIRED</code></td>
<td class="px-3.5 py-2.5 text-slate-600 leading-relaxed">目标平台需要服务端 Cookie 凭据校验(如小红书 <code class="font-mono text-[11px]">XIAOHONGSHU_COOKIE_REQUIRED</code>、拼多多 <code class="font-mono text-[11px]">PINDUODUO_COOKIE_REQUIRED</code>、微信视频号 <code class="font-mono text-[11px]">WECHAT_CHANNELS_COOKIE_REQUIRED</code> 等)。请在管理后台「系统设置 - Cookie管理」中配置有效凭据。</td>
</tr>
<tr>
<td class="px-3.5 py-2.5"><span class="inline-flex items-center px-1.5 py-0.5 rounded text-xs font-mono font-medium bg-amber-50 text-amber-700 border border-amber-200/60">401</span></td>
<td class="px-3.5 py-2.5"><code class="font-mono text-xs font-semibold text-slate-800 bg-slate-100/90 px-2 py-0.5 rounded border border-slate-200/60">API_KEY_REQUIRED</code></td>
<td class="px-3.5 py-2.5 text-slate-600 leading-relaxed">请求头或查询参数中未提供 API Key 凭证。</td>
</tr>
<tr>
<td class="px-3.5 py-2.5"><span class="inline-flex items-center px-1.5 py-0.5 rounded text-xs font-mono font-medium bg-amber-50 text-amber-700 border border-amber-200/60">401</span></td>
<td class="px-3.5 py-2.5"><code class="font-mono text-xs font-semibold text-slate-800 bg-slate-100/90 px-2 py-0.5 rounded border border-slate-200/60">INVALID_API_KEY</code></td>
<td class="px-3.5 py-2.5 text-slate-600 leading-relaxed">提供的 API Key 不存在或已被删除。</td>
</tr>
<tr>
<td class="px-3.5 py-2.5"><span class="inline-flex items-center px-1.5 py-0.5 rounded text-xs font-mono font-medium bg-amber-50 text-amber-700 border border-amber-200/60">403</span></td>
<td class="px-3.5 py-2.5"><code class="font-mono text-xs font-semibold text-slate-800 bg-slate-100/90 px-2 py-0.5 rounded border border-slate-200/60">API_KEY_DISABLED</code></td>
<td class="px-3.5 py-2.5 text-slate-600 leading-relaxed">该 API Key 或关联的客户账号已被管理员停用。</td>
</tr>
<tr>
<td class="px-3.5 py-2.5"><span class="inline-flex items-center px-1.5 py-0.5 rounded text-xs font-mono font-medium bg-amber-50 text-amber-700 border border-amber-200/60">403</span></td>
<td class="px-3.5 py-2.5"><code class="font-mono text-xs font-semibold text-slate-800 bg-slate-100/90 px-2 py-0.5 rounded border border-slate-200/60">ACCOUNT_EXPIRED</code></td>
<td class="px-3.5 py-2.5 text-slate-600 leading-relaxed">账号使用期限已到期,请联系管理员续期。</td>
</tr>
<tr>
<td class="px-3.5 py-2.5"><span class="inline-flex items-center px-1.5 py-0.5 rounded text-xs font-mono font-medium bg-amber-50 text-amber-700 border border-amber-200/60">402</span></td>
<td class="px-3.5 py-2.5"><code class="font-mono text-xs font-semibold text-slate-800 bg-slate-100/90 px-2 py-0.5 rounded border border-slate-200/60">INSUFFICIENT_CREDITS</code></td>
<td class="px-3.5 py-2.5 text-slate-600 leading-relaxed">账号可用解析积分已耗尽(剩余 0 点),请充值或调整额度。</td>
</tr>
<tr>
<td class="px-3.5 py-2.5"><span class="inline-flex items-center px-1.5 py-0.5 rounded text-xs font-mono font-medium bg-yellow-50 text-yellow-800 border border-yellow-200/60">429</span></td>
<td class="px-3.5 py-2.5"><code class="font-mono text-xs font-semibold text-slate-800 bg-slate-100/90 px-2 py-0.5 rounded border border-slate-200/60">RATE_LIMITED</code></td>
<td class="px-3.5 py-2.5 text-slate-600 leading-relaxed">超出当前账号、API Key 或平台的并发 QPS 阈值,请在客户端增加重试与指数退避。</td>
</tr>
<tr>
<td class="px-3.5 py-2.5"><span class="inline-flex items-center px-1.5 py-0.5 rounded text-xs font-mono font-medium bg-slate-100 text-slate-700 border border-slate-200/60">503</span></td>
<td class="px-3.5 py-2.5"><code class="font-mono text-xs font-semibold text-slate-800 bg-slate-100/90 px-2 py-0.5 rounded border border-slate-200/60">API_DISABLED</code></td>
<td class="px-3.5 py-2.5 text-slate-600 leading-relaxed">系统全局 API 服务或特定平台被管理员临时维护关闭。</td>
</tr>
</tbody>
</table>
</div>
</section>
</article>
<!-- 右侧粘性固定目录 (本页目录) -->
<aside class="hidden lg:block sticky top-24">
<div class="space-y-4">
<div class="text-sm font-semibold text-slate-900 tracking-tight pl-3.5">本页目录</div>
<nav class="space-y-3 border-l border-slate-200/90">
<a href="#sec-auth" class="toc-item block pl-3.5 -ml-[1px] py-0.5 text-xs sm:text-[13px] font-medium text-slate-500 hover:text-slate-900 transition-colors border-l-2 border-transparent leading-relaxed" onclick="smoothScrollToDocs('sec-auth');return false;">接口鉴权机制</a>
<a href="#sec-params" class="toc-item block pl-3.5 -ml-[1px] py-0.5 text-xs sm:text-[13px] font-medium text-slate-500 hover:text-slate-900 transition-colors border-l-2 border-transparent leading-relaxed" onclick="smoothScrollToDocs('sec-params');return false;">请求参数规范</a>
<a href="#sec-schema" class="toc-item block pl-3.5 -ml-[1px] py-0.5 text-xs sm:text-[13px] font-medium text-slate-500 hover:text-slate-900 transition-colors border-l-2 border-transparent leading-relaxed" onclick="smoothScrollToDocs('sec-schema');return false;">返回数据字典</a>
<a href="#sec-snippets" class="toc-item block pl-3.5 -ml-[1px] py-0.5 text-xs sm:text-[13px] font-medium text-slate-500 hover:text-slate-900 transition-colors border-l-2 border-transparent leading-relaxed" onclick="smoothScrollToDocs('sec-snippets');return false;">多语言对接示例</a>
<a href="#sec-errors" class="toc-item block pl-3.5 -ml-[1px] py-0.5 text-xs sm:text-[13px] font-medium text-slate-500 hover:text-slate-900 transition-colors border-l-2 border-transparent leading-relaxed" onclick="smoothScrollToDocs('sec-errors');return false;">标准错误码排障</a>
</nav>
</div>
</aside>
</div>
</div>
</div>
<!-- ==========================================================================
Slide-over 侧滑调试抽屉 (Drawer)
========================================================================== -->
<div id="api-drawer-backdrop" class="fixed inset-0 bg-slate-900/50 backdrop-blur-sm z-50 transition-opacity duration-300 opacity-0 pointer-events-none" onclick="closePlaygroundDrawer()"></div>
<div id="api-drawer" class="fixed inset-y-0 right-0 max-w-xl w-full bg-white shadow-2xl z-50 transform translate-x-full transition-transform duration-300 ease-in-out flex flex-col" role="dialog" aria-modal="true" aria-labelledby="drawer-title">
<div class="flex items-center justify-between px-6 py-4 border-b border-slate-200">
<div class="flex items-center gap-2.5">
<div class="w-8 h-8 rounded-lg bg-brand-50 text-brand-600 flex items-center justify-center border border-brand-200/50">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polygon points="5 3 19 12 5 21 5 3"/></svg>
</div>
<h3 class="text-base font-bold text-slate-900" id="drawer-title">在线接口调试</h3>
</div>
<button type="button" class="w-8 h-8 rounded-lg flex items-center justify-center text-slate-400 hover:text-slate-600 hover:bg-slate-100 transition-colors text-xl leading-none" onclick="closePlaygroundDrawer()" aria-label="关闭抽屉">&times;</button>
</div>
<div class="flex-1 overflow-y-auto p-6 space-y-5 custom-scroll">
<form id="api-playground-form" onsubmit="executePlaygroundRequest(event)" class="space-y-4">
<!-- 待解析链接输入 -->
<div>
<div class="flex items-center justify-between mb-1.5">
<label class="text-xs font-semibold text-slate-700">待解析链接 / 分享文案 <span class="text-rose-500">*</span></label>
</div>
<textarea id="pg-target-url" rows="3"
class="w-full px-3.5 py-2.5 bg-slate-50/50 border border-slate-200 rounded-lg text-xs sm:text-sm text-slate-800 focus:outline-none focus:ring-2 focus:ring-brand-500/20 focus:border-brand-500 transition-colors font-mono break-all leading-relaxed resize-y"
placeholder="粘贴目标作品分享链接或文案 (例如 https://v.douyin.com/...)"
required autocomplete="off" oninput="syncCodeSnippets()"></textarea>
</div>
<!-- 密钥凭证 -->
<div>
<div class="flex items-center justify-between mb-1.5">
<label class="text-xs font-semibold text-slate-700">API Key 凭据</label>
<a href="{{ url_for('admin.keys') if g.user and g.user['role'] == 'admin' else url_for('portal.keys') }}" class="text-xs text-brand-600 hover:text-brand-700 underline">前往密钥管理 ↗</a>
</div>
<div class="flex items-center gap-2">
{% set available_keys = my_keys or (keys if g.user and g.user['role'] != 'admin' else []) %}
{% set first_key = available_keys[0] if available_keys and available_keys|length > 0 else None %}
{% set has_initial_key = (not new_api_key and first_key) %}
<div class="flex-1 flex items-center min-h-[40px] px-3 bg-slate-50/50 border border-slate-200 rounded-lg focus-within:border-brand-500 focus-within:ring-2 focus-within:ring-brand-500/20 transition-all cursor-text" id="pg-key-input-box" onclick="focusApiKeyInput(event)">
<div id="pg-selected-key-chip" class="inline-flex items-center gap-1.5 bg-brand-50 border border-brand-200 text-brand-700 text-xs px-2 py-1 rounded-md max-w-full truncate" style="{% if not has_initial_key %}display:none{% endif %}" data-val="{{ first_key['key'] if first_key else '' }}">
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="text-brand-600 flex-shrink-0"><circle cx="7.5" cy="15.5" r="5.5"/><path d="m21 2-9.6 9.6"/><path d="m15.5 7.5 3 3L22 7l-3-3"/></svg>
<span id="pg-key-chip-name" class="font-medium truncate">{{ first_key['name'] if first_key else '密钥' }}</span>
<span id="pg-key-chip-prefix" class="text-brand-500 font-mono text-[11px]">({{ (first_key['key'][:7] ~ '...') if first_key else '' }})</span>
<button type="button" class="key-chip-remove text-brand-400 hover:text-brand-700 ml-1 text-sm font-bold" onclick="clearSelectedKey(event)" title="移除此 Key" aria-label="移除">&times;</button>
</div>
<input type="text" id="pg-api-key" class="w-full bg-transparent border-0 text-sm text-slate-800 focus:outline-none placeholder-slate-400 font-mono"
placeholder="请输入或选择 API Key"
value="{% if not has_initial_key %}{{ new_api_key or '' }}{% endif %}"
style="{% if has_initial_key %}display:none{% endif %}"
autocomplete="off"
oninput="handleManualKeyInput()"
onkeydown="handleKeyInputKeydown(event)">
</div>
<!-- Custom Dropdown Component for Playground Key Selection -->
<div class="relative" id="pg-key-dropdown-wrap">
<button type="button" class="h-10 px-3 flex items-center gap-1.5 text-xs font-medium bg-white border border-slate-200 hover:bg-slate-50 text-slate-700 rounded-lg shadow-sm transition-colors whitespace-nowrap" id="pg-key-dropdown-btn" onclick="togglePgKeyDropdown(event)" title="选择已有 Key 或前往创建">
<span id="pg-key-dropdown-label">{{ first_key['name'] if has_initial_key else '选择 Key' }}</span>
<svg class="w-3.5 h-3.5 text-slate-400" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
<polyline points="6 9 12 15 18 9"></polyline>
</svg>
</button>
<div class="pg-key-dropdown-menu hidden absolute right-0 mt-1 w-56 bg-white border border-slate-200 rounded-xl shadow-lg z-50 py-1" id="pg-key-dropdown-menu">
<button type="button" class="pg-key-menu-item w-full flex items-center justify-between px-3.5 py-2 text-xs text-left text-slate-700 hover:bg-slate-50 {% if not has_initial_key and not new_api_key %}text-brand-600 font-semibold bg-brand-50/50{% endif %}" data-val="" onclick="handlePgKeyItemSelect('', '手动输入')">
<span class="truncate">未选择 Key (手动输入)</span>
<svg class="pg-key-item-check w-3.5 h-3.5 text-brand-600 {% if not has_initial_key and not new_api_key %}block{% else %}hidden{% endif %}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><polyline points="20 6 9 17 4 12"/></svg>
</button>
{% if available_keys and available_keys|length > 0 %}
{% for k in available_keys %}
{% set is_selected = (new_api_key and k['key'] in new_api_key) or (not new_api_key and loop.first) %}
<button type="button" class="pg-key-menu-item w-full flex items-center justify-between px-3.5 py-2 text-xs text-left text-slate-700 hover:bg-slate-50 {% if is_selected %}text-brand-600 font-semibold bg-brand-50/50{% endif %}" data-val="{{ k['key'] }}" data-name="{{ k['name'] or '密钥' }}" onclick="handlePgKeyItemSelect('{{ k['key'] }}', '{{ k['name'] or '密钥' }}')">
<span class="truncate">{{ k['name'] or '密钥' }} ({{ k['key'][:7] }}...)</span>
<svg class="pg-key-item-check w-3.5 h-3.5 text-brand-600 {% if is_selected %}block{% else %}hidden{% endif %}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><polyline points="20 6 9 17 4 12"/></svg>
</button>
{% endfor %}
<div class="my-1 border-t border-slate-100"></div>
<button type="button" class="w-full flex items-center px-3.5 py-2 text-xs text-left text-brand-600 hover:bg-brand-50/50 font-medium" onclick="handlePgKeyActionCreate()">
<span>+ 创建新 Key / 管理密钥 ↗</span>
</button>
{% else %}
<div class="my-1 border-t border-slate-100"></div>
<button type="button" class="w-full flex items-center px-3.5 py-2 text-xs text-left text-brand-600 hover:bg-brand-50/50 font-medium" onclick="handlePgKeyActionCreate()">
<span>+ 暂无 Key,点击前往创建 ↗</span>
</button>
{% endif %}
</div>
</div>
</div>
</div>
<!-- 传参模式与操作按钮 -->
<div class="flex items-center justify-between flex-wrap gap-3 pt-2">
<div class="flex items-center gap-2 bg-slate-100 p-1 rounded-lg">
<label id="lbl-auth-header" class="flex items-center gap-1.5 px-2.5 py-1 rounded-md text-xs font-medium cursor-pointer transition-all bg-white text-slate-900 shadow-sm">
<input type="radio" name="pg-auth-type" value="header" checked onchange="updateAuthToggleUI('header')" class="sr-only">
<span>Header 模式</span>
</label>
<label id="lbl-auth-query" class="flex items-center gap-1.5 px-2.5 py-1 rounded-md text-xs font-medium cursor-pointer transition-all text-slate-600 hover:text-slate-900">
<input type="radio" name="pg-auth-type" value="query" onchange="updateAuthToggleUI('query')" class="sr-only">
<span>Query 模式</span>
</label>
</div>
<div class="flex items-center gap-2">
<button type="button" class="px-3 py-1.5 text-xs font-medium bg-white hover:bg-slate-50 text-slate-700 border border-slate-200 rounded-lg shadow-sm transition-colors" onclick="resetPlayground()" title="清空并重置">重置</button>
<button type="submit" id="pg-submit-btn" class="inline-flex items-center justify-center gap-1.5 px-4 py-1.5 text-xs font-medium bg-brand-600 hover:bg-brand-700 active:bg-brand-800 text-white rounded-lg shadow-sm shadow-brand-500/20 transition-colors min-w-[100px]">
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polygon points="5 3 19 12 5 21 5 3"/></svg>
<span id="pg-btn-text">发送测试</span>
</button>
</div>
</div>
</form>
<!-- 调试响应结果容器 -->
<div id="pg-result-container" class="space-y-3 pt-3 border-t border-slate-200" style="display:none">
<!-- 智能情境错误排错引导 (In-context Error Alert) -->
<div id="pg-context-alert" class="p-3 bg-amber-50 border border-amber-200 rounded-xl text-amber-800 text-xs flex items-start gap-2.5 leading-relaxed" style="display:none">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="text-amber-600 flex-shrink-0 mt-0.5"><circle cx="12" cy="12" r="10"/><line x1="12" y1="8" x2="12" y2="12"/><line x1="12" y1="16" x2="12.01" y2="16"/></svg>
<div id="pg-context-alert-text" class="flex-1"></div>
</div>
<!-- 响应代码卡片 (现代浅灰轻量风格) -->
<div class="rounded-xl overflow-hidden bg-slate-50/70 border border-slate-200">
<div class="flex items-center justify-between gap-3 px-3.5 py-2.5 bg-slate-100/70 border-b border-slate-200/80">
<div class="flex items-center gap-2 flex-wrap min-w-0">
<div class="flex items-center gap-1.5 text-xs font-semibold text-slate-700 font-mono">
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="text-slate-500"><polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/></svg>
<span>Response</span>
</div>
<span class="text-slate-300">·</span>
<span id="pg-res-status" class="inline-flex items-center gap-1 text-xs font-semibold font-mono text-emerald-600">
<span class="w-1.5 h-1.5 rounded-full bg-emerald-500"></span>200 OK
</span>
<span id="pg-res-platform" class="text-xs font-medium text-slate-600 bg-white px-1.5 py-0.5 rounded border border-slate-200/80 text-[11px]" style="display:none"></span>
<span id="pg-res-time" class="text-xs text-slate-400 font-mono">-- ms</span>
</div>
<button type="button" id="pg-copy-btn" class="inline-flex items-center gap-1.5 px-2.5 py-1 rounded-md text-xs font-medium text-slate-600 hover:text-slate-900 bg-white hover:bg-slate-50 border border-slate-200 transition-all shadow-2xs flex-shrink-0" onclick="copyPlaygroundJson()">
<svg id="pg-copy-btn-icon" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="14" height="14" x="8" y="8" rx="2" ry="2"/><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"/></svg>
<span id="pg-copy-btn-text">复制 JSON</span>
</button>
</div>
<pre id="pg-res-json" class="p-3.5 text-xs font-mono text-slate-800 bg-slate-50/40 overflow-x-auto leading-relaxed max-h-[360px] custom-scroll"></pre>
</div>
</div>
</div>
</div>
<!-- 交互脚本与智能排障字典 -->
<script>
(function() {
let currentLang = 'curl';
// 智能排障建议字典 (In-context Error Help)
const ERROR_TIPS = {
'COOKIE_REQUIRED': '💡 排查建议:该平台(如小红书、拼多多、微信)需要有效登录凭证。请在「系统设置 - Cookie管理」中配置有效 Cookie。',
'INSUFFICIENT_CREDITS': '💡 排查建议:当前账号可用点数已耗尽(剩余 0 点)。请联系系统管理员充值点数或修改额度。',
'EXPIRED_USER': '💡 排查建议:您的账号使用期限已到期。请联系系统超级管理员进行账号延期。',
'ACCOUNT_EXPIRED': '💡 排查建议:您的账号尚未开通或已到期。请联系系统超级管理员进行账号延期。',
'INVALID_KEY': '💡 排查建议:API Key 无效、已被删除或填入了脱敏前缀。出于安全,数据库仅加密存储,请填入创建时保存的完整 32 位 Key。',
'INVALID_API_KEY': '💡 排查建议:API Key 无效或填入了脱敏前缀(含 ...)。出于安全考虑,数据库仅加密存储哈希,无法还原完整明文,请直接粘贴创建密钥时保存的完整 32 位 API Key。',
'API_KEY_REQUIRED': '💡 排查建议:未提供 API Key,请在输入框填入有效的 32 位 API Key。',
'API_KEY_DISABLED': '💡 排查建议:该 API Key 或当前账号已被停用。',
'RATE_LIMITED': '💡 排查建议:超出并发 QPS 阈值。请在客户端降低请求并发度,并添加指数退避重试逻辑。',
'PLATFORM_NOT_SUPPORTED': '💡 排查建议:目标链接所属平台尚未受支持,或属于仅好友可见的私密分享作品。',
'MEDIA_NOT_FOUND': '💡 排查建议:源视频已被删除、作者隐藏,或源平台触发了滑块风控验证。',
'URL_NOT_FOUND': '💡 排查建议:未能在输入文本中检测到合法 http/https 链接,请检查文本是否粘贴完整。',
'INVALID_TEXT': '💡 排查建议:待解析链接内容为空,或文案长度超过了 2000 个字符限制。',
'API_DISABLED': '💡 排查建议:系统全局 API 目前处于维护关闭状态,请稍后再试或联系管理员。'
};
window.openPlaygroundDrawer = function() {
const drawer = document.getElementById('api-drawer');
const backdrop = document.getElementById('api-drawer-backdrop');
if (drawer && backdrop) {
drawer.classList.remove('translate-x-full');
drawer.classList.add('translate-x-0');
backdrop.classList.remove('opacity-0', 'pointer-events-none');
backdrop.classList.add('opacity-100', 'pointer-events-auto');
document.body.style.overflow = 'hidden';
const input = document.getElementById('pg-target-url');
if (input) setTimeout(() => input.focus(), 150);
}
};
window.closePlaygroundDrawer = function() {
const drawer = document.getElementById('api-drawer');
const backdrop = document.getElementById('api-drawer-backdrop');
if (drawer && backdrop) {
drawer.classList.remove('translate-x-0');
drawer.classList.add('translate-x-full');
backdrop.classList.remove('opacity-100', 'pointer-events-auto');
backdrop.classList.add('opacity-0', 'pointer-events-none');
document.body.style.overflow = '';
}
};
// ESC 键关闭抽屉
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape') {
closePlaygroundDrawer();
}
});
window.smoothScrollToDocs = function(elementId) {
const el = document.getElementById(elementId);
if (el) {
el.scrollIntoView({ behavior: 'smooth' });
}
};
function initDocScrollSpy() {
const sectionIds = ['sec-auth', 'sec-params', 'sec-schema', 'sec-snippets', 'sec-errors'];
const links = document.querySelectorAll('.toc-item');
if (!links.length) return;
function updateSpy() {
const scrollY = window.pageYOffset || document.documentElement.scrollTop;
const topbar = document.querySelector('header');
const topbarHeight = topbar ? topbar.offsetHeight : 64;
const triggerOffset = topbarHeight + 60;
let activeId = sectionIds[0];
for (let i = 0; i < sectionIds.length; i++) {
const sec = document.getElementById(sectionIds[i]);
if (sec) {
const top = sec.getBoundingClientRect().top + scrollY - triggerOffset;
if (scrollY >= top) {
activeId = sectionIds[i];
}
}
}
links.forEach(link => {
const href = link.getAttribute('href') || '';
if (href === '#' + activeId) {
link.classList.add('border-brand-600', 'text-slate-900', 'font-semibold');
link.classList.remove('border-transparent', 'text-slate-500');
} else {
link.classList.remove('border-brand-600', 'text-slate-900', 'font-semibold');
link.classList.add('border-transparent', 'text-slate-500');
}
});
}
window.addEventListener('scroll', updateSpy, { passive: true });
window.addEventListener('resize', updateSpy, { passive: true });
setTimeout(updateSpy, 100);
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initDocScrollSpy);
} else {
initDocScrollSpy();
}
window.copyText = function(text, successMsg) {
navigator.clipboard.writeText(text).then(() => {
if (typeof showToast === 'function') {
showToast(successMsg || '已复制到剪贴板', 'success');
}
});
};
window.updateAuthToggleUI = function(mode) {
const lblHeader = document.getElementById('lbl-auth-header');
const lblQuery = document.getElementById('lbl-auth-query');
if (mode === 'header') {
if (lblHeader) {
lblHeader.className = 'flex items-center gap-1.5 px-2.5 py-1 rounded-md text-xs font-medium cursor-pointer transition-all bg-white text-slate-900 shadow-sm';
}
if (lblQuery) {
lblQuery.className = 'flex items-center gap-1.5 px-2.5 py-1 rounded-md text-xs font-medium cursor-pointer transition-all text-slate-600 hover:text-slate-900';
}
} else {
if (lblHeader) {
lblHeader.className = 'flex items-center gap-1.5 px-2.5 py-1 rounded-md text-xs font-medium cursor-pointer transition-all text-slate-600 hover:text-slate-900';
}
if (lblQuery) {
lblQuery.className = 'flex items-center gap-1.5 px-2.5 py-1 rounded-md text-xs font-medium cursor-pointer transition-all bg-white text-slate-900 shadow-sm';
}
}
syncCodeSnippets();
};
window.fillPlaygroundUrl = function(url) {
const input = document.getElementById('pg-target-url');
if (input) {
input.value = url;
syncCodeSnippets();
input.focus();
}
};
function getBaseUrl() {
return (window.location.origin || '').replace(/\/$/, '') + '/';
}
window.goToKeyManagement = function() {
closePlaygroundDrawer();
window.location.href = "{{ url_for('admin.keys') if g.user and g.user['role'] == 'admin' else url_for('portal.keys') }}";
};
window.focusApiKeyInput = function(e) {
if (e && e.target && (e.target.classList.contains('key-chip-remove') || e.target.closest('.key-chip-remove'))) return;
const input = document.getElementById('pg-api-key');
if (input && input.style.display !== 'none') input.focus();
};
window.togglePgKeyDropdown = function(e) {
if (e) {
e.preventDefault();
e.stopPropagation();
}
const menu = document.getElementById('pg-key-dropdown-menu');
if (menu) {
menu.classList.toggle('hidden');
}
};
window.closePgKeyDropdown = function() {
const menu = document.getElementById('pg-key-dropdown-menu');
if (menu) {
menu.classList.add('hidden');
}
};
window.handlePgKeyItemSelect = function(val, name) {
closePgKeyDropdown();
if (!val) {
clearSelectedKey();
return;
}
applySelectedKey(val, name);
};
window.handlePgKeyActionCreate = function() {
closePgKeyDropdown();
goToKeyManagement();
};
window.applySelectedKey = function(fullKey, name) {
const chip = document.getElementById('pg-selected-key-chip');
const chipName = document.getElementById('pg-key-chip-name');
const chipPrefix = document.getElementById('pg-key-chip-prefix');
const input = document.getElementById('pg-api-key');
const label = document.getElementById('pg-key-dropdown-label');
const displayPrefix = fullKey ? (fullKey.length > 10 ? fullKey.substring(0, 7) + '...' : fullKey) : '';
if (chipName) chipName.textContent = name || '密钥';
if (chipPrefix) chipPrefix.textContent = '(' + displayPrefix + ')';
if (chip) {
chip.dataset.val = fullKey;
chip.style.display = 'inline-flex';
}
if (input) {
input.value = fullKey;
input.style.display = 'none';
}
if (label) {
label.textContent = name || '密钥';
}
document.querySelectorAll('#pg-key-dropdown-menu .pg-key-menu-item').forEach(item => {
const check = item.querySelector('.pg-key-item-check');
if (item.dataset.val === fullKey) {
item.classList.add('text-brand-600', 'font-semibold', 'bg-brand-50/50');
if (check) check.classList.remove('hidden');
} else {
item.classList.remove('text-brand-600', 'font-semibold', 'bg-brand-50/50');
if (check) check.classList.add('hidden');
}
});
syncCodeSnippets();
};
window.clearSelectedKey = function(e) {
if (e) e.stopPropagation();
const chip = document.getElementById('pg-selected-key-chip');
const input = document.getElementById('pg-api-key');
const label = document.getElementById('pg-key-dropdown-label');
if (chip) {
chip.style.display = 'none';
chip.dataset.val = '';
}
if (input) {
input.style.display = 'block';
input.value = '';
input.placeholder = '请输入或选择 API Key';
input.focus();
}
if (label) {
label.textContent = '选择 Key';
}
document.querySelectorAll('#pg-key-dropdown-menu .pg-key-menu-item').forEach(item => {
const check = item.querySelector('.pg-key-item-check');
if (!item.dataset.val) {
item.classList.add('text-brand-600', 'font-semibold', 'bg-brand-50/50');
if (check) check.classList.remove('hidden');
} else {
item.classList.remove('text-brand-600', 'font-semibold', 'bg-brand-50/50');
if (check) check.classList.add('hidden');
}
});
syncCodeSnippets();
};
window.handleManualKeyInput = function() {
const chip = document.getElementById('pg-selected-key-chip');
const label = document.getElementById('pg-key-dropdown-label');
if (chip && chip.style.display !== 'none') {
chip.style.display = 'none';
chip.dataset.val = '';
}
if (label) {
label.textContent = '选择 Key';
}
document.querySelectorAll('#pg-key-dropdown-menu .pg-key-menu-item').forEach(item => {
const check = item.querySelector('.pg-key-item-check');
if (!item.dataset.val) {
item.classList.add('text-brand-600', 'font-semibold', 'bg-brand-50/50');
if (check) check.classList.remove('hidden');
} else {
item.classList.remove('text-brand-600', 'font-semibold', 'bg-brand-50/50');
if (check) check.classList.add('hidden');
}
});
syncCodeSnippets();
};
window.handleKeyInputKeydown = function(e) {
const chip = document.getElementById('pg-selected-key-chip');
if ((e.key === 'Backspace' || e.key === 'Delete') && chip && chip.style.display !== 'none') {
e.preventDefault();
clearSelectedKey();
}
};
document.addEventListener('click', function(e) {
const wrap = document.getElementById('pg-key-dropdown-wrap');
const menu = document.getElementById('pg-key-dropdown-menu');
if (wrap && menu && !menu.classList.contains('hidden') && !wrap.contains(e.target)) {
menu.classList.add('hidden');
}
});
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape') {
closePgKeyDropdown();
}
});
window.resetPlayground = function() {
const urlInput = document.getElementById('pg-target-url');
if (urlInput) urlInput.value = '';
clearSelectedKey();
const resBox = document.getElementById('pg-result-container');
if (resBox) resBox.style.display = 'none';
};
function getPlaygroundValues() {
const urlInput = document.getElementById('pg-target-url');
const keyInput = document.getElementById('pg-api-key');
const chip = document.getElementById('pg-selected-key-chip');
const authRadio = document.querySelector('input[name="pg-auth-type"]:checked');
const rawUrl = (urlInput ? urlInput.value : '').trim() || 'https://v.douyin.com/xxx/';
const rawKey = (chip && chip.style.display !== 'none' ? (chip.dataset.val || (keyInput ? keyInput.value : '')) : (keyInput ? keyInput.value : '')).trim() || 'mp-xxxxxxxxxxxxxxxx';
const authType = authRadio ? authRadio.value : 'header';
return { rawUrl, rawKey, authType, baseUrl: getBaseUrl() };
}
window.switchSnippetTab = function(lang) {
currentLang = lang;
document.querySelectorAll('.doc-code-tabs .doc-code-tab').forEach(tab => {
if (tab.dataset.lang === lang) {
tab.className = 'doc-code-tab active px-2.5 py-1 text-xs font-semibold rounded-md transition-colors bg-white text-slate-800 shadow-xs border border-slate-200/80';
} else {
tab.className = 'doc-code-tab px-2.5 py-1 text-xs font-medium rounded-md transition-colors text-slate-500 hover:text-slate-800';
}
});
syncCodeSnippets();
};
window.syncCodeSnippets = function() {
const { rawUrl, rawKey, authType, baseUrl } = getPlaygroundValues();
const endpoint = baseUrl + 'api/v1/parse';
const display = document.getElementById('snippet-code-display');
if (!display) return;
let code = '';
if (currentLang === 'curl') {
if (authType === 'header') {
code = `curl -X GET '${endpoint}?url=${encodeURIComponent(rawUrl)}' \\\n -H 'Authorization: Bearer ${rawKey}'`;
} else {
code = `curl -X GET '${endpoint}?key=${encodeURIComponent(rawKey)}&url=${encodeURIComponent(rawUrl)}'`;
}
} else if (currentLang === 'python') {
if (authType === 'header') {
code = `import requests
url = "${endpoint}"
headers = {
"Authorization": "Bearer ${rawKey}"
}
params = {
"url": "${rawUrl}"
}
response = requests.get(url, headers=headers, params=params, timeout=15)
data = response.json()
if data.get("succ"):
print("解析成功:", data["data"]["title"])
print("视频直链:", data["data"].get("video_url"))
else:
print(f"解析失败 [{data.get('code')}]: {data.get('message')}")`;
} else {
code = `import requests
url = "${endpoint}"
params = {
"key": "${rawKey}",
"url": "${rawUrl}"
}
response = requests.get(url, params=params, timeout=15)
data = response.json()
print(data)`;
}
} else if (currentLang === 'js') {
if (authType === 'header') {
code = `// Node.js (Fetch API) / 现代浏览器
const targetUrl = encodeURIComponent("${rawUrl}");
const apiUrl = "${endpoint}?url=" + targetUrl;
async function parseMedia() {
try {
const res = await fetch(apiUrl, {
method: "GET",
headers: {
"Authorization": "Bearer ${rawKey}"
}
});
const result = await res.json();
if (result.succ) {
console.log("解析成功:", result.data.title);
console.log("视频地址:", result.data.video_url);
} else {
console.error("解析失败:", result.message);
}
} catch (err) {
console.error("请求异常:", err);
}
}
parseMedia();`;
} else {
code = `// Query 参数写法
const params = new URLSearchParams({
key: "${rawKey}",
url: "${rawUrl}"
});
fetch(\`${endpoint}?\${params.toString()}\`)
.then(res => res.json())
.then(data => console.log(data))
.catch(err => console.error(err));`;
}
} else if (currentLang === 'go') {
code = `package main
import (
"encoding/json"
"fmt"
"io"
"net/http"
"net/url"
"time"
)
func main() {
baseURL := "${endpoint}"
targetURL := "${rawUrl}"
apiKey := "${rawKey}"
params := url.Values{}
params.Add("url", targetURL)
req, err := http.NewRequest("GET", baseURL+"?"+params.Encode(), nil)
if err != nil {
panic(err)
}
req.Header.Set("Authorization", "Bearer "+apiKey)
client := &http.Client{Timeout: 15 * time.Second}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}`;
} else if (currentLang === 'php') {
code = `<?php
$apiUrl = "${endpoint}";
$apiKey = "${rawKey}";
$targetUrl = "${rawUrl}";
$ch = curl_init();
$query = http_build_query(['url' => $targetUrl]);
curl_setopt($ch, CURLOPT_URL, $apiUrl . '?' . $query);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $apiKey
]);
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response, true);
if (!empty($data['succ'])) {
echo "标题: " . $data['data']['title'] . PHP_EOL;
echo "视频直链: " . $data['data']['video_url'] . PHP_EOL;
} else {
echo "错误: " . ($data['message'] ?? '未知错误') . PHP_EOL;
}`;
} else if (currentLang === 'java') {
code = `import java.net.URI;
import java.net.URLEncoder;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
public class MediaParserDemo {
public static void main(String[] args) throws Exception {
String baseUrl = "${endpoint}";
String targetUrl = "${rawUrl}";
String apiKey = "${rawKey}";
String fullUrl = baseUrl + "?url=" + URLEncoder.encode(targetUrl, StandardCharsets.UTF_8);
HttpClient client = HttpClient.newBuilder()
.connectTimeout(Duration.ofSeconds(10))
.build();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(fullUrl))
.header("Authorization", "Bearer " + apiKey)
.GET()
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println("Status: " + response.statusCode());
System.out.println("Body: " + response.body());
}
}`;
}
window._activeSnippetRawCode = code;
display.innerHTML = highlightSyntax(code, currentLang);
};
function highlightSyntax(raw, lang) {
if (!raw) return '';
let escaped = raw
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;');
const tokens = [];
const stash = (html) => {
const idx = tokens.length;
tokens.push(html);
return `___TOKEN_${idx}___`;
};
// 1. Comments
escaped = escaped.replace(/(^|[^\\])(\/\/[^\n]*|#[^\n]*)/gm, (match, prefix, comment) => {
return prefix + stash(`<span class="hl-cmt">${comment}</span>`);
});
// 2. Strings
escaped = escaped.replace(/("(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|`[^`]*`)/g, (str) => {
return stash(`<span class="hl-str">${str}</span>`);
});
// 3. Keywords & Builtins
if (lang === 'curl') {
escaped = escaped.replace(/\b(curl)\b/g, '<span class="hl-cmd">$1</span>')
.replace(/(-X|-H|-d|--data|--header)\b/g, '<span class="hl-kw">$1</span>')
.replace(/\b(GET|POST|PUT|DELETE|Bearer)\b/g, '<span class="hl-type">$1</span>');
} else {
const kwRegex = /\b(import|from|const|let|var|function|async|await|if|else|return|public|class|static|void|package|defer|panic|try|catch|new|throws|print|echo|def|as|export|default|switch|case|break)\b/g;
escaped = escaped.replace(kwRegex, '<span class="hl-kw">$1</span>');
const typeRegex = /\b(String|HttpClient|HttpRequest|HttpResponse|URI|URLEncoder|Duration|StandardCharsets|Exception|URLSearchParams|JSON|response|requests|time|http|url|io|fmt|json|int|bool|error|true|false|null|nil|Array)\b/g;
escaped = escaped.replace(typeRegex, '<span class="hl-type">$1</span>');
}
// Restore stashed tokens
for (let i = 0; i < tokens.length; i++) {
escaped = escaped.replace(`___TOKEN_${i}___`, tokens[i]);
}
return escaped;
}
window.copyActiveCodeSnippet = function() {
const rawCode = window._activeSnippetRawCode || document.getElementById('snippet-code-display')?.textContent || '';
const btn = document.getElementById('copy-snippet-btn');
const btnText = document.getElementById('copy-snippet-btn-text');
const btnIcon = document.getElementById('copy-snippet-btn-icon');
if (!rawCode) return;
navigator.clipboard.writeText(rawCode).then(() => {
if (btn && btnText) {
const oldText = btnText.textContent;
const oldClass = btn.className;
btn.className = 'inline-flex items-center gap-1.5 px-2.5 py-1 rounded-md text-xs font-medium text-emerald-700 bg-emerald-50 border border-emerald-300 shadow-xs transition-all';
btnText.textContent = '已复制!';
if (btnIcon) {
btnIcon.innerHTML = '<polyline points="20 6 9 17 4 12" stroke-width="2.5"></polyline>';
}
setTimeout(() => {
btn.className = oldClass;
btnText.textContent = oldText;
if (btnIcon) {
btnIcon.innerHTML = '<rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/>';
}
}, 2000);
}
});
};
function highlightJson(json) {
if (typeof json !== 'string') {
json = JSON.stringify(json, null, 2);
}
return json
.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;')
.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
let cls = 'hl-num';
if (/^"/.test(match)) {
if (/:$/.test(match)) {
cls = 'hl-type';
} else {
cls = 'hl-str';
}
} else if (/true|false/.test(match)) {
cls = 'hl-kw';
} else if (/null/.test(match)) {
cls = 'hl-cmt';
}
return '<span class="' + cls + '">' + match + '</span>';
});
}
window.copyPlaygroundJson = function() {
const rawJson = window._lastPlaygroundRawJson || document.getElementById('pg-res-json')?.textContent || '';
if (!rawJson) return;
const btn = document.getElementById('pg-copy-btn');
const btnIcon = document.getElementById('pg-copy-btn-icon');
const btnText = document.getElementById('pg-copy-btn-text');
navigator.clipboard.writeText(rawJson).then(() => {
if (btn && btnText) {
const oldText = btnText.textContent;
const oldClass = btn.className;
btn.className = 'inline-flex items-center gap-1.5 px-2.5 py-1 rounded-md text-xs font-medium text-emerald-700 bg-emerald-50 border border-emerald-300 shadow-2xs transition-all';
btnText.textContent = '已复制!';
if (btnIcon) {
btnIcon.innerHTML = '<polyline points="20 6 9 17 4 12" stroke-width="2.5"></polyline>';
}
setTimeout(() => {
btn.className = oldClass;
btnText.textContent = oldText;
if (btnIcon) {
btnIcon.innerHTML = '<rect width="14" height="14" x="8" y="8" rx="2" ry="2"/><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"/>';
}
}, 2000);
}
});
};
window.executePlaygroundRequest = async function(e) {
if (e) e.preventDefault();
const { rawUrl, rawKey, authType } = getPlaygroundValues();
if (!rawUrl) {
if (typeof showToast === 'function') showToast('请提供待解析链接', 'warning');
return;
}
const btn = document.getElementById('pg-submit-btn');
const btnText = document.getElementById('pg-btn-text');
const resBox = document.getElementById('pg-result-container');
const resStatus = document.getElementById('pg-res-status');
const resTime = document.getElementById('pg-res-time');
const resPlatform = document.getElementById('pg-res-platform');
const resJson = document.getElementById('pg-res-json');
const alertBox = document.getElementById('pg-context-alert');
const alertText = document.getElementById('pg-context-alert-text');
if (btn) btn.disabled = true;
if (btnText) btnText.textContent = '请求中...';
let targetRequestUrl = '/api/v1/parse?url=' + encodeURIComponent(rawUrl);
const headers = {};
if (rawKey) {
if (authType === 'header') {
headers['Authorization'] = 'Bearer ' + rawKey;
} else {
targetRequestUrl += '&key=' + encodeURIComponent(rawKey);
}
}
const startTime = performance.now();
try {
const resp = await fetch(targetRequestUrl, {
method: 'GET',
headers: headers
});
const elapsed = Math.round(performance.now() - startTime);
const status = resp.status;
const data = await resp.json().catch(() => null);
window._lastPlaygroundRawJson = JSON.stringify(data, null, 2);
if (resBox) resBox.style.display = 'block';
if (resTime) resTime.textContent = elapsed + ' ms';
if (resStatus) {
const isSucc = status === 200 && data && data.succ;
resStatus.className = 'inline-flex items-center gap-1 text-xs font-semibold font-mono ' +
(isSucc ? 'text-emerald-600' : 'text-rose-600');
resStatus.innerHTML = `<span class="w-1.5 h-1.5 rounded-full ${isSucc ? 'bg-emerald-500' : 'bg-rose-500'}"></span>` + (status === 200 && data && data.succ ? '200 OK' : 'HTTP ' + status);
}
if (resJson) {
resJson.innerHTML = highlightJson(data || {});
}
// 智能情境错误提示检查 (In-context Error Alert)
if (alertBox && alertText) {
const errorCode = (data && (data.error_code || data.code)) ? String(data.error_code || data.code) : '';
if (errorCode && ERROR_TIPS[errorCode]) {
alertText.textContent = ERROR_TIPS[errorCode];
alertBox.style.display = 'flex';
} else if (!data || !data.succ) {
alertText.textContent = '💡 提示:' + ((data && (data.retdesc || data.message)) ? (data.retdesc || data.message) : '接口请求未能成功完成');
alertBox.style.display = 'flex';
} else {
alertBox.style.display = 'none';
}
}
if (data && data.succ) {
if (resPlatform && data.data) {
resPlatform.textContent = data.data.platform || '已解析';
resPlatform.style.display = 'inline-block';
}
if (typeof showToast === 'function') {
showToast('解析成功!耗时 ' + elapsed + 'ms', 'success');
}
} else {
if (resPlatform) resPlatform.style.display = 'none';
if (typeof showToast === 'function') {
showToast('请求失败: ' + (data && (data.retdesc || data.message) ? (data.retdesc || data.message) : 'HTTP ' + status), 'error');
}
}
} catch (err) {
const elapsed = Math.round(performance.now() - startTime);
if (resBox) resBox.style.display = 'block';
if (resStatus) {
resStatus.className = 'inline-flex items-center gap-1 text-xs font-semibold font-mono text-rose-600';
resStatus.innerHTML = '<span class="w-1.5 h-1.5 rounded-full bg-rose-500"></span>网络异常';
}
if (resTime) resTime.textContent = elapsed + ' ms';
if (resJson) resJson.textContent = 'Client Network Error: ' + (err.message || err);
if (alertBox) alertBox.style.display = 'none';
if (typeof showToast === 'function') showToast('请求发生网络异常', 'error');
} finally {
if (btn) btn.disabled = false;
if (btnText) btnText.textContent = '发送测试';
}
};
// 监听 Ctrl+Enter / Cmd+Enter 快速提交
document.addEventListener('keydown', function(e) {
if ((e.ctrlKey || e.metaKey) && e.key === 'Enter') {
const targetInput = document.getElementById('pg-target-url');
if (targetInput && document.activeElement === targetInput) {
e.preventDefault();
executePlaygroundRequest();
}
}
});
// 初始化代码示例
document.addEventListener('DOMContentLoaded', () => {
syncCodeSnippets();
});
setTimeout(syncCodeSnippets, 50);
})();
</script>