File size: 10,326 Bytes
0b8d5a5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>API Py — Test Panel</title>
<style>
  :root{
    --bg:#0f1115; --panel:#161a22; --panel2:#1c212b; --border:#2a3040;
    --text:#e6e9ef; --muted:#8b93a7; --accent:#4f8cff; --accent2:#34d399;
    --danger:#f87171; --mono:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;
  }
  *{box-sizing:border-box}
  body{margin:0;background:var(--bg);color:var(--text);
    font-family:system-ui,-apple-system,Segoe UI,Roboto,sans-serif;line-height:1.5}
  header{padding:18px 24px;border-bottom:1px solid var(--border);
    display:flex;align-items:center;gap:16px;flex-wrap:wrap;
    position:sticky;top:0;background:var(--bg);z-index:5}
  header h1{font-size:18px;margin:0;font-weight:600}
  header .sub{color:var(--muted);font-size:13px}
  .base{display:flex;align-items:center;gap:8px;margin-left:auto;flex-wrap:wrap}
  .base label{color:var(--muted);font-size:13px}
  main{padding:24px;display:grid;grid-template-columns:repeat(auto-fit,minmax(380px,1fr));
    gap:20px;align-items:start}
  .card{background:var(--panel);border:1px solid var(--border);border-radius:12px;
    padding:16px;display:flex;flex-direction:column;gap:12px}
  .card h2{font-size:14px;margin:0;letter-spacing:.02em;display:flex;
    align-items:center;gap:8px}
  .method{font-family:var(--mono);font-size:11px;padding:2px 8px;border-radius:6px;
    font-weight:600}
  .get{background:rgba(79,140,255,.15);color:#7aa9ff}
  .post{background:rgba(52,211,153,.15);color:#5eead4}
  .path{font-family:var(--mono);font-size:12px;color:var(--muted)}
  .field{display:flex;flex-direction:column;gap:5px}
  .field label{font-size:12px;color:var(--muted)}
  .row{display:flex;gap:10px;flex-wrap:wrap}
  .row .field{flex:1;min-width:140px}
  input,select,button{
    background:var(--panel2);color:var(--text);border:1px solid var(--border);
    border-radius:8px;padding:8px 10px;font-size:13px;font-family:inherit;outline:none}
  input:focus,select:focus{border-color:var(--accent)}
  input[type=text],input[type=url]{width:100%}
  .check{flex-direction:row;align-items:center;gap:8px}
  .check input{accent-color:var(--accent);width:16px;height:16px}
  .check label{color:var(--text)}
  .actions{display:flex;gap:8px;align-items:center;margin-top:2px}
  button.run{background:var(--accent);color:#fff;border:none;font-weight:600;cursor:pointer}
  button.run:hover{filter:brightness(1.08)}
  button.run:disabled{opacity:.6;cursor:wait}
  .status{font-family:var(--mono);font-size:12px;border-radius:8px;padding:8px 10px;
    background:var(--panel2)}
  .status.ok{color:var(--accent2)}
  .status.err{color:var(--danger,#f87171)}
  .status.wait{color:var(--muted)}
  pre.js{background:#0a0d12;border:1px solid var(--border);border-radius:8px;
    padding:12px;font-family:var(--mono);font-size:12px;overflow:auto;
    max-height:360px;margin:0;white-space:pre-wrap;word-break:break-word}
  .links{display:flex;flex-direction:column;gap:4px}
  .links a{color:#7aa9ff;text-decoration:none;font-family:var(--mono);
    font-size:12px;word-break:break-all}
  .links a:hover{text-decoration:underline}
  .meta{font-size:12px;color:var(--muted)}
  .title{color:var(--text);font-weight:600}
</style>
</head>
<body>
<header>
  <h1>API Py <span class="sub">· test panel</span></h1>
  <div class="base">
    <label for="base">API base</label>
    <input type="url" id="base" value="https://lljz66-api.hf.space" style="width:320px" spellcheck="false">
  </div>
</header>

<main>
  <!-- /health -->
  <section class="card">
    <h2><span class="method get">GET</span><span class="path">/health</span></h2>
    <div class="actions"><button class="run" id="healthRun">Run</button></div>
    <div class="status wait" id="healthStatus">not run</div>
    <pre class="js" id="healthOut"></pre>
  </section>

  <!-- /map -->
  <section class="card">
    <h2><span class="method get">GET</span><span class="path">/map</span></h2>
    <div class="row">
      <div class="field"><label>url</label>
        <input type="text" id="map_url" value="https://example.com" spellcheck="false"></div>
      <div class="field"><label>search (optional)</label>
        <input type="text" id="map_search" placeholder="filter keyword" spellcheck="false"></div>
    </div>
    <div class="row">
      <div class="field"><label>sitemap</label>
        <select id="map_sitemap">
          <option value="include" selected>include</option>
          <option value="skip">skip</option>
          <option value="only">only</option>
        </select></div>
      <div class="field"><label>limit</label>
        <input type="number" id="map_limit" value="100" min="1" max="5000"></div>
      <div class="field check"><input type="checkbox" id="map_sub" checked>
        <label for="map_sub">include subdomains</label></div>
    </div>
    <div class="actions"><button class="run" id="mapRun">Run</button></div>
    <div class="status" id="map_status">not run</div>
    <div class="meta" id="map_meta"></div>
    <div class="links" id="map_links"></div>
    <pre class="js" id="mapOut" style="display:none"></pre>
  </section>

  <!-- /scrape -->
  <section class="card">
    <h2><span class="method post">POST</span><span class="path">/scrape</span></h2>
    <div class="field"><label>url</label>
      <input type="url" id="s_url" value="https://example.com" spellcheck="false"></div>
    <div class="actions"><button class="run" id="sRun">Run</button></div>
    <div class="status" id="s_status">not run</div>
    <div class="title" id="s_title"></div>
    <pre class="js" id="sOut"></pre>
  </section>

  <!-- /favicon -->
  <section class="card">
    <h2><span class="method get">GET</span><span class="path">/favicon</span></h2>
    <div class="field"><label>url</label>
      <input type="url" id="f_url" value="https 7">https://example.com</div>
    <div class="actions"><button class="run" id="fRun">Run</button></div>
    <div class="status" id="f_status">not run</div>
    <div id="f_icon" class="meta" style="display:flex;align-items:center;gap:10px"></div>
    <pre class="js" id="fOut" style="display:none"></pre>
  </section>
</main>

<script>
  const $ = id => document.getElementById(id);
  function baseUrl(){ return $('base').value.replace(/\/+$/,''); }
  async function req(path, opts){
    const res = await fetch(baseUrl() + path, opts);
    const text = await res.text();
    let body; try{ body = JSON.parse(text); }catch(e){ body = text; }
    return {ok:res.ok, status:res.status, body};
  }
  function showStatus(el, kind, msg){ el.className='status '+kind; el.textContent=msg; }
  const fmt = o => JSON.stringify(o,null,2);

  async function runHealth(){
    const st=$('healthStatus'), out=$('healthOut'), btn=$('healthRun');
    btn.disabled=true; showStatus(st,'wait','loading…'); out.textContent='—';
    try{
      const r=await req('/health');
      out.textContent=fmt(r.body);
      showStatus(st, r.ok?'ok':'err', 'HTTP '+r.status + (r.ok?' · healthy':''));
    }catch(e){ showStatus(st,'err','network error: '+e.message); }
    btn.disabled=false;
  }

  async function runMap(){
    const st=$('map_status'), out=$('mapOut'), meta=$('map_meta'), links=$('map_links'), btn=$('mapRun');
    btn.disabled=true;
    showStatus(st,'wait','crawling…'); meta.textContent=''; links.innerHTML=''; out.style.display='none';
    const params=new URLSearchParams();
    params.set('url',$('map_url').value.trim());
    if($('map_search').value.trim()) params.set('search',$('map_search').value.trim());
    params.set('sitemap',$('map_sitemap').value);
    params.set('include_subdomains',$('map_sub').checked);
    params.set('limit',$('map_limit').value);
    try{
      const r=await req('/map?'+params.toString());
      out.style.display='block'; out.textContent=fmt(r.body);
      if(r.ok){
        const arr=r.body.links||[];
        showStatus(st,'ok','HTTP '+r.status+' · total '+r.body.total);
        meta.textContent=arr.length+' links shown';
        links.innerHTML=arr.map(u=>'<a href="'+u.replace(/"/g,'')+'" target="_blank" rel="noopener">'+u+'</a>').join('');
      }else{
        showStatus(st,'err','HTTP '+r.status+' · '+((r.body&&r.body.detail)?r.body.detail:''));
      }
    }catch(e){ showStatus(st,'err','network error: '+e.message); }
    btn.disabled=false;
  }

  async function runScrape(){
    const st=$('s_status'), ti=$('s_title'), co=$('sOut'), btn=$('sRun');
    btn.disabled=true;
    showStatus(st,'wait','scraping…'); ti.textContent=''; co.textContent='—';
    try{
      const r=await req('/scrape',{method:'POST',headers:{'Content-Type':'application/json'},
        body:JSON.stringify({url:$('s_url').value.trim()})});
      if(r.ok){
        showStatus(st,'ok','HTTP '+r.status);
        ti.textContent = r.body.title? 'Title: '+r.body.title : '';
        co.textContent = r.body.content || '(empty content)';
      }else{
        showStatus(st,'err','HTTP '+r.status+' · '+((r.body&&r.body.detail)?r.body.detail:JSON.stringify(r.body)));
        co.textContent='';
      }
    }catch(e){ showStatus(st,'err','network error: '+e.message); }
    btn.disabled=false;
  }

  async function runFavicon(){
    const st=$('f_status'), icon=$('f_icon'), pre=$('fOut'), btn=$('fRun');
    btn.disabled=true;
    showStatus(st,'wait','looking up…'); icon.innerHTML=''; pre.style.display='none';
    try{
      const r=await req('/favicon?url='+encodeURIComponent($('f_url').value.trim()));
      pre.style.display='block'; pre.textContent=fmt(r.body);
      if(r.ok){
        showStatus(st,'ok','HTTP '+r.status);
        icon.innerHTML='<img src="'+r.body.icon_url+'" alt="favicon" width="24" height="24"> <span>'+r.body.domain+'</span>';
      }else showStatus(st,'err','HTTP '+r.status);
    }catch(e){ showStatus(st,'err','network error: '+e.message); }
    btn.disabled=false;
  }

  $('healthRun').onclick=runHealth;
  $('mapRun').onclick=runMap;
  $('sRun').onclick=runScrape;
  $('fRun').onclick=runFavicon;
  $('map_url').addEventListener('keydown',e=>{if(e.key==='Enter')runMap();});
  $('s_url').addEventListener('keydown',e=>{if(e.key==='Enter')runScrape();});
  $('f_url').addEventListener('keydown',e=>{if(e.key==='Enter')runFavicon();});
</script>
</body>
</html>