mirror of
https://github.com/wnlen/clash-for-linux.git
synced 2026-02-04 10:11:28 +08:00
1 line
5.0 KiB
JavaScript
1 line
5.0 KiB
JavaScript
import{$ as e,C as t,Et as n,G as r,H as i,J as a,N as o,P as s,Q as c,V as l,W as u,Z as d,_t as f,at as p,ct as m,ft as h,j as g,kt as _,pt as v,q as y,st as b,x,yt as S,z as C}from"./CwRUcIL4.js";import{s as w}from"./_v7-ePgP.js";import{i as T}from"./CIh0-pO9.js";import{n as E}from"./DQ_xW1ii.js";import{p as ee}from"./Dw7DszGx.js";import{t as te}from"./D3YKBdJv.js";var D=[];for(let e=0;e<256;++e)D.push((e+256).toString(16).slice(1));function O(e,t=0){return(D[e[t+0]]+D[e[t+1]]+D[e[t+2]]+D[e[t+3]]+`-`+D[e[t+4]]+D[e[t+5]]+`-`+D[e[t+6]]+D[e[t+7]]+`-`+D[e[t+8]]+D[e[t+9]]+`-`+D[e[t+10]]+D[e[t+11]]+D[e[t+12]]+D[e[t+13]]+D[e[t+14]]+D[e[t+15]]).toLowerCase()}var k,A=new Uint8Array(16);function j(){if(!k){if(typeof crypto>`u`||!crypto.getRandomValues)throw Error(`crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported`);k=crypto.getRandomValues.bind(crypto)}return k(A)}var M={randomUUID:typeof crypto<`u`&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function N(e,t,n){e||={};let r=e.random??e.rng?.()??j();if(r.length<16)throw Error(`Random bytes length must be >= 16`);if(r[6]=r[6]&15|64,r[8]=r[8]&63|128,t){if(n||=0,n<0||n+16>t.length)throw RangeError(`UUID byte range ${n}:${n+15} is out of buffer bounds`);for(let e=0;e<16;++e)t[n+e]=r[e];return t}return O(r)}function P(e,t,n){return M.randomUUID&&!t&&!e?M.randomUUID():N(e,t,n)}var F=P,I={class:`mx-auto flex h-full w-full max-w-screen-sm flex-col items-center justify-center gap-6 p-4`},L={class:`flex flex-col items-center gap-2`},R={class:`text-sm text-base-content/60`},z={class:`flex w-full flex-col gap-4`},B={class:`fieldset`},V={class:`label`,for:`url`},H={id:`defaultEndpoints`},U=[`value`],W=[`value`],G=[`value`],K=[`value`],q={class:`fieldset`},J={class:`label`,for:`secret`},Y={class:`grid w-full grid-cols-2 gap-4`},X=[`onClick`],Z={class:`truncate`},Q=e({__name:`setup`,setup(e){let{t:D}=x();g({title:u(()=>D(`setup`))});let O=s(),k=o(),A=t(),j=f({url:``,secret:``}),M=S(!1),N=u(()=>typeof window>`u`?``:window.__METACUBEXD_CONFIG__?.defaultBackendURL||`http://127.0.0.1:9090`),P=u(()=>typeof window>`u`?``:window.location.origin);function Q(e){A.setSelectedEndpoint(e),O.replace(`/overview`)}async function ne(e){let t=A.endpointList.find(t=>t.id===e);t&&await E(t.url,t.secret)&&Q(e)}async function $(){M.value=!0;try{let e=j.url,t=j.secret,n=ee(e);if(!await E(n,t)){M.value=!1;return}let r=F(),i=[...A.endpointList],a=i.find(e=>e.url===n);if(!a){A.setEndpointList([{id:r,url:n,secret:t},...i]),Q(r);return}a.secret=t,a.id=r,A.setEndpointList(i),Q(r)}finally{M.value=!1}}function re(e){A.removeEndpoint(e)}return p(async()=>{let e=k.query||(typeof window<`u`?new URLSearchParams(window.location.search):null);if(e&&typeof e==`object`){let t=e.hostname;if(t){j.url=`${e.http?`http:`:e.https?`https:`:typeof window<`u`?window.location.protocol:`http:`}//${t}${e.port?`:${e.port}`:``}`,j.secret=e.secret||``,await $();return}}A.endpointList.length===0&&(j.url=N.value,j.secret=``,await $())}),(e,t)=>{let o=te;return b(),a(`div`,I,[r(`div`,L,[t[2]||=r(`div`,{class:`text-3xl font-bold uppercase sm:text-4xl`},[r(`span`,{class:`bg-linear-to-br from-primary to-secondary bg-clip-text text-transparent`},` metacube `),r(`span`,null,`(`),r(`a`,{class:`inline-block text-primary transition-transform hover:scale-125 hover:rotate-90`,href:`https://github.com/metacubex/metacubexd`,target:`_blank`},` xd `),r(`span`,null,`)`)],-1),r(`p`,R,_(n(D)(`setupDescription`)),1)]),r(`form`,{class:`contents`,onSubmit:l($,[`prevent`])},[r(`div`,z,[r(`fieldset`,B,[r(`label`,V,[r(`span`,null,_(n(D)(`endpointURL`)),1)]),v(r(`input`,{id:`url`,"onUpdate:modelValue":t[0]||=e=>n(j).url=e,type:`url`,class:`input w-full`,placeholder:`http(s)://{hostname}:{port}`,list:`defaultEndpoints`,autocomplete:`on`},null,512),[[C,n(j).url]]),r(`datalist`,H,[r(`option`,{value:n(w)},null,8,U),n(N)&&n(N)!==n(`http://127.0.0.1:9090`)?(b(),a(`option`,{key:0,value:n(N)},null,8,W)):y(``,!0),n(P)&&n(P)!==n(`http://127.0.0.1:9090`)?(b(),a(`option`,{key:1,value:n(P)},null,8,G)):y(``,!0),(b(!0),a(i,null,m(n(A).endpointList,e=>(b(),a(`option`,{key:e.id,value:e.url},null,8,K))),128))])]),t[3]||=r(`input`,{type:`text`,name:`username`,autocomplete:`username`,class:`hidden`,"aria-hidden":`true`,tabindex:`-1`},null,-1),r(`fieldset`,q,[r(`label`,J,[r(`span`,null,_(n(D)(`secret`)),1)]),v(r(`input`,{id:`secret`,"onUpdate:modelValue":t[1]||=e=>n(j).secret=e,type:`password`,class:`input w-full`,placeholder:`secret`,autocomplete:`current-password`},null,512),[[C,n(j).secret]])]),c(o,{type:`submit`,class:`uppercase btn-primary`,loading:n(M)},{default:h(()=>[d(_(n(D)(`add`)),1)]),_:1},8,[`loading`])])],32),r(`div`,Y,[(b(!0),a(i,null,m(n(A).endpointList,e=>(b(),a(`div`,{key:e.id,class:`badge flex w-full cursor-pointer items-center justify-between gap-4 py-4 badge-info`,onClick:t=>ne(e.id)},[r(`span`,Z,_(e.url),1),c(o,{class:`btn-circle text-white btn-ghost btn-xs`,onClick:l(t=>re(e.id),[`stop`])},{default:h(()=>[c(n(T))]),_:1},8,[`onClick`])],8,X))),128))])])}}});export{Q as default}; |