%PDF- %PDF-
| Direktori : /home2/rezakur1/ai.rezakurnia.com/assets/ |
| Current File : //home2/rezakur1/ai.rezakurnia.com/assets/KeysPage-3glt5udb.js |
import{r as s,a as w,j as e,L as X}from"./index-Bu042oJp.js";import{B as i}from"./Button-CsqZL9Xc.js";import{C as $,a as O,b as T}from"./Card-TlRU04W7.js";import{B as Y}from"./Badge-BhTU663i.js";import{I as F}from"./Input-x6BCAoBW.js";import{M as C}from"./Modal-D2xuPxb5.js";import{d as W,e as ee}from"./format-CjhWL3Ta.js";import"./index-Cfl-v9NS.js";const R=10;function ae(){const[m,j]=s.useState([]),[c,u]=s.useState(0),[d,p]=s.useState(1),[x,f]=s.useState(!0),[S,B]=s.useState(null),[K,h]=s.useState(0),r=s.useCallback(()=>h(l=>l+1),[]);s.useEffect(()=>{let l=!1;return f(!0),w(`/me/keys?page=${d}&limit=${R}`).then(n=>{l||(j(n.keys),u(n.total))}).catch(n=>{l||B(n.message)}).finally(()=>{l||f(!1)}),()=>{l=!0}},[K,d]);const k=s.useCallback(async l=>{const n=await w("/me/keys",{method:"POST",body:{name:l}});return r(),n},[r]),P=s.useCallback(async l=>{await w(`/me/keys/${l}`,{method:"DELETE"}),r()},[r]),y=s.useCallback(async l=>{await w(`/me/keys/${l}/permanent`,{method:"DELETE"}),r()},[r]),b=Math.max(1,Math.ceil(c/R));return{keys:m,total:c,page:d,totalPages:b,setPage:p,loading:x,error:S,refresh:r,createKey:k,revokeKey:P,removePermanent:y}}function de(){const{keys:m,total:j,page:c,totalPages:u,setPage:d,loading:p,error:x,createKey:f,revokeKey:S,removePermanent:B}=ae(),[K,h]=s.useState(!1),[r,k]=s.useState(""),[P,y]=s.useState(!1),[b,l]=s.useState(null),[n,A]=s.useState(null),[q,E]=s.useState(!1),[D,g]=s.useState(null),[Z,_]=s.useState(!1),[t,N]=s.useState(null),[I,L]=s.useState(""),[M,H]=s.useState(!1),[z,v]=s.useState(null),J=a=>{N(a),L(""),v(null)},Q=async()=>{if(t){H(!0),v(null);try{await B(t.id),N(null),L(""),m.length===1&&c>1&&d(c-1)}catch(a){v(a instanceof Error?a.message:"Gagal menghapus key"),H(!1)}}},G=async()=>{const a=r.trim();if(!a){l("Nama key wajib diisi.");return}y(!0),l(null);try{const o=await f(a);h(!1),k(""),A(o),E(!1)}catch(o){l(o instanceof Error?o.message:"Gagal membuat key")}finally{y(!1)}},U=async()=>{if(n!=null&&n.key)try{await navigator.clipboard.writeText(n.key),E(!0),setTimeout(()=>E(!1),2e3)}catch{}},V=async()=>{if(D!=null){_(!0);try{await S(D),g(null)}catch(a){alert(a instanceof Error?a.message:"Gagal revoke key")}finally{_(!1)}}};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-bold tracking-tight text-white sm:text-2xl",children:"API Keys"}),e.jsx("p",{className:"mt-1 text-sm text-slate-500",children:"Buat dan kelola kunci API untuk mengakses gateway."})]}),e.jsxs(i,{onClick:()=>h(!0),children:[e.jsx("svg",{className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2.2,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 4.5v15m7.5-7.5h-15"})}),"Buat Key Baru"]})]}),e.jsxs($,{children:[e.jsx(O,{title:"Contoh Pemakaian",subtitle:"Ringkasan cara memakai API key di gateway"}),e.jsx(T,{children:e.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-end sm:justify-between",children:[e.jsxs("div",{className:"min-w-0 space-y-3",children:[e.jsxs("p",{className:"text-xs leading-relaxed text-slate-500",children:["Gunakan API key sebagai Bearer token pada header"," ",e.jsx("code",{className:"rounded bg-white/[0.06] px-1.5 py-0.5 font-mono text-[11px] text-brand-200",children:"Authorization"})," ","ke endpoint chat completions."]}),e.jsxs("div",{className:"inline-flex flex-wrap items-center gap-2 rounded-xl border border-white/[0.06] bg-ink-950/80 px-3 py-2",children:[e.jsx("span",{className:"inline-flex items-center rounded-md border border-blue-400/25 bg-blue-500/10 px-1.5 py-0.5 text-[10px] font-bold tracking-wide text-blue-300",children:"POST"}),e.jsx("code",{className:"font-mono text-[11px] text-white",children:"/v1/chat/completions"}),e.jsx("span",{className:"text-[10px] text-slate-600",children:"·"}),e.jsx("code",{className:"font-mono text-[10px] text-slate-500",children:"https://api.rezakurnia.com/v1"})]}),e.jsxs("div",{className:"flex flex-wrap gap-x-4 gap-y-1 text-[11px] text-slate-500",children:[e.jsxs("span",{children:["• ",e.jsx("span",{className:"text-red-300",children:"401"})," key salah / nonaktif"]}),e.jsxs("span",{children:["• ",e.jsx("span",{className:"text-amber-300",children:"402"})," saldo / kuota habis"]}),e.jsxs("span",{children:["• ",e.jsx("span",{className:"text-emerald-300",children:"200"})," sukses"]})]})]}),e.jsxs(X,{to:"/docs",className:"inline-flex shrink-0 items-center justify-center gap-2 rounded-xl bg-gradient-to-r from-blue-500 to-blue-600 px-4 py-2.5 text-xs font-semibold text-white transition-all hover:from-blue-400 hover:to-blue-500 active:scale-[0.98]",children:["Buka API Documentation",e.jsx("svg",{className:"h-3.5 w-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M13.5 4.5L21 12l-7.5 7.5M21 12H3"})})]})]})})]}),e.jsxs($,{children:[e.jsx(O,{title:"Daftar API Key",subtitle:"Key lengkap hanya terlihat satu kali saat dibuat"}),e.jsxs(T,{className:"p-0",children:[x&&e.jsxs("div",{className:"p-5 text-sm text-red-300",children:["Gagal memuat key: ",x]}),p&&!x&&e.jsx("div",{className:"space-y-3 p-5",children:[...Array(3)].map((a,o)=>e.jsx("div",{className:"h-16 animate-pulse rounded-xl bg-white/[0.02]"},o))}),!p&&!x&&m.length===0&&e.jsxs("div",{className:"px-5 py-12 text-center",children:[e.jsx("p",{className:"text-sm text-slate-400",children:"Belum ada API key."}),e.jsx("p",{className:"mt-1 text-xs text-slate-500",children:"Buat key pertama Anda untuk mulai memanggil model AI."})]}),!p&&!x&&m.length>0&&e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[680px] text-left text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-white/[0.06] bg-white/[0.02] text-[11px] uppercase tracking-wider text-slate-500",children:[e.jsx("th",{className:"px-5 py-3 font-semibold",children:"Nama"}),e.jsx("th",{className:"px-4 py-3 font-semibold",children:"Key Prefix"}),e.jsx("th",{className:"px-4 py-3 font-semibold",children:"Status"}),e.jsx("th",{className:"px-4 py-3 text-right font-semibold",children:"Saldo Kredit"}),e.jsx("th",{className:"px-4 py-3 font-semibold",children:"Dibuat"}),e.jsx("th",{className:"px-5 py-3 text-right font-semibold",children:"Aksi"})]})}),e.jsx("tbody",{children:m.map(a=>{const o=a.is_active===1;return e.jsxs("tr",{className:"border-b border-white/[0.04] transition-colors last:border-0 hover:bg-white/[0.02]",children:[e.jsx("td",{className:"px-5 py-3.5",children:e.jsx("p",{className:"font-medium text-white",children:a.name})}),e.jsx("td",{className:"px-4 py-3.5",children:e.jsx("span",{className:"font-mono text-xs text-slate-500",children:a.key_prefix})}),e.jsx("td",{className:"px-4 py-3.5",children:o?e.jsxs(Y,{tone:"success",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-emerald-400"}),"Aktif"]}):e.jsxs(Y,{tone:"danger",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-red-400"}),"Nonaktif"]})}),e.jsx("td",{className:"px-4 py-3.5 text-right font-medium tabular-nums text-slate-300",children:W(a.credit_balance)}),e.jsx("td",{className:"px-4 py-3.5 text-xs tabular-nums text-slate-500",children:ee(a.created_at)}),e.jsx("td",{className:"px-5 py-3.5 text-right",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[o?e.jsx(i,{variant:"danger",size:"sm",onClick:()=>g(a.id),children:"Revoke"}):e.jsx("span",{className:"text-xs text-slate-600",children:"—"}),e.jsx(i,{variant:"subtle",size:"sm",title:"Hapus key permanen dari akun",onClick:()=>J(a),className:"text-red-400 hover:bg-red-500/10 hover:text-red-300",children:"Hapus"})]})})]},a.id)})})]})})]})]}),j>R&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("p",{className:"text-xs text-slate-500",children:["Total ",j," key · Halaman ",c," dari ",u]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(i,{variant:"ghost",size:"sm",disabled:c<=1,onClick:()=>d(a=>Math.max(1,a-1)),children:"← Sebelumnya"}),e.jsx(i,{variant:"ghost",size:"sm",disabled:c>=u,onClick:()=>d(a=>Math.min(u,a+1)),children:"Berikutnya →"})]})]}),e.jsx(C,{open:K,onClose:()=>h(!1),title:"Buat API Key Baru",subtitle:"Beri nama yang jelas, mis. 'App Mobile' atau 'Server Prod'",children:e.jsxs("div",{className:"space-y-4",children:[b&&e.jsx("div",{className:"rounded-xl border border-red-500/25 bg-red-500/10 px-4 py-3 text-sm text-red-300",children:b}),e.jsx(F,{label:"Nama Key",placeholder:"cth: App Mobile",maxLength:100,value:r,onChange:a=>k(a.target.value),onKeyDown:a=>{a.key==="Enter"&&(a.preventDefault(),G())},autoFocus:!0}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(i,{variant:"ghost",onClick:()=>h(!1),children:"Batal"}),e.jsx(i,{isLoading:P,onClick:G,children:"Buat Key"})]})]})}),e.jsx(C,{open:!!n,onClose:()=>A(null),title:"API Key Berhasil Dibuat 🎉",subtitle:"Salin sekarang — key tidak akan tampil lagi setelah ditutup.",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"rounded-xl border border-amber-400/25 bg-amber-500/10 px-4 py-3 text-xs text-amber-200",children:"⚠️ Key lengkap hanya ditampilkan sekali. Simpan di tempat aman sebelum menutup jendela ini."}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"rounded-xl border border-white/[0.08] bg-ink-950/80 px-4 py-3 pr-24 font-mono text-xs text-brand-200 break-all",children:n==null?void 0:n.key}),e.jsx("button",{onClick:U,className:"absolute right-2 top-1/2 -translate-y-1/2 rounded-lg border border-white/[0.08] bg-white/[0.04] px-3 py-1.5 text-xs font-medium text-white transition hover:bg-white/[0.08]",children:q?"✓ Tersalin":"Salin"})]}),e.jsxs("div",{className:"flex items-center justify-between text-xs text-slate-500",children:[e.jsx("span",{className:"font-mono",children:n==null?void 0:n.key_prefix}),e.jsxs("span",{children:["Saldo:"," ",e.jsx("span",{className:"tabular-nums",children:n?W(n.credit_balance):"0.00"})]})]}),e.jsx(i,{className:"w-full",onClick:()=>A(null),children:"Saya sudah menyimpannya"})]})}),e.jsx(C,{open:!!t,onClose:()=>{M||N(null)},title:"Hapus API Key Permanen",subtitle:"Tindakan ini tidak dapat dibatalkan",width:"max-w-sm",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-xl border border-red-500/25 bg-red-500/10 px-4 py-3 text-xs leading-relaxed text-red-300",children:["Anda akan ",e.jsx("strong",{children:"menghapus permanen"})," key"," ",e.jsx("strong",{children:t==null?void 0:t.name})," (",e.jsxs("span",{className:"font-mono",children:[t==null?void 0:t.key_prefix,"…"]}),"). Key ini berhenti berfungsi dan riwayat pemakaiannya ikut terhapus."]}),e.jsx(F,{label:`Ketik nama key untuk konfirmasi: ${(t==null?void 0:t.name)??""}`,value:I,onChange:a=>{L(a.target.value),v(null)},placeholder:(t==null?void 0:t.name)??"",autoFocus:!0}),z&&e.jsx("p",{className:"text-xs font-medium text-red-400",children:z}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(i,{variant:"ghost",onClick:()=>N(null),disabled:M,children:"Batal"}),e.jsx(i,{variant:"danger",isLoading:M,disabled:I.trim()!==(t==null?void 0:t.name),onClick:Q,children:"Ya, Hapus"})]}),I.trim()!==(t==null?void 0:t.name)&&e.jsx("p",{className:"text-right text-[11px] text-slate-500",children:"Ketik nama key lengkap untuk mengaktifkan tombol."})]})}),e.jsx(C,{open:D!=null,onClose:()=>g(null),title:"Revoke API Key?",subtitle:"Key akan langsung nonaktif dan tidak bisa dipakai lagi.",width:"max-w-sm",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-sm text-slate-400",children:"Tindakan ini tidak bisa dibatalkan. Key yang di-revoke tetap tampil di daftar dengan status Nonaktif."}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(i,{variant:"ghost",onClick:()=>g(null),children:"Batal"}),e.jsx(i,{variant:"danger",isLoading:Z,onClick:V,children:"Ya, Revoke"})]})]})})]})}export{de as default};