5 lines
4.1 KiB
JavaScript
5 lines
4.1 KiB
JavaScript
import{j as e}from"./jsx-runtime.ClP7wGfN.js";import{r as a}from"./index.DK-fsZOb.js";function j(r){try{return JSON.parse(r)}catch{return null}}function S(r){const[o,p]=a.useState(""),[l,b]=a.useState(""),[n,g]=a.useState(""),[d,w]=a.useState('{"kind":"report-summary","public_title":"Q4 review pack"}'),[i,c]=a.useState(null),[u,h]=a.useState(!1),x=a.useMemo(()=>{const t=j(d),s={source_sha256:l.trim(),output_sha256:n.trim()};return t&&typeof t=="object"&&(s.metadata=t),s},[d,n,l]),m=a.useMemo(()=>{const t=r.baseUrl.replace(/\/+$/,""),s=JSON.stringify(x).replace(/'/g,"'\\''");return`curl -sS -X POST ${t}/v1/trace \\
|
|
-H 'Authorization: Bearer $IFTRACE_API_KEY' \\
|
|
-H 'Content-Type: application/json' \\
|
|
-d '${s}'`},[x,r.baseUrl]);async function y(){h(!0),c(null);try{const t=r.baseUrl.replace(/\/+$/,""),s=await fetch(`${t}/v1/trace`,{method:"POST",headers:{"Content-Type":"application/json",...o.trim()?{Authorization:`Bearer ${o.trim()}`}:{}},body:JSON.stringify(x)}),f=await s.text();c({ok:s.ok,status:s.status,body:f})}catch(t){c({ok:!1,status:0,body:t?.message?String(t.message):String(t)})}finally{h(!1)}}return e.jsxs("div",{className:"rounded-2xl border border-white/10 bg-white/5 p-5 shadow-[0_16px_60px_rgba(0,0,0,0.35)]",children:[e.jsx("div",{className:"text-sm font-semibold text-white/90",children:"Try the endpoint"}),e.jsxs("p",{className:"mt-2 text-sm text-white/70",children:["This sends a real request to ",e.jsx("span",{className:"font-medium text-white/85",children:r.baseUrl}),". Use non-confidential hashes."]}),e.jsxs("div",{className:"mt-4 grid gap-3 sm:grid-cols-2",children:[e.jsxs("label",{className:"grid gap-1 text-xs text-white/70",children:["API key (optional)",e.jsx("input",{value:o,onChange:t=>p(t.target.value),placeholder:"IFTRACE_API_KEY",className:"rounded-xl border border-white/10 bg-slate-950/30 px-3 py-2 text-sm text-white/90 placeholder:text-white/35"})]}),e.jsx("div",{className:"hidden sm:block"}),e.jsxs("label",{className:"grid gap-1 text-xs text-white/70",children:["source_sha256",e.jsx("input",{value:l,onChange:t=>b(t.target.value),placeholder:"64-hex",className:"rounded-xl border border-white/10 bg-slate-950/30 px-3 py-2 text-sm text-white/90 placeholder:text-white/35"})]}),e.jsxs("label",{className:"grid gap-1 text-xs text-white/70",children:["output_sha256",e.jsx("input",{value:n,onChange:t=>g(t.target.value),placeholder:"64-hex",className:"rounded-xl border border-white/10 bg-slate-950/30 px-3 py-2 text-sm text-white/90 placeholder:text-white/35"})]}),e.jsxs("label",{className:"grid gap-1 text-xs text-white/70 sm:col-span-2",children:["metadata (JSON, optional)",e.jsx("textarea",{value:d,onChange:t=>w(t.target.value),rows:3,className:"rounded-xl border border-white/10 bg-slate-950/30 px-3 py-2 font-mono text-xs text-white/90 placeholder:text-white/35"})]})]}),e.jsxs("div",{className:"mt-4 flex flex-col gap-2 sm:flex-row sm:items-center",children:[e.jsx("button",{type:"button",onClick:y,disabled:u,className:"inline-flex items-center justify-center rounded-full bg-primary px-4 py-2 text-sm font-medium text-primary-foreground transition hover:bg-primary/90 disabled:cursor-not-allowed disabled:opacity-60",children:u?"Sending…":"Send request"}),e.jsx("button",{type:"button",onClick:()=>navigator.clipboard?.writeText(m),className:"inline-flex items-center justify-center rounded-full border border-white/12 bg-white/5 px-4 py-2 text-sm font-medium text-white/85 transition hover:bg-white/10 hover:text-white",children:"Copy curl"})]}),e.jsxs("div",{className:"mt-4",children:[e.jsx("div",{className:"text-xs font-medium uppercase tracking-wide text-white/50",children:"curl"}),e.jsx("pre",{className:"mt-2 overflow-x-auto rounded-2xl border border-white/10 bg-slate-950/40 p-4 text-xs text-white/85",children:e.jsx("code",{children:m})})]}),i&&e.jsxs("div",{className:"mt-4",children:[e.jsx("div",{className:"text-xs font-medium uppercase tracking-wide text-white/50",children:"Response"}),e.jsx("pre",{className:"mt-2 overflow-x-auto rounded-2xl border border-white/10 bg-slate-950/40 p-4 text-xs text-white/85",children:e.jsxs("code",{children:[i.ok?"OK":"FAIL"," status=",i.status,`
|
|
`,i.body]})})]})]})}export{S as ApiTryForm};
|