745 lines
29 KiB
Python
745 lines
29 KiB
Python
import json
|
|||
|
|
import re
|
||
|
|
import subprocess
|
||
|
|
|
||
|
|
with open("scratch/unified_docs_data.json") as f:
|
||
|
|
unified_data = json.load(f)
|
||
|
|
|
||
|
|
# Read current HTML
|
||
|
|
with open("web/docs/index.html") as f:
|
||
|
|
orig_html = f.read()
|
||
|
|
|
||
|
|
# Extract head/styles
|
||
|
|
head_part = orig_html.split('<style>')[0]
|
||
|
|
style_part = orig_html.split('<style>')[1].split('</style>')[0]
|
||
|
|
|
||
|
|
# Extra styles
|
||
|
|
extra_styles = """
|
||
|
|
/* ─── API Key & Endpoints Tabs Styling ─── */
|
||
|
|
.m-MULTI { background: #EAE6FE; color: #5B21B6; border-color: #DDD6FE; font-weight: 700; }
|
||
|
|
[data-theme=dark] .m-MULTI { background: #3B1B68; color: #DDD6FE; border-color: #6D28D9; }
|
||
|
|
.ep-key-badge { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--ink3); }
|
||
|
|
.ep-count-tag { font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--soft); border: 1px solid var(--line); color: var(--ink2); margin-left: 8px; }
|
||
|
|
|
||
|
|
.ep-full-url-bar {
|
||
|
|
display: flex;
|
||
|
|
align-items: center;
|
||
|
|
gap: 12px;
|
||
|
|
background: var(--soft);
|
||
|
|
border: 1px solid var(--line);
|
||
|
|
border-radius: 12px;
|
||
|
|
padding: 10px 16px;
|
||
|
|
margin: 14px 0 20px 0;
|
||
|
|
flex-wrap: wrap;
|
||
|
|
}
|
||
|
|
.ep-full-url-bar code {
|
||
|
|
font-family: var(--mono);
|
||
|
|
font-size: 13.5px;
|
||
|
|
color: var(--acc);
|
||
|
|
word-break: break-all;
|
||
|
|
flex: 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
.ep-tabs-wrapper {
|
||
|
|
margin: 12px 0 22px 0;
|
||
|
|
padding-bottom: 14px;
|
||
|
|
border-bottom: 1px solid var(--line);
|
||
|
|
}
|
||
|
|
.ep-tabs-label {
|
||
|
|
font-size: 11.5px;
|
||
|
|
font-weight: 700;
|
||
|
|
letter-spacing: 0.06em;
|
||
|
|
text-transform: uppercase;
|
||
|
|
color: var(--ink3);
|
||
|
|
margin-bottom: 10px;
|
||
|
|
display: block;
|
||
|
|
}
|
||
|
|
.ep-tabs {
|
||
|
|
display: flex;
|
||
|
|
gap: 8px;
|
||
|
|
flex-wrap: wrap;
|
||
|
|
}
|
||
|
|
.ep-tab {
|
||
|
|
padding: 8px 14px;
|
||
|
|
border-radius: 10px;
|
||
|
|
background: var(--soft);
|
||
|
|
border: 1px solid var(--line);
|
||
|
|
font-family: var(--sans);
|
||
|
|
font-size: 13px;
|
||
|
|
font-weight: 600;
|
||
|
|
color: var(--ink2);
|
||
|
|
cursor: pointer;
|
||
|
|
display: inline-flex;
|
||
|
|
align-items: center;
|
||
|
|
gap: 8px;
|
||
|
|
transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.15s;
|
||
|
|
}
|
||
|
|
.ep-tab:hover {
|
||
|
|
border-color: var(--acc);
|
||
|
|
color: var(--ink);
|
||
|
|
transform: translateY(-1px);
|
||
|
|
}
|
||
|
|
.ep-tab.active {
|
||
|
|
background: var(--card);
|
||
|
|
border-color: var(--acc);
|
||
|
|
color: var(--acc);
|
||
|
|
box-shadow: 0 2px 10px rgba(0,0,0,0.06);
|
||
|
|
}
|
||
|
|
.ep-tab .m { padding: 3px 7px; font-size: 11px; }
|
||
|
|
|
||
|
|
/* ─── Preset Chips & Copying ─── */
|
||
|
|
.chip {
|
||
|
|
font: 400 13px var(--mono);
|
||
|
|
padding: 6px 12px;
|
||
|
|
border-radius: 8px;
|
||
|
|
background: var(--soft);
|
||
|
|
border: 1px solid var(--line);
|
||
|
|
color: var(--ink2);
|
||
|
|
cursor: pointer;
|
||
|
|
transition: background 0.15s, border-color 0.15s, transform 0.15s, color 0.15s, box-shadow 0.15s;
|
||
|
|
user-select: none;
|
||
|
|
position: relative;
|
||
|
|
}
|
||
|
|
.chip:hover {
|
||
|
|
border-color: var(--acc);
|
||
|
|
color: var(--ink);
|
||
|
|
transform: translateY(-1px);
|
||
|
|
box-shadow: 0 2px 6px rgba(0,0,0,0.06);
|
||
|
|
}
|
||
|
|
.chip:active {
|
||
|
|
transform: scale(0.96);
|
||
|
|
}
|
||
|
|
.chip.copied {
|
||
|
|
background: #10b981 !important;
|
||
|
|
border-color: #059669 !important;
|
||
|
|
color: #ffffff !important;
|
||
|
|
box-shadow: 0 0 12px rgba(16, 185, 129, 0.45);
|
||
|
|
transform: scale(1.05);
|
||
|
|
}
|
||
|
|
.chip.sel {
|
||
|
|
background: var(--tint);
|
||
|
|
border-color: var(--acc);
|
||
|
|
color: var(--ink);
|
||
|
|
font-weight: 600;
|
||
|
|
}
|
||
|
|
.chips-hint {
|
||
|
|
margin: 6px 0 10px 0;
|
||
|
|
font-size: 12.5px;
|
||
|
|
color: var(--ink3);
|
||
|
|
display: flex;
|
||
|
|
align-items: center;
|
||
|
|
gap: 6px;
|
||
|
|
}
|
||
|
|
.chips-hint b { color: var(--ink); font-weight: 600; }
|
||
|
|
|
||
|
|
.pr-tools {
|
||
|
|
display: flex;
|
||
|
|
gap: 8px;
|
||
|
|
flex-wrap: wrap;
|
||
|
|
align-items: center;
|
||
|
|
margin-bottom: 10px;
|
||
|
|
}
|
||
|
|
.pr-tools input {
|
||
|
|
flex: 1;
|
||
|
|
min-width: 170px;
|
||
|
|
padding: 8px 12px;
|
||
|
|
border: 1px solid var(--line);
|
||
|
|
border-radius: 9px;
|
||
|
|
background: var(--soft);
|
||
|
|
font: inherit;
|
||
|
|
font-size: 13px;
|
||
|
|
color: var(--ink);
|
||
|
|
}
|
||
|
|
.pr-tools .btn {
|
||
|
|
padding: 7px 12px;
|
||
|
|
font-size: 12.5px;
|
||
|
|
display: inline-flex;
|
||
|
|
align-items: center;
|
||
|
|
gap: 6px;
|
||
|
|
}
|
||
|
|
.btn-primary {
|
||
|
|
background: var(--ink);
|
||
|
|
color: var(--paper);
|
||
|
|
border-color: var(--ink);
|
||
|
|
}
|
||
|
|
.btn-primary:hover {
|
||
|
|
background: var(--ink2);
|
||
|
|
border-color: var(--ink2);
|
||
|
|
}
|
||
|
|
[data-theme=dark] .btn-primary {
|
||
|
|
background: #ffffff;
|
||
|
|
color: #0f0e0b;
|
||
|
|
border-color: #ffffff;
|
||
|
|
}
|
||
|
|
|
||
|
|
.multi-select-toggle {
|
||
|
|
display: inline-flex;
|
||
|
|
align-items: center;
|
||
|
|
gap: 6px;
|
||
|
|
font-size: 12px;
|
||
|
|
color: var(--ink2);
|
||
|
|
cursor: pointer;
|
||
|
|
padding: 5px 9px;
|
||
|
|
border-radius: 7px;
|
||
|
|
border: 1px solid var(--line);
|
||
|
|
background: var(--soft);
|
||
|
|
user-select: none;
|
||
|
|
}
|
||
|
|
.multi-select-toggle input { cursor: pointer; }
|
||
|
|
"""
|
||
|
|
|
||
|
|
new_style = style_part + extra_styles
|
||
|
|
|
||
|
|
# Raw JS code
|
||
|
|
js_code = r"""
|
||
|
|
(()=>{
|
||
|
|
const $=(s,r=document)=>r.querySelector(s),$$=(s,r=document)=>[...r.querySelectorAll(s)];
|
||
|
|
const esc=s=>String(s??'').replace(/[&<>"']/g,c=>({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]));
|
||
|
|
let D=JSON.parse($('#api-data').textContent);
|
||
|
|
const open=new Set();let toastT;
|
||
|
|
|
||
|
|
// Snippets generator using actual full URL
|
||
|
|
const meaningful=v=>v&&!/^(none|null|-|—)/i.test(v.trim());
|
||
|
|
const clean=v=>v.replace(/^['"]|['"]$/g,'');
|
||
|
|
|
||
|
|
function fields(ep){
|
||
|
|
let used=false;
|
||
|
|
return ep.params.filter(p=>p.rq).map(p=>{
|
||
|
|
const file=/file|binary/i.test(p.ty);let v;
|
||
|
|
if(file)v=(p.n||'file')+'.jpg';
|
||
|
|
else if(meaningful(p.df)&&!/auto/i.test(p.df))v=clean(p.df);
|
||
|
|
else if(!used&&ep.chips.length&&/id$/i.test(p.n)){v=ep.chips[0];used=true}
|
||
|
|
else v='<'+p.n+'>';
|
||
|
|
return{n:p.n,file,v,q:/query/i.test(p.lc)};
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
function snippets(ep){
|
||
|
|
const url=ep.full_url || ep.path;
|
||
|
|
const f=fields(ep),isImg=/image|video|audio/.test(ep.resp);
|
||
|
|
const q=f.filter(x=>x.q),b=f.filter(x=>!x.q),qs=q.length?'?'+q.map(x=>x.n+'='+encodeURIComponent(x.v)).join('&'):'';
|
||
|
|
const omitted=ep.params.length-f.length;
|
||
|
|
|
||
|
|
let curl=`curl -X ${ep.method} "${url}${qs}"`+b.map(x=>` \\\n -F "${x.n}=${x.file?'@':''}${x.v}"`).join('')+(isImg?` \\\n -o result.${/jpeg/.test(ep.resp)?'jpg':'png'}`:'');
|
||
|
|
const files=b.filter(x=>x.file),data=b.filter(x=>!x.file);
|
||
|
|
const py=`import requests\n\nres = requests.${ep.method.toLowerCase()}(\n "${url}${qs}"`+(b.length?`,\n files={${files.map(x=>`"${x.n}": open("${x.v}", "rb")`).join(', ')}},\n data={${data.map(x=>`"${x.n}": "${x.v}"`).join(', ')}}`:'')+`,\n)\nres.raise_for_status()\n`+(isImg?`open("result.${/jpeg/.test(ep.resp)?'jpg':'png'}", "wb").write(res.content)`:`print(res.json())`);
|
||
|
|
const js=(b.length?`const form = new FormData();\n`+files.map(x=>`form.append("${x.n}", fileInput.files[0]); // ${x.v}`).join('\n')+(files.length?'\n':'')+data.map(x=>`form.append("${x.n}", "${x.v}");`).join('\n')+'\n\n':'')+`const res = await fetch("${url}${qs}", {\n method: "${ep.method}",`+(b.length?`\n body: form,`:'')+`\n});\n`+(isImg?`const image = URL.createObjectURL(await res.blob());`:`const result = await res.json();`);
|
||
|
|
return{curl,py,js,omitted};
|
||
|
|
}
|
||
|
|
|
||
|
|
const ICON='<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="m6 9 6 6 6-6"/></svg>';
|
||
|
|
|
||
|
|
function renderEndpointView(ep, isMulti){
|
||
|
|
const sn=snippets(ep);
|
||
|
|
return `<div class="ep-detail-pane" id="pane-${esc(ep.id)}">`+
|
||
|
|
(isMulti ? `<div class="ep-full-url-bar"><span class="m m-${esc(ep.method)}">${esc(ep.method)}</span><code>${esc(ep.full_url)}</code><button class="btn" data-act="copyurl" data-url="${esc(ep.full_url)}">Copy URL</button></div>` : '')+
|
||
|
|
`<p class="desc">${esc(ep.desc||ep.summary)}</p>`+
|
||
|
|
(ep.subs && ep.subs.length?`<h4>Also served at <span>${ep.subs.length} more routes</span></h4><ul class="subs">${ep.subs.map(x=>`<li><span class="m m-${esc(x.m)}">${esc(x.m)}</span><code>${esc(x.p)}</code><span>${esc(x.d)}</span></li>`).join('')}</ul>`:'')+
|
||
|
|
`<h4>Parameters <span>${ep.params.length} total, ${ep.params.filter(p=>p.rq).length} required</span></h4>`+
|
||
|
|
(ep.params.length?`<table class="pt"><thead><tr><th>Name</th><th>Type</th><th>Required</th><th>Default</th><th>What it does</th></tr></thead><tbody>${ep.params.map(p=>`<tr class="${p.rq?'req':''}"><td><code class="pn">${esc(p.n)}</code>${p.al?`<span class="al">also accepts <code>${esc(p.al)}</code></span>`:''}</td><td><code class="ty">${esc(p.ty)}</code><span class="lc">${esc(p.lc)}</span></td><td>${p.rq?'<span class="rq">Required</span>':'<span class="op">Optional</span>'}</td><td><code class="df">${esc(p.df||'—')}</code></td><td>${esc(p.ds)}</td></tr>`).join('')}</tbody></table>`:'<p class="hint">This endpoint takes no parameters.</p>')+
|
||
|
|
(ep.chips && ep.chips.length?`<h4>Verified Presets <span>${ep.chips.length} accepted values</span></h4>
|
||
|
|
<div class="pr-tools">
|
||
|
|
<input type="search" placeholder="Filter ${ep.chips.length} presets…" data-act="chipfilter" aria-label="Filter presets">
|
||
|
|
<button class="btn btn-primary" data-act="copyall" title="Copy all presets (newline-separated)">Copy All (${ep.chips.length})</button>
|
||
|
|
<button class="btn" data-act="copycomma" title="Copy all comma-separated">Copy Comma</button>
|
||
|
|
<button class="btn" data-act="copyjson" title="Copy as JSON array">Copy JSON</button>
|
||
|
|
<button class="btn" data-act="copyfilter" style="display:none;" title="Copy filtered presets">Copy Filtered (<span data-filtered-count>0</span>)</button>
|
||
|
|
<label class="multi-select-toggle" title="Enable multiple preset checkbox selection">
|
||
|
|
<input type="checkbox" data-act="toggleselectmode">
|
||
|
|
<span>Select Mode</span>
|
||
|
|
</label>
|
||
|
|
<button class="btn" data-act="copysel" style="display:none;">Copy Selected (<span data-n>0</span>)</button>
|
||
|
|
<button class="btn" data-act="clearsel" style="display:none;">Clear</button>
|
||
|
|
</div>
|
||
|
|
<div class="chips-hint">
|
||
|
|
<span>💡 Click any preset below to <b>copy it instantly</b>.</span>
|
||
|
|
</div>
|
||
|
|
<div class="chips">${ep.chips.map(c=>`<button class="chip" data-act="chip" data-val="${esc(c)}" title="Click to copy ${esc(c)}">${esc(c)}</button>`).join('')}</div>`:'')+
|
||
|
|
`<h4>Response</h4><div class="resp"><code>${esc(ep.resp||'—')}</code><span>${/json/.test(ep.resp)?'Parsed JSON body':'Binary image body, write it straight to a file'}</span></div>`+
|
||
|
|
`<h4>Try it</h4><div class="code" data-code><div class="ctab"><button class="on" data-act="tab" data-t="curl">cURL</button><button data-act="tab" data-t="py">Python</button><button data-act="tab" data-t="js">JavaScript</button><button class="cp" data-act="copycode">Copy</button></div><pre data-t="curl">${esc(sn.curl)}</pre><pre data-t="py" hidden>${esc(sn.py)}</pre><pre data-t="js" hidden>${esc(sn.js)}</pre></div>`+
|
||
|
|
(sn.omitted?`<p class="hint">${sn.omitted} optional parameter${sn.omitted>1?'s are':' is'} left out of these examples.</p>`:'')+
|
||
|
|
`</div>`;
|
||
|
|
}
|
||
|
|
|
||
|
|
function detail(api, s){
|
||
|
|
const isMulti = api.endpoints.length > 1;
|
||
|
|
let html = '';
|
||
|
|
|
||
|
|
if(isMulti){
|
||
|
|
html += `<div class="ep-tabs-wrapper">
|
||
|
|
<span class="ep-tabs-label">Endpoints categorized under this API (${api.endpoints.length}):</span>
|
||
|
|
<div class="ep-tabs">
|
||
|
|
${api.endpoints.map((ep, idx) => `
|
||
|
|
<button class="ep-tab ${idx === 0 ? 'active' : ''}" data-act="eptab" data-epid="${esc(ep.id)}">
|
||
|
|
<span class="m m-${esc(ep.method)}">${esc(ep.method)}</span>
|
||
|
|
<span>${esc(ep.subpath)}</span>
|
||
|
|
<span style="opacity:0.75;font-weight:400;font-size:12px;">(${esc(ep.title)})</span>
|
||
|
|
</button>
|
||
|
|
`).join('')}
|
||
|
|
</div>
|
||
|
|
</div>`;
|
||
|
|
|
||
|
|
html += `<div class="ep-panes">
|
||
|
|
${api.endpoints.map((ep, idx) => `
|
||
|
|
<div class="ep-pane-wrap" id="pane-wrap-${esc(ep.id)}" style="${idx === 0 ? '' : 'display:none;'}">
|
||
|
|
${renderEndpointView(ep, true)}
|
||
|
|
</div>
|
||
|
|
`).join('')}
|
||
|
|
</div>`;
|
||
|
|
} else {
|
||
|
|
html += `<div class="ep-full-url-bar"><span class="m m-${esc(api.endpoints[0].method)}">${esc(api.endpoints[0].method)}</span><code>${esc(api.endpoints[0].full_url)}</code><button class="btn" data-act="copyurl" data-url="${esc(api.endpoints[0].full_url)}">Copy URL</button></div>`;
|
||
|
|
html += renderEndpointView(api.endpoints[0], false);
|
||
|
|
}
|
||
|
|
|
||
|
|
return html;
|
||
|
|
}
|
||
|
|
|
||
|
|
function apiCardHTML(api, s){
|
||
|
|
const isMulti = api.endpoints.length > 1;
|
||
|
|
const totalParams = api.endpoints.reduce((acc, ep) => acc + (ep.params ? ep.params.length : 0), 0);
|
||
|
|
const totalChips = api.endpoints.reduce((acc, ep) => acc + (ep.chips ? ep.chips.length : 0), 0);
|
||
|
|
const methodBadge = isMulti ? `<span class="m m-MULTI">MULTI</span>` : `<span class="m m-${esc(api.endpoints[0].method)}">${esc(api.endpoints[0].method)}</span>`;
|
||
|
|
|
||
|
|
return `<article class="ep" id="${esc(api.id)}" data-sec="${esc(s.id)}">
|
||
|
|
<button class="eh" data-act="toggle" aria-expanded="false">
|
||
|
|
${methodBadge}
|
||
|
|
<span>
|
||
|
|
<span class="et">${esc(api.api_key)}</span>
|
||
|
|
<code class="ep-path">${esc(api.api_ip_link)}</code>
|
||
|
|
<span class="es">${esc(api.summary)}</span>
|
||
|
|
</span>
|
||
|
|
<span class="ek">
|
||
|
|
${isMulti ? `<span class="ep-count-tag">${api.endpoints.length} routes</span>` : `<span>1 route</span>`}
|
||
|
|
${totalChips ? `<span>${totalChips} presets</span>` : ''}
|
||
|
|
<span class="chev">${ICON}</span>
|
||
|
|
</span>
|
||
|
|
</button>
|
||
|
|
<div class="eb"><div class="ei"><div class="ew"></div></div></div>
|
||
|
|
</article>`;
|
||
|
|
}
|
||
|
|
|
||
|
|
const findAPI = id => {
|
||
|
|
for(const s of D.sections){
|
||
|
|
const a = s.apis.find(x => x.id === id);
|
||
|
|
if(a) return { a, s };
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
function render(){
|
||
|
|
const allApis = D.sections.flatMap(s => s.apis);
|
||
|
|
const totalEndpoints = allApis.reduce((acc, a) => acc + a.endpoints.length, 0);
|
||
|
|
const totalPresets = allApis.reduce((acc, a) => acc + a.endpoints.reduce((pacc, ep) => pacc + ep.chips.length, 0), 0);
|
||
|
|
const y = scrollY;
|
||
|
|
|
||
|
|
document.title = D.meta.title;
|
||
|
|
const m = D.meta;
|
||
|
|
|
||
|
|
$('#app').innerHTML = `
|
||
|
|
<nav class="rail" aria-label="API families">
|
||
|
|
<a class="brand" href="#top">
|
||
|
|
<svg viewBox="0 0 34 34">
|
||
|
|
<rect width="34" height="34" rx="10" fill="var(--ink)"/>
|
||
|
|
<circle cx="17" cy="17" r="8" fill="none" stroke="var(--paper)" stroke-width="2.4"/>
|
||
|
|
<path d="M17 9v8l6 4" stroke="hsl(172 70% 70%)" stroke-width="2.4" fill="none" stroke-linecap="round"/>
|
||
|
|
</svg>
|
||
|
|
<div>
|
||
|
|
<b>FastAPI Backend</b>
|
||
|
|
<span>${allApis.length} APIs (${totalEndpoints} routes)</span>
|
||
|
|
</div>
|
||
|
|
</a>
|
||
|
|
${D.sections.map(s => `
|
||
|
|
<a class="fam" href="#${esc(s.id)}" data-s="${esc(s.id)}" style="--h:${+s.hue||250}">
|
||
|
|
<i></i>${esc(s.title)}<em>${s.apis.length}</em>
|
||
|
|
</a>
|
||
|
|
`).join('')}
|
||
|
|
<div class="railfoot">Press <b>/</b> to search all APIs & presets.</div>
|
||
|
|
</nav>
|
||
|
|
<div class="shell">
|
||
|
|
<header class="top">
|
||
|
|
<button class="find" data-act="pal">
|
||
|
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2"><circle cx="11" cy="11" r="7"/><path d="m20 20-3.5-3.5"/></svg>
|
||
|
|
Search by API Key, URL or parameter
|
||
|
|
<kbd>/</kbd>
|
||
|
|
</button>
|
||
|
|
<span class="sp"></span>
|
||
|
|
<button class="btn" data-act="all">Expand all</button>
|
||
|
|
<button class="btn" data-act="theme" aria-label="Switch theme">Theme</button>
|
||
|
|
<a href="/docs/logout" class="btn" style="text-decoration:none;display:inline-flex;align-items:center;gap:6px;" title="Lock Documentation">
|
||
|
|
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2"><rect x="3" y="11" width="18" height="11" rx="2" ry="2"/><path d="M7 11V7a5 5 0 0 1 10 0v4"/></svg>Lock
|
||
|
|
</a>
|
||
|
|
</header>
|
||
|
|
<main id="top">
|
||
|
|
<section class="hero">
|
||
|
|
<h1>${esc(m.heading || m.title)}</h1>
|
||
|
|
<p class="lead">${esc(m.intro)}</p>
|
||
|
|
<button class="reel" data-act="reel" aria-label="Open this API">
|
||
|
|
<code><span class="mv" id="rm"></span> <span id="rp"></span><span class="cur"></span></code>
|
||
|
|
<small id="rs"></small>
|
||
|
|
</button>
|
||
|
|
<div class="facts">
|
||
|
|
<div><b>${allApis.length}</b>APIs (from Credentials)</div>
|
||
|
|
<div><b>${totalEndpoints}</b>Endpoint routes</div>
|
||
|
|
<div><b>${D.sections.length}</b>Families</div>
|
||
|
|
<div><b>${totalPresets.toLocaleString()}</b>Verified presets</div>
|
||
|
|
</div>
|
||
|
|
${m.authNote ? `<p class="note">${esc(m.authNote)}</p>` : ''}
|
||
|
|
</section>
|
||
|
|
${D.sections.map(s => `
|
||
|
|
<section class="fsec" id="${esc(s.id)}" style="--h:${+s.hue||250}">
|
||
|
|
<div class="fhead">
|
||
|
|
<h2>${esc(s.title)}</h2>
|
||
|
|
<div class="tag">
|
||
|
|
${s.tag ? `<span>${esc(s.tag)}</span>` : ''}
|
||
|
|
<span>${s.apis.length} API${s.apis.length===1?'':'s'}</span>
|
||
|
|
</div>
|
||
|
|
${s.lead ? `<p>${esc(s.lead)}</p>` : ''}
|
||
|
|
</div>
|
||
|
|
${s.apis.map(api => apiCardHTML(api, s)).join('')}
|
||
|
|
</section>
|
||
|
|
`).join('')}
|
||
|
|
</main>
|
||
|
|
</div>
|
||
|
|
<div class="pal" hidden data-act="palbg">
|
||
|
|
<div class="pbox" role="dialog" aria-label="Search APIs and endpoints">
|
||
|
|
<input id="pq" placeholder="Search ${allApis.length} APIs, URLs, parameters, presets…" autocomplete="off">
|
||
|
|
<div class="pl" id="pl"></div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
<div class="toast" id="toast" hidden></div>
|
||
|
|
`;
|
||
|
|
|
||
|
|
open.forEach(id => {
|
||
|
|
const f = findAPI(id);
|
||
|
|
const a = document.getElementById(id);
|
||
|
|
if(f && a) setOpen(a, true);
|
||
|
|
});
|
||
|
|
scrollTo(0, y);
|
||
|
|
spy();
|
||
|
|
reel();
|
||
|
|
}
|
||
|
|
|
||
|
|
function setOpen(a, on){
|
||
|
|
const f = findAPI(a.id);
|
||
|
|
if(!f) return;
|
||
|
|
a.classList.toggle('open', on);
|
||
|
|
$('.eh', a).setAttribute('aria-expanded', on);
|
||
|
|
a.style.setProperty('--h', f.s.hue);
|
||
|
|
a.style.setProperty('--a', `hsl(${+f.s.hue||250} 55% 40%)`);
|
||
|
|
const w = $('.ew', a);
|
||
|
|
if(on && !w.innerHTML) w.innerHTML = detail(f.a, f.s);
|
||
|
|
on ? open.add(a.id) : open.delete(a.id);
|
||
|
|
}
|
||
|
|
|
||
|
|
function toast(t){
|
||
|
|
const n = $('#toast');
|
||
|
|
n.textContent = t;
|
||
|
|
n.hidden = false;
|
||
|
|
clearTimeout(toastT);
|
||
|
|
toastT = setTimeout(() => n.hidden = true, 1800);
|
||
|
|
}
|
||
|
|
|
||
|
|
async function copy(t, msg){
|
||
|
|
try {
|
||
|
|
await navigator.clipboard.writeText(t);
|
||
|
|
} catch {
|
||
|
|
const x = document.createElement('textarea');
|
||
|
|
x.value = t;
|
||
|
|
document.body.append(x);
|
||
|
|
x.select();
|
||
|
|
document.execCommand('copy');
|
||
|
|
x.remove();
|
||
|
|
}
|
||
|
|
toast(msg || 'Copied to clipboard');
|
||
|
|
}
|
||
|
|
|
||
|
|
function goto(id){
|
||
|
|
const a = document.getElementById(id);
|
||
|
|
if(!a) return;
|
||
|
|
setOpen(a, true);
|
||
|
|
history.replaceState(null, '', '#' + id);
|
||
|
|
setTimeout(() => a.scrollIntoView({ behavior: 'smooth', block: 'start' }), 60);
|
||
|
|
}
|
||
|
|
|
||
|
|
let ro;
|
||
|
|
function spy(){
|
||
|
|
ro && ro.disconnect();
|
||
|
|
ro = new IntersectionObserver(es => es.forEach(en => {
|
||
|
|
if(en.isIntersecting) $$('.fam').forEach(f => f.classList.toggle('on', f.dataset.s === en.target.id));
|
||
|
|
}), { rootMargin: '-20% 0px -70% 0px' });
|
||
|
|
$$('.fsec').forEach(s => ro.observe(s));
|
||
|
|
}
|
||
|
|
|
||
|
|
let reelTok = 0, reelCur = null;
|
||
|
|
async function reel(){
|
||
|
|
const tok = ++reelTok, rp = $('#rp'), rm = $('#rm'), rs = $('#rs'), box = $('.reel');
|
||
|
|
if(!rp) return;
|
||
|
|
const allApis = D.sections.flatMap(s => s.apis.map(a => ({ a, s }))).filter(x => x.a.api_ip_link);
|
||
|
|
if(!allApis.length) return;
|
||
|
|
const still = matchMedia('(prefers-reduced-motion:reduce)').matches, z = ms => new Promise(r => setTimeout(r, ms));
|
||
|
|
let i = Math.floor(Math.random() * allApis.length);
|
||
|
|
|
||
|
|
while(tok === reelTok && document.contains(rp)){
|
||
|
|
const { a, s } = allApis[i % allApis.length];
|
||
|
|
reelCur = a.id;
|
||
|
|
box.style.setProperty('--h', s.hue);
|
||
|
|
rm.textContent = a.api_key;
|
||
|
|
rs.textContent = '';
|
||
|
|
if(still){
|
||
|
|
rp.textContent = a.api_ip_link;
|
||
|
|
rs.textContent = `${a.summary} (${a.endpoints.length} routes)`;
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
for(let k = 1; k <= a.api_ip_link.length && tok === reelTok; k++){
|
||
|
|
rp.textContent = a.api_ip_link.slice(0, k);
|
||
|
|
await z(18);
|
||
|
|
}
|
||
|
|
rs.textContent = `${a.summary} (${a.endpoints.length} routes)`;
|
||
|
|
await z(2400);
|
||
|
|
for(let k = a.api_ip_link.length; k >= 0 && tok === reelTok; k -= 3){
|
||
|
|
rp.textContent = a.api_ip_link.slice(0, Math.max(k, 0));
|
||
|
|
await z(8);
|
||
|
|
}
|
||
|
|
i += 7;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
function palList(q){
|
||
|
|
const t = q.toLowerCase().split(/\s+/).filter(Boolean), out = [];
|
||
|
|
for(const s of D.sections){
|
||
|
|
for(const a of s.apis){
|
||
|
|
const epDetails = a.endpoints.map(ep => [ep.title, ep.full_url, ep.subpath, ep.summary, ...ep.params.map(p => p.n), ...ep.chips].join(' ')).join(' ');
|
||
|
|
const hay = [a.api_key, a.api_ip_link, a.summary, s.title, epDetails].join(' ').toLowerCase();
|
||
|
|
if(t.every(w => hay.includes(w))){
|
||
|
|
const h = (a.api_key + ' ' + a.api_ip_link).toLowerCase();
|
||
|
|
out.push({ a, sc: t.reduce((n, w) => n + (h.includes(w) ? 3 : 0) + (h.startsWith(w) ? 4 : 0), 0) });
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return out.sort((x, y) => y.sc - x.sc).slice(0, 40);
|
||
|
|
}
|
||
|
|
|
||
|
|
let pi = 0, pr = [];
|
||
|
|
function palDraw(){
|
||
|
|
const l = $('#pl');
|
||
|
|
pr = palList($('#pq').value);
|
||
|
|
pi = Math.min(pi, Math.max(pr.length - 1, 0));
|
||
|
|
l.innerHTML = pr.length ? pr.map((x, i) => `
|
||
|
|
<button class="pi ${i === pi ? 'on' : ''}" data-act="pick" data-id="${esc(x.a.id)}">
|
||
|
|
<span class="m m-${esc(x.a.method)}">${esc(x.a.method)}</span>
|
||
|
|
<span>
|
||
|
|
<b>${esc(x.a.api_key)}</b>
|
||
|
|
<code>${esc(x.a.api_ip_link)}</code>
|
||
|
|
</span>
|
||
|
|
</button>
|
||
|
|
`).join('') : '<p class="pe">No matching APIs found. Try searching by API key (e.g. <code>Teeth_Whitener</code>) or parameter name.</p>';
|
||
|
|
$('.pi.on')?.scrollIntoView({ block: 'nearest' });
|
||
|
|
}
|
||
|
|
|
||
|
|
function palOpen(on){
|
||
|
|
const p = $('.pal');
|
||
|
|
p.hidden = !on;
|
||
|
|
if(on){
|
||
|
|
$('#pq').value = '';
|
||
|
|
pi = 0;
|
||
|
|
palDraw();
|
||
|
|
$('#pq').focus();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// Global click delegation
|
||
|
|
document.addEventListener('click', ev => {
|
||
|
|
const t = ev.target.closest('[data-act]');
|
||
|
|
if(!t) return;
|
||
|
|
const a = t.dataset.act;
|
||
|
|
const card = t.closest('.ep');
|
||
|
|
|
||
|
|
if(a === 'palbg'){ if(ev.target === t) palOpen(false); return; }
|
||
|
|
if(a === 'toggle') setOpen(card, !card.classList.contains('open'));
|
||
|
|
else if(a === 'pal') palOpen(true);
|
||
|
|
else if(a === 'pick'){ palOpen(false); goto(t.dataset.id); }
|
||
|
|
else if(a === 'reel' && reelCur) goto(reelCur);
|
||
|
|
else if(a === 'theme'){
|
||
|
|
const n = document.documentElement.dataset.theme === 'dark' ? 'light' : 'dark';
|
||
|
|
document.documentElement.dataset.theme = n;
|
||
|
|
try { localStorage.setItem('apidocs-theme', n); } catch {}
|
||
|
|
}
|
||
|
|
else if(a === 'all'){
|
||
|
|
const on = t.textContent === 'Expand all';
|
||
|
|
$$('.ep').forEach(x => setOpen(x, on));
|
||
|
|
t.textContent = on ? 'Collapse all' : 'Expand all';
|
||
|
|
}
|
||
|
|
// Endpoint switching within multi-endpoint API
|
||
|
|
else if(a === 'eptab'){
|
||
|
|
const epid = t.dataset.epid;
|
||
|
|
const cardBody = t.closest('.ew');
|
||
|
|
$$('.ep-tab', cardBody).forEach(tab => tab.classList.toggle('active', tab === t));
|
||
|
|
$$('.ep-pane-wrap', cardBody).forEach(pane => {
|
||
|
|
pane.style.display = (pane.id === `pane-wrap-${epid}`) ? 'block' : 'none';
|
||
|
|
});
|
||
|
|
}
|
||
|
|
// Copy full URL button
|
||
|
|
else if(a === 'copyurl'){
|
||
|
|
const url = t.dataset.url;
|
||
|
|
if(url) copy(url, 'Copied full API URL');
|
||
|
|
}
|
||
|
|
// Single-Click Preset Chip Copy (USER REQUIREMENT!)
|
||
|
|
else if(a === 'chip'){
|
||
|
|
const chipVal = t.dataset.val || t.textContent.trim();
|
||
|
|
const epPane = t.closest('.ep-detail-pane') || t.closest('.ew');
|
||
|
|
const selectMode = epPane.querySelector('[data-act="toggleselectmode"]')?.checked;
|
||
|
|
|
||
|
|
if(selectMode){
|
||
|
|
// In select mode: toggle selection for custom bulk copying
|
||
|
|
t.classList.toggle('sel');
|
||
|
|
const selCount = epPane.querySelectorAll('.chip.sel').length;
|
||
|
|
const countSpan = epPane.querySelector('[data-n]');
|
||
|
|
if(countSpan) countSpan.textContent = selCount;
|
||
|
|
const copySelBtn = epPane.querySelector('[data-act="copysel"]');
|
||
|
|
if(copySelBtn) copySelBtn.style.display = selCount > 0 ? 'inline-flex' : 'none';
|
||
|
|
const clearBtn = epPane.querySelector('[data-act="clearsel"]');
|
||
|
|
if(clearBtn) clearBtn.style.display = selCount > 0 ? 'inline-flex' : 'none';
|
||
|
|
} else {
|
||
|
|
// DEFAULT: SINGLE CLICK COPIES THAT PRESET INSTANTLY!
|
||
|
|
copy(chipVal, `Copied "${chipVal}"`);
|
||
|
|
t.classList.add('copied');
|
||
|
|
setTimeout(() => t.classList.remove('copied'), 650);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
// Bulk Copy: Copy All (newline-separated)
|
||
|
|
else if(a === 'copyall'){
|
||
|
|
const epPane = t.closest('.ep-detail-pane') || t.closest('.ew');
|
||
|
|
const chips = [...epPane.querySelectorAll('.chip')].map(c => c.dataset.val || c.textContent.trim());
|
||
|
|
if(chips.length) copy(chips.join('\n'), `Copied all ${chips.length} presets (newline-separated)`);
|
||
|
|
}
|
||
|
|
// Bulk Copy: Copy Comma-Separated
|
||
|
|
else if(a === 'copycomma'){
|
||
|
|
const epPane = t.closest('.ep-detail-pane') || t.closest('.ew');
|
||
|
|
const chips = [...epPane.querySelectorAll('.chip')].map(c => c.dataset.val || c.textContent.trim());
|
||
|
|
if(chips.length) copy(chips.join(', '), `Copied all ${chips.length} presets (comma-separated)`);
|
||
|
|
}
|
||
|
|
// Bulk Copy: Copy JSON Array
|
||
|
|
else if(a === 'copyjson'){
|
||
|
|
const epPane = t.closest('.ep-detail-pane') || t.closest('.ew');
|
||
|
|
const chips = [...epPane.querySelectorAll('.chip')].map(c => c.dataset.val || c.textContent.trim());
|
||
|
|
if(chips.length) copy(JSON.stringify(chips, null, 2), `Copied ${chips.length} presets as JSON array`);
|
||
|
|
}
|
||
|
|
// Bulk Copy: Copy Filtered Search Results
|
||
|
|
else if(a === 'copyfilter'){
|
||
|
|
const epPane = t.closest('.ep-detail-pane') || t.closest('.ew');
|
||
|
|
const visibleChips = [...epPane.querySelectorAll('.chip:not([hidden])')].map(c => c.dataset.val || c.textContent.trim());
|
||
|
|
if(visibleChips.length) copy(visibleChips.join('\n'), `Copied ${visibleChips.length} matching presets`);
|
||
|
|
}
|
||
|
|
// Bulk Copy: Copy Selected Custom Set
|
||
|
|
else if(a === 'copysel'){
|
||
|
|
const epPane = t.closest('.ep-detail-pane') || t.closest('.ew');
|
||
|
|
const selChips = [...epPane.querySelectorAll('.chip.sel')].map(c => c.dataset.val || c.textContent.trim());
|
||
|
|
if(selChips.length) copy(selChips.join('\n'), `Copied ${selChips.length} selected presets`);
|
||
|
|
}
|
||
|
|
// Clear custom selection
|
||
|
|
else if(a === 'clearsel'){
|
||
|
|
const epPane = t.closest('.ep-detail-pane') || t.closest('.ew');
|
||
|
|
epPane.querySelectorAll('.chip.sel').forEach(c => c.classList.remove('sel'));
|
||
|
|
const countSpan = epPane.querySelector('[data-n]');
|
||
|
|
if(countSpan) countSpan.textContent = 0;
|
||
|
|
t.style.display = 'none';
|
||
|
|
const copySelBtn = epPane.querySelector('[data-act="copysel"]');
|
||
|
|
if(copySelBtn) copySelBtn.style.display = 'none';
|
||
|
|
}
|
||
|
|
// Code tabs (cURL, Python, JS)
|
||
|
|
else if(a === 'tab'){
|
||
|
|
const box = t.closest('[data-code]');
|
||
|
|
$$('.ctab button[data-t]', box).forEach(b => b.classList.toggle('on', b === t));
|
||
|
|
$$('pre', box).forEach(p => p.hidden = p.dataset.t !== t.dataset.t);
|
||
|
|
}
|
||
|
|
// Copy code snippet
|
||
|
|
else if(a === 'copycode'){
|
||
|
|
copy($$('pre', t.closest('[data-code]')).find(p => !p.hidden).textContent, 'Copied request snippet');
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
// Input delegation for preset filter & search
|
||
|
|
document.addEventListener('input', ev => {
|
||
|
|
const t = ev.target;
|
||
|
|
if(t.id === 'pq'){
|
||
|
|
pi = 0;
|
||
|
|
palDraw();
|
||
|
|
} else if(t.dataset.act === 'chipfilter'){
|
||
|
|
const q = t.value.toLowerCase().trim();
|
||
|
|
const epPane = t.closest('.ep-detail-pane') || t.closest('.ew');
|
||
|
|
const chips = epPane.querySelectorAll('.chip');
|
||
|
|
let matchCount = 0;
|
||
|
|
chips.forEach(c => {
|
||
|
|
const val = (c.dataset.val || c.textContent).toLowerCase();
|
||
|
|
const matches = !q || val.includes(q);
|
||
|
|
c.hidden = !matches;
|
||
|
|
if(matches) matchCount++;
|
||
|
|
});
|
||
|
|
const filterBtn = epPane.querySelector('[data-act="copyfilter"]');
|
||
|
|
if(filterBtn){
|
||
|
|
if(q && matchCount > 0){
|
||
|
|
filterBtn.style.display = 'inline-flex';
|
||
|
|
filterBtn.querySelector('[data-filtered-count]').textContent = matchCount;
|
||
|
|
} else {
|
||
|
|
filterBtn.style.display = 'none';
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
// Toggle select mode change event
|
||
|
|
document.addEventListener('change', ev => {
|
||
|
|
const t = ev.target;
|
||
|
|
if(t.dataset.act === 'toggleselectmode'){
|
||
|
|
const epPane = t.closest('.ep-detail-pane') || t.closest('.ew');
|
||
|
|
const hint = epPane.querySelector('.chips-hint span');
|
||
|
|
if(t.checked){
|
||
|
|
if(hint) hint.innerHTML = '👉 <b>Select Mode Active:</b> Click presets to select them, then click Copy Selected.';
|
||
|
|
} else {
|
||
|
|
if(hint) hint.innerHTML = '💡 Click any preset below to <b>copy it instantly</b>.';
|
||
|
|
}
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
// Keyboard shortcuts
|
||
|
|
document.addEventListener('keydown', ev => {
|
||
|
|
const p = $('.pal'), typing = /INPUT|TEXTAREA/.test(document.activeElement.tagName);
|
||
|
|
if(((ev.ctrlKey || ev.metaKey) && ev.key === 'k') || (ev.key === '/' && !typing)){
|
||
|
|
ev.preventDefault();
|
||
|
|
palOpen(true);
|
||
|
|
} else if(p && !p.hidden){
|
||
|
|
if(ev.key === 'Escape') palOpen(false);
|
||
|
|
else if(ev.key === 'ArrowDown'){ ev.preventDefault(); pi = Math.min(pi + 1, pr.length - 1); palDraw(); }
|
||
|
|
else if(ev.key === 'ArrowUp'){ ev.preventDefault(); pi = Math.max(pi - 1, 0); palDraw(); }
|
||
|
|
else if(ev.key === 'Enter' && pr[pi]){ palOpen(false); goto(pr[pi].a.id); }
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
render();
|
||
|
|
})();
|
||
|
|
"""
|
||
|
|
|
||
|
|
# Assemble new HTML
|
||
|
|
new_html = head_part + "<style>" + new_style + "</style>\n</head>\n<body>\n<div id=\"app\"></div>\n"
|
||
|
|
new_html += '<script id="api-data" type="application/json">' + json.dumps(unified_data) + '</script>\n'
|
||
|
|
new_html += '<script>' + js_code + '</script>\n</body>\n</html>'
|
||
|
|
|
||
|
|
# Write to test file and check syntax
|
||
|
|
with open("/tmp/test_docs.js", "w") as f:
|
||
|
|
f.write(js_code)
|
||
|
|
|
||
|
|
res = subprocess.run(["node", "--check", "/tmp/test_docs.js"], capture_output=True, text=True)
|
||
|
|
print("Node check exit code:", res.returncode)
|
||
|
|
if res.stderr:
|
||
|
|
print("Errors:", res.stderr)
|
||
|
|
exit(1)
|
||
|
|
|
||
|
|
# Write to web/docs/index.html and web/docs/FASTAPI_BACKEND_API_DOCS.html
|
||
|
|
with open("web/docs/index.html", "w") as f:
|
||
|
|
f.write(new_html)
|
||
|
|
|
||
|
|
with open("web/docs/FASTAPI_BACKEND_API_DOCS.html", "w") as f:
|
||
|
|
f.write(new_html)
|
||
|
|
|
||
|
|
print("SUCCESS: Updated web/docs/index.html and web/docs/FASTAPI_BACKEND_API_DOCS.html!")
|
||
|
|
print(f"Total HTML file size: {len(new_html)} bytes")
|