metacubexd/assets/Setup-afnxihz-.js

2 lines
3.7 KiB
JavaScript
Raw Normal View History

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