mirror of
https://github.com/rishikanthc/Scriberr.git
synced 2026-06-29 23:36:18 +00:00
6 lines
18 KiB
JavaScript
6 lines
18 KiB
JavaScript
import{r as p,j as e,G as Z,c as ee,R as te}from"./styles-CUNhQwI0.js";function se(){var S,$;const[t,s]=p.useState(null),[n,i]=p.useState(null),[r,c]=p.useState(""),[m,o]=p.useState(null),[f,x]=p.useState(!1);p.useEffect(()=>{fetch("/api/swagger.json").then(a=>a.ok?a.json():Promise.reject(a.statusText)).then(a=>s(a)).catch(a=>i(String(a)))},[]),p.useEffect(()=>{fetch("/api/undocumented.json").then(a=>a.ok?a.json():null).then(a=>a&&o(a)).catch(()=>{})},[]);const y=p.useMemo(()=>{var l;if(!(t!=null&&t.paths))return{};const a=[];for(const[u,v]of Object.entries(t.paths))for(const[N,w]of Object.entries(v)){const T=N.toUpperCase();if(!["GET","POST","PUT","PATCH","DELETE"].includes(T))continue;const E=Array.isArray(w.tags)?w.tags[0]:void 0;a.push({method:T,path:u,summary:w.summary||w.operationId,description:w.description,tag:E,meta:w})}const d={};for(const u of a){const v=u.tag||"General";d[v]||(d[v]=[]),d[v].push(u)}if((l=m==null?void 0:m.endpoints)!=null&&l.length){const u=N=>`${N.method}:${N.path}`,v=new Set(a.map(u));for(const N of m.endpoints){const w=u(N);if(v.has(w))continue;const T=N.tag||"Undocumented";d[T]||(d[T]=[]),d[T].push({...N,meta:{}})}}for(const u of Object.keys(d))d[u].sort((v,N)=>v.path.localeCompare(N.path));return d},[t,m]),h=p.useMemo(()=>{const a=Object.keys(y);if(!(t!=null&&t.tags))return a;const d=t.tags.map(l=>l.name);return[...d.filter(l=>a.includes(l)),...a.filter(l=>!d.includes(l))]},[t,y]);return e.jsxs("div",{className:"min-h-screen bg-white",children:[e.jsx("header",{className:"api-topbar",children:e.jsxs("div",{className:"container-narrow py-3 flex items-center justify-between gap-3",children:[e.jsxs("a",{href:"/",className:"flex items-center gap-2 select-none min-w-0",children:[e.jsx("span",{className:"logo-font-poiret text-lg text-gray-900",children:"Scriberr"}),e.jsx("span",{className:"text-gray-300",children:"/"}),e.jsx("span",{className:"text-sm text-gray-600",children:"API Reference"})]}),e.jsxs("div",{className:"flex items-center gap-2 w-full sm:w-auto",children:[e.jsx("input",{placeholder:"Search endpoints",value:r,onChange:a=>c(a.target.value),className:"w-full sm:w-56 rounded-md border border-gray-300 bg-white px-3 py-1.5 text-sm outline-none focus:ring-2 focus:ring-gray-300"}),e.jsx("button",{className:"sm:hidden inline-flex items-center justify-center rounded-md border border-gray-200 bg-white px-2.5 py-1.5 text-gray-700 hover:bg-gray-50",onClick:()=>x(a=>!a),"aria-label":"Toggle tags",children:e.jsx("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",className:"size-5",children:e.jsx("path",{d:"M4 7h16M4 12h16M4 17h16"})})}),e.jsx("div",{className:"hidden md:block",children:e.jsx(Z,{})})]})]})}),e.jsxs("main",{className:"container-narrow py-10",children:[f&&e.jsxs("div",{className:"sm:hidden mb-4 border border-gray-200 rounded-lg p-3",children:[e.jsx("div",{className:"text-[11px] font-medium text-gray-500 mb-2",children:"Tags"}),e.jsx("ul",{className:"grid grid-cols-2 gap-2 text-sm",children:h.length>0?h.map(a=>e.jsx("li",{children:e.jsx("a",{href:`#tag-${encodeURIComponent(a)}`,className:"text-gray-700 hover:text-gray-900",onClick:()=>x(!1),children:a})},`m-${a}`)):e.jsx("li",{className:"text-gray-400",children:"Loading tags…"})})]}),n&&e.jsxs("p",{className:"text-red-600",children:["Failed to load: ",n]}),e.jsxs("div",{className:"mb-10",children:[e.jsx("h1",{className:"text-[28px] font-semibold tracking-tight text-gray-900",children:((S=t==null?void 0:t.info)==null?void 0:S.title)||"Scriberr API"}),e.jsxs("div",{className:"mt-1 text-sm text-gray-600",children:["Version ",(($=t==null?void 0:t.info)==null?void 0:$.version)||"1.0.0"]}),t&&e.jsx(re,{doc:t})]}),e.jsx(ne,{}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-[240px_minmax(0,1fr)] gap-8 mt-10",children:[e.jsx("aside",{className:"api-sidebar",children:e.jsxs("div",{className:"sticky top-24 pr-6",children:[e.jsx("div",{className:"text-[11px] font-medium text-gray-500 mb-2",children:"Tags"}),e.jsx("ul",{className:"space-y-2 text-sm min-h-[200px]",children:h.length>0?h.map(a=>e.jsx("li",{children:e.jsx("a",{href:`#tag-${encodeURIComponent(a)}`,className:"text-gray-600 hover:text-gray-900",children:a})},a)):e.jsx("li",{className:"text-gray-400",children:"Loading tags…"})})]})}),e.jsx("div",{children:e.jsx("section",{className:"space-y-12",children:t?h.map(a=>{const d=(y[a]||[]).filter(l=>{const u=r.trim().toLowerCase();return u?l.path.toLowerCase().includes(u)||l.method.toLowerCase().includes(u)||(l.summary||"").toLowerCase().includes(u)||(l.description||"").toLowerCase().includes(u):!0});return d.length?e.jsxs("div",{id:`tag-${a}`,children:[e.jsx("h2",{className:"text-base font-semibold mb-3 text-gray-900",children:a}),e.jsx("div",{className:"space-y-4",children:d.map(l=>e.jsx(ae,{ep:l,doc:t},`${l.method}-${l.path}`))})]},a):null}):e.jsx("div",{className:"text-gray-500",children:"Loading API…"})})})]})]})]})}function re({doc:t}){var r;const s=typeof window<"u"?window.location:{protocol:"http:",host:"localhost:8080"},n=t.basePath||"",i=t.openapi?Array.isArray(t.servers)&&((r=t.servers[0])==null?void 0:r.url)||`${s.protocol}//${s.host}`:`${s.protocol}//${t.host||s.host}${n}`;return e.jsxs("div",{className:"mt-2 text-sm text-gray-600",children:["Base URL: ",e.jsx("code",{className:"text-gray-900",children:i})]})}function ne(){const s=`${typeof window<"u"?window.location.origin:"http://localhost:8080"}/api/v1`,n=["curl -X POST",`'${s}/auth/login'`,"-H 'Content-Type: application/json'",`-d '{"username":"alice","password":"your-password"}'`].join(" "),i=["curl -X GET",`'${s}/transcription/list'`,"-H 'Authorization: Bearer YOUR_JWT'"].join(" "),r=["curl -X GET",`'${s}/transcription/list'`,"-H 'X-API-Key: YOUR_API_KEY'"].join(" ");return e.jsx("section",{className:"container-narrow",children:e.jsxs("div",{className:"grid md:grid-cols-2 gap-6",children:[e.jsxs("article",{className:"api-card",children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-900",children:"Authentication"}),e.jsxs("p",{className:"text-sm text-gray-600 mt-2",children:["Protected endpoints accept either a Bearer JWT in the ",e.jsx("code",{children:"Authorization"})," header or an API key via the ",e.jsx("code",{children:"X-API-Key"})," header. Some endpoints require JWT specifically (user account and LLM config)."]}),e.jsxs("ul",{className:"list-disc pl-5 text-sm text-gray-600 mt-2",children:[e.jsxs("li",{children:["JWT-only: ",e.jsx("code",{children:"/auth/change-password"}),", ",e.jsx("code",{children:"/auth/change-username"}),", ",e.jsx("code",{children:"/api-keys"}),", ",e.jsx("code",{children:"/llm/config"})]}),e.jsx("li",{children:"API key or JWT: transcription, chat, notes, summaries, summarize, admin"})]})]}),e.jsxs("article",{className:"api-card",children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-900",children:"Get a JWT"}),e.jsx("p",{className:"text-sm text-gray-600 mt-2",children:"Authenticate and use the token with the Authorization header."}),e.jsx("div",{className:"mt-3",children:e.jsx(B,{curl:n,js:I(n),wrap:!0})})]}),e.jsxs("article",{className:"api-card md:col-span-1",children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-900",children:"Use JWT"}),e.jsx("div",{className:"mt-3",children:e.jsx(B,{curl:i,js:I(i),wrap:!0})})]}),e.jsxs("article",{className:"api-card md:col-span-1",children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-900",children:"Use API Key"}),e.jsx("div",{className:"mt-3",children:e.jsx(B,{curl:r,js:I(r),wrap:!0})})]})]})})}function ae({ep:t,doc:s}){var T,E,J,M,q;const n=p.useMemo(()=>oe(`${t.method}-${t.path}`),[t.method,t.path]),[i,r]=p.useState(!1),[c,m]=p.useState(!1),[o,f]=p.useState(!1),x=Array.isArray((T=t.meta)==null?void 0:T.parameters)?t.meta.parameters:[],y=(E=t.meta)==null?void 0:E.requestBody,h=((J=t.meta)==null?void 0:J.responses)||{},S=p.useMemo(()=>{var R;const j=Array.isArray((R=t.meta)==null?void 0:R.security)?t.meta.security:[],A=[];for(const k of j)k&&typeof k=="object"&&A.push(...Object.keys(k));return[...new Set(A)]},[t.meta]),$=s.securityDefinitions||((M=s.components)==null?void 0:M.securitySchemes)||{},a=le(y,s)||de(t.meta),d=a&&Object.keys(a.content||{})[0],l=d?(q=a.content[d])==null?void 0:q.schema:void 0,u=l?O(l,s.components,s.definitions):void 0,v=S[0],N=ue(v,$),w=me(t.method,t.path,d,u,N,x);return e.jsxs("article",{id:n,className:"api-card",children:[e.jsx("button",{onClick:()=>r(j=>!j),className:"w-full text-left",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(ie,{method:t.method}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"text-sm text-gray-900 truncate",children:t.path}),e.jsx("a",{href:`#${n}`,title:"Permalink",className:"ml-auto text-gray-400 hover:text-gray-700",children:"#"})]}),t.summary&&e.jsx("div",{className:"text-[13px] text-gray-600 mt-0.5 truncate",children:t.summary})]})]})}),i&&e.jsxs("div",{className:"pt-4",children:[t.description&&e.jsx("p",{className:"text-sm text-gray-600",children:t.description}),!!S.length&&e.jsxs("div",{className:"mt-3 text-xs text-gray-600 flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"text-gray-500",children:"Auth:"}),S.map(j=>e.jsx(pe,{name:j,def:$==null?void 0:$[j]},j))]}),!!x.length&&e.jsxs("div",{className:"mt-4",children:[e.jsx("h4",{className:"api-section-title mb-2",children:"Parameters"}),e.jsx(ce,{params:c?x:x.slice(0,8)}),x.length>8&&e.jsx("button",{onClick:()=>m(j=>!j),className:"mt-2 text-xs text-gray-600 hover:text-gray-900",children:c?"Show less":`Show all ${x.length} parameters`})]}),l&&e.jsxs("div",{className:"mt-3",children:[e.jsxs("h4",{className:"api-section-title mb-2",children:["Request Body ",e.jsxs("span",{className:"text-gray-500",children:["(",d,")"]})]}),e.jsx(P,{text:L(u)})]}),h&&Object.keys(h).length>0&&e.jsxs("div",{className:"mt-3",children:[e.jsx("h4",{className:"api-section-title mb-2",children:"Response"}),(()=>{var W;const j=Object.entries(h),A=j.findIndex(([C])=>C==="200"),R=j[A>=0?A:0],k=j.filter((C,g)=>g!==(A>=0?A:0)),[D,b]=R,z=(b==null?void 0:b.content)||{},G=Object.keys(z)[0],H=G?(W=z[G])==null?void 0:W.schema:b==null?void 0:b.schema,V=H?O(H,s.components,s.definitions):(b==null?void 0:b.description)||"";return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"rounded-md border border-gray-200 p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-gray-600 mb-2",children:[e.jsxs("span",{className:"status-pill",children:["HTTP ",D]}),(b==null?void 0:b.description)&&e.jsx("span",{children:b.description})]}),e.jsx(P,{text:L(V)})]}),k.length>0&&e.jsx("button",{onClick:()=>f(C=>!C),className:"mt-2 text-xs text-gray-600 hover:text-gray-900",children:o?"Hide other responses":`Show ${k.length} more`}),o&&e.jsx("div",{className:"space-y-2 mt-2",children:k.map(([C,g])=>{var F;const K=(g==null?void 0:g.content)||{},_=Object.keys(K)[0],X=_?(F=K[_])==null?void 0:F.schema:g==null?void 0:g.schema,Q=X?O(X,s.components,s.definitions):(g==null?void 0:g.description)||"";return e.jsxs("div",{className:"rounded-md border border-gray-200 p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-gray-600 mb-2",children:[e.jsxs("span",{className:"status-pill",children:["HTTP ",C]}),(g==null?void 0:g.description)&&e.jsx("span",{children:g.description})]}),e.jsx(P,{text:L(Q)})]},C)})})]})})()]}),e.jsxs("div",{className:"mt-3",children:[e.jsx("h4",{className:"api-section-title mb-2",children:"Examples"}),e.jsx(B,{curl:w,js:I(w)})]})]})]})}function P({text:t,wrap:s}){const n=typeof t=="string"?t:JSON.stringify(t,null,2),[i,r]=p.useState(!1);return e.jsxs("div",{className:"relative",children:[e.jsx("pre",{className:`codeblock ${s?"codeblock-wrap":""}`,children:e.jsx("code",{children:n})}),e.jsx("button",{onClick:()=>{navigator.clipboard.writeText(n).then(()=>{r(!0),setTimeout(()=>r(!1),1200)})},className:"absolute top-2 right-2 inline-flex items-center gap-2 rounded-md border border-gray-300 bg-white text-gray-700 px-2 py-1 text-[11px] hover:bg-gray-50",children:i?"Copied":"Copy"})]})}function B({curl:t,js:s,wrap:n}){const[i,r]=p.useState("curl");return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-2 inline-flex rounded-md border border-gray-200 bg-white p-0.5 text-xs",children:[e.jsx("button",{onClick:()=>r("curl"),className:`px-2 py-1 rounded ${i==="curl"?"bg-gray-100 text-gray-900":"text-gray-600"}`,children:"cURL"}),e.jsx("button",{onClick:()=>r("js"),className:`px-2 py-1 rounded ${i==="js"?"bg-gray-100 text-gray-900":"text-gray-600"}`,children:"JavaScript"})]}),i==="curl"?e.jsx(P,{text:t,wrap:n}):e.jsx(P,{text:s,wrap:n})]})}function ie({method:t}){const n={GET:"bg-emerald-50 text-emerald-700 ring-emerald-200",POST:"bg-blue-50 text-blue-700 ring-blue-200",PUT:"bg-amber-50 text-amber-700 ring-amber-200",PATCH:"bg-cyan-50 text-cyan-700 ring-cyan-200",DELETE:"bg-rose-50 text-rose-700 ring-rose-200"}[t]||"bg-gray-100 text-gray-700 ring-gray-200";return e.jsx("span",{className:`pill ${n} min-w-[54px] text-center`,children:t})}function ce({params:t}){const s={path:[],query:[],header:[],cookie:[],body:[]};for(const i of t){const r=(i.in||"other").toLowerCase();s[r]||(s[r]=[]),s[r].push(i)}const n=["path","query","header","cookie"];return e.jsx("div",{className:"space-y-3",children:n.map(i=>s[i]&&s[i].length?e.jsxs("div",{children:[e.jsxs("div",{className:"text-[11px] font-medium text-gray-500 mb-1",children:[i.charAt(0).toUpperCase()+i.slice(1)," parameters"]}),e.jsx("ul",{className:"space-y-1",children:s[i].map(r=>{const c=r.schema||{},m=c.type||(c.$ref?U(c.$ref):r.type||""),o=[];(c.default!==void 0||r.default!==void 0)&&o.push(`default: ${c.default??r.default}`),c.enum&&o.push(`enum: ${(c.enum||[]).join(", ")}`);const f=[r.description,...o].filter(Boolean).join(" — ");return e.jsxs("li",{className:"text-xs text-gray-700",children:[e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx("code",{className:"px-1 py-0.5 rounded bg-gray-100 border border-gray-200 text-gray-900",children:r.name}),e.jsx("span",{className:"text-gray-500",children:m}),r.required&&e.jsx("span",{className:"text-gray-500",children:"• required"})]}),f&&e.jsxs("span",{className:"text-gray-600",children:[" — ",f]})]},`${r.name}-${r.in}`)})})]},i):null)})}function oe(t){return t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/(^-|-$)/g,"")}function U(t){const s=t.match(/#\/(components\/(schemas|requestBodies)|definitions)\/(.+)$/);return s?s[s.length-1]:t}function Y(t,s,n){var r,c;if(!t||!t.$ref)return t;const i=U(t.$ref);return((r=s==null?void 0:s.schemas)==null?void 0:r[i])||((c=s==null?void 0:s.requestBodies)==null?void 0:c[i])||(n==null?void 0:n[i])||t}function le(t,s){if(t)return t.$ref?Y(t,s.components,s.definitions):t}function de(t){if(!(t!=null&&t.parameters))return;const s=t.parameters.find(n=>n.in==="body");if(s)return{content:{"application/json":{schema:s.schema||{}}}}}function O(t,s,n,i=0,r=new Set){if(!t)return"";if(i>8)return"…";if(t.example!==void 0)return t.example;if(t.$ref){const m=t.$ref,o=U(m);return r.has(o)?`{circular:${o}}`:(r.add(o),O(Y(t,s,n),s,n,i+1,r))}const c=t.type;if(t.examples&&Array.isArray(t.examples)&&t.examples.length)return t.examples[0];if(c==="object"||t.properties&&typeof t.properties=="object"){const m={},o=t.properties||{};let f=0;for(const[x,y]of Object.entries(o))if(m[x]=O(y,s,n,i+1,r),++f>15)break;return m}if(c==="array")return[O(t.items||{},s,n,i+1,r)];if(t.enum&&Array.isArray(t.enum))return t.enum[0];switch(c){case"integer":case"number":return 123;case"boolean":return!0;case"string":default:return(t==null?void 0:t.format)==="date-time"?new Date().toISOString():"string"}}function L(t){if(typeof t=="string")return t;try{return JSON.stringify(t,null,2)}catch{return String(t)}}function me(t,s,n,i,r,c){const m=typeof window<"u"?window.location.origin:"http://localhost:8080",o=(c||[]).filter(h=>h.in==="query"),f=t==="GET"&&o.length?"?"+o.map(h=>`${encodeURIComponent(h.name)}=${encodeURIComponent(ge(h))}`).join("&"):"",x=`${m}${s}${f}`,y=["curl","-X",t,`'${x}'`];if(r&&r.length)for(const h of r)y.push("-H",`'${h}'`);return n&&y.push("-H",`'Content-Type: ${n}'`),i!==void 0&&y.push("-d",`'${JSON.stringify(i)}'`),y.join(" ")}function I(t){try{const s=t.match(/-X\s+(GET|POST|PUT|PATCH|DELETE)/i),n=t.match(/'https?:[^']+'/),i=/-H\s+'([^']+)'/g,r=t.match(/-d\s+'([^']+)'/),c=s?s[1].toUpperCase():"GET",m=n?n[0].slice(1,-1):"",o={};let f;for(;(f=i.exec(t))!==null;){const[h,...S]=f[1].split(":"),$=S.join(":").trim();o[h.trim()]=$}const x=r?r[1]:void 0;return[`const res = await fetch('${m}', {`,` method: '${c}',`,Object.keys(o).length?` headers: ${JSON.stringify(o,null,2).replace(/\n/g,`
|
|
`).replace(/^/gm," ")},`:"",x?` body: ${xe(x)?`JSON.stringify(${he(x)})`:`'${x}'`},`:"","});","const data = await res.json();","console.log(data);"].filter(Boolean).join(`
|
|
`)}catch{return`// Could not convert to fetch.
|
|
// Original:
|
|
${t}`}}function xe(t){try{return JSON.parse(t),!0}catch{return!1}}function he(t){try{return JSON.parse(t)}catch{return t}}function ue(t,s={}){var i;if(!t||!s[t])return[];const n=s[t];if(n.type==="apiKey"){const r=n.name||((i=n.description)!=null&&i.includes("Authorization")?"Authorization":"X-API-Key");return r.toLowerCase()==="authorization"?["Authorization: Bearer YOUR_JWT"]:[`${r}: YOUR_API_KEY`]}return n.type==="http"&&n.scheme==="bearer"?["Authorization: Bearer YOUR_JWT"]:[]}function pe({name:t,def:s}){const n=s?s.type==="apiKey"?s.name==="Authorization"?"Bearer token":`${s.name} header`:s.type==="http"&&s.scheme==="bearer"?"Bearer token":t:t;return e.jsx("span",{className:"inline-flex items-center gap-1 rounded-full bg-gray-200 text-gray-800 px-2 py-0.5",children:n})}function ge(t){const s=t.schema||{};if(t.example!==void 0)return t.example;if(s.example!==void 0)return s.example;if(s.default!==void 0)return s.default;if(s.enum&&s.enum.length)return s.enum[0];switch(s.type||t.type){case"integer":case"number":return 1;case"boolean":return!0;case"string":default:return"value"}}const fe=ee(document.getElementById("root"));fe.render(e.jsx(te.StrictMode,{children:e.jsx(se,{})}));
|