metacubexd/assets/Setup-CqaOhgQf.js
2024-09-14 16:15:03 +00:00

2 lines
3.6 KiB
JavaScript

import{u as q,a as H,b as M,c as N,v as T,o as X,e as p,d as G,i as o,f as h,g as J,S as K,B as C,I as O,F as Q,t as $,z as b,s as w,h as E,j as W,k as R,l as Y,m as Z,n as tt}from"./index-DWMGWNy8.js";var a=[];for(var y=0;y<256;++y)a.push((y+256).toString(16).slice(1));function et(t,n=0){return(a[t[n+0]]+a[t[n+1]]+a[t[n+2]]+a[t[n+3]]+"-"+a[t[n+4]]+a[t[n+5]]+"-"+a[t[n+6]]+a[t[n+7]]+"-"+a[t[n+8]]+a[t[n+9]]+"-"+a[t[n+10]]+a[t[n+11]]+a[t[n+12]]+a[t[n+13]]+a[t[n+14]]+a[t[n+15]]).toLowerCase()}var m,nt=new Uint8Array(16);function st(){if(!m&&(m=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!m))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return m(nt)}var at=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const L={randomUUID:at};function rt(t,n,x){if(L.randomUUID&&!n&&!t)return L.randomUUID();t=t||{};var l=t.random||(t.rng||st)();return l[6]=l[6]&15|64,l[8]=l[8]&63|128,et(l)}var lt=$("<option>"),it=$('<div class="mx-auto flex max-w-screen-sm flex-col items-center gap-4 py-10"><form class=contents><div class="flex w-full flex-col gap-4"><div class=flex-1><label class=label><span class=label-text></span></label><input name=url type=url class="input input-bordered w-full"placeholder=http(s)://{hostname}:{port} list=defaultEndpoints><datalist id=defaultEndpoints><option value=http://127.0.0.1:9090></option></datalist></div><div class=flex-1><label class=label><span class=label-text></span></label><input name=secret type=password class="input input-bordered w-full"placeholder=secret></div></div></form><div class="grid w-full grid-cols-2 gap-4">'),ot=$('<div class="badge badge-info flex w-full cursor-pointer items-center justify-between gap-4 py-4"><span class=truncate>');const ct=b.object({url:b.string().min(1),secret:b.string()}),ut=()=>{const[t]=q(),n=H(),x=M(),l=s=>{R(s),x("/overview")},_=(s,e)=>Z.get(s,{headers:e?{Authorization:`Bearer ${e}`}:{}}).then(({ok:r})=>r).catch(r=>{const{message:i}=r;E.error(i)}),I=async s=>{const e=p().find(r=>r.id===s);e&&await _(e.url,e.secret)&&l(s)},v=async({url:s,secret:e})=>{const r=tt(s);if(!await _(r,e))return;const i=rt(),c=p().slice(),d=c.find(f=>f.url===r);if(!d){w([{id:i,url:r,secret:e},...c]),l(i);return}d.secret=e,d.id=i,w(c),l(i)},k=s=>{const{message:e}=s;E.error(e)},{form:S}=N({extend:T({schema:ct}),onSubmit:v,onError:k}),D=s=>{W()===s&&R(""),w(p().filter(e=>e.id!==s))};return X(()=>{let s=n.search||window.location.search;if(s){const r=n.hash.match(/\?.*$/);Array.isArray(r)&&r[0]&&(s=r[0].replace("?",""))}const e=new URLSearchParams(s);e.has("hostname")?v({url:`${e.get("http")?"http:":e.get("https")?"https:":window.location.protocol}//${e.get("hostname")}${e.get("port")?`:${e.get("port")}`:""}`,secret:e.get("secret")??""}):p().length===0&&v({url:"http://127.0.0.1:9090",secret:""})}),(()=>{var s=it(),e=s.firstChild,r=e.firstChild,i=r.firstChild,c=i.firstChild,d=c.firstChild,f=c.nextSibling,U=f.nextSibling;U.firstChild;var j=i.nextSibling,A=j.firstChild,V=A.firstChild,B=e.nextSibling;return G(S,e,()=>S),o(d,()=>t("endpointURL")),o(U,h(K,{get when(){return window.location.origin!=="http://127.0.0.1:9090"},get children(){var u=lt();return J(()=>u.value=window.location.origin),u}}),null),o(V,()=>t("secret")),o(r,h(C,{type:"submit",class:"btn-primary uppercase",get children(){return t("add")}}),null),o(B,h(Q,{get each(){return p()},children:({id:u,url:F})=>(()=>{var g=ot(),z=g.firstChild;return g.$$click=()=>I(u),o(z,F),o(g,h(C,{class:"btn-circle btn-ghost btn-xs text-white",onClick:P=>{P.stopPropagation(),D(u)},get children(){return h(O,{})}}),null),g})()})),s})()};Y(["click"]);export{ut as default};