2025-02-08 16:40:20 +08:00
|
|
|
import{_ as g,G as m,a as i,c as n,b as t,m as u,x as h,n as w,t as k,D as S,d as l,F as C,h as T,i as _,e as $,j as f,a0 as E,g as x,z as M,v as V,f as D,w as A,k as R}from"./index-CzWvo_ZG.js";import{M as P}from"./message-J9x5bCHs.js";import{d as y}from"./dayjs.min-DCV570D8.js";import{L}from"./localeText-I-1K1Tno.js";const U={name:"RemoteServer",props:{server:Object},data(){return{active:!1,startTime:void 0,endTime:void 0,errorMsg:"",refreshing:!1}},methods:{async handshake(){this.active=!1,this.server.host&&this.server.apiKey&&(this.refreshing=!0,this.startTime=void 0,this.endTime=void 0,this.startTime=y(),await fetch(`${this.server.host}/api/handshake`,{headers:{"content-type":"application/json","wg-dashboard-apikey":this.server.apiKey},method:"GET",signal:AbortSignal.timeout(5e3)}).then(s=>{if(s.status===200)return s.json();throw new Error(s.statusText)}).then(()=>{this.endTime=y(),this.active=!0}).catch(s=>{this.active=!1,this.errorMsg=s}),this.refreshing=!1)},async connect(){await fetch(`${this.server.host}/api/authenticate`,{headers:{"content-type":"application/json","wg-dashboard-apikey":this.server.apiKey},body:JSON.stringify({host:window.location.hostname}),method:"POST",signal:AbortSignal.timeout(5e3)}).then(s=>s.json()).then(s=>{this.$emit("setActiveServer"),this.$router.push("/")})}},mounted(){this.handshake()},computed:{getHandshakeTime(){return this.startTime&&this.endTime?`${y().subtract(this.startTime).millisecond()}ms`:this.refreshing?m("Pinging..."):this.errorMsg?this.errorMsg:"N/A"}}},q={class:"card rounded-3"},B={class:"card-body"},j={class:"d-flex gap-3 w-100 remoteServerContainer"},O={class:"d-flex gap-3 align-items-center flex-grow-1"},G={class:"d-flex gap-3 align-items-center flex-grow-1"},N={class:"d-flex gap-2 button-group"},K={class:"card-footer gap-2 d-flex align-items-center"},z={key:0,class:"spin ms-auto text-primary-emphasis"};function W(s,e,d,c,a,p){return i(),n("div",q,[t("div",B,[t("div",j,[t("div",O,[e[7]||(e[7]=t("i",{class:"bi bi-server"},null,-1)),u(t("input",{class:"form-control form-control-sm",onBlur:e[0]||(e[0]=o=>this.handshake()),"onUpdate:modelValue":e[1]||(e[1]=o=>this.server.host=o),type:"url"},null,544),[[h,this.server.host]])]),t("div",G,[e[8]||(e[8]=t("i",{class:"bi bi-key-fill"},null,-1)),u(t("input",{class:"form-control form-control-sm",onBlur:e[2]||(e[2]=o=>this.handshake()),"onUpdate:modelValue":e[3]||(e[3]=o=>this.server.apiKey=o),type:"text"},null,544),[[h,this.server.apiKey]])]),t("div",N,[t("button",{onClick:e[4]||(e[4]=o=>this.$emit("delete")),class:"ms-auto btn btn-sm bg-danger-subtle text-danger-emphasis border-1 border-danger-subtle"},e[9]||(e[9]=[t("i",{class:"bi bi-trash"},null,-1)])),t("button",{onClick:e[5]||(e[5]=o=>this.connect()),class:w([{disabled:!this.active},"ms-auto btn btn-sm bg-success-subtle text-success-emphasis border-1 border-success-subtle"])},e[10]||(e[10]=[t("i",{class:"bi bi-arrow-right-circle"},null,-1)]),2)])])]),t("div",K,[t("span",{class:w(["dot ms-0 me-2",[this.active?"active":"inactive"]])},null,2),t("small",null,k(this.getHandshakeTime),1),this.refreshing?(i(),n("div",z,e[11]||(e[11]=[t("i",{class:"bi bi-arrow-clockwise"},null,-1)]))):(i(),n("a",{key:1,role:"button",onClick:e[6]||(e[6]=o=>this.handshake()),class:"text-primary-emphasis text-decoration-none ms-auto disabled"},e[12]||(e[12]=[t("i",{class:"bi bi-arrow-clockwise me"},null,-1)])))])])}const F=g(U,[["render",W],["__scopeId","data-v-ed7817c7"]]),H={name:"RemoteServerList",setup(){return{store:S()}},components:{LocaleText:L,RemoteServer:F}},J={class:"w-100 mt-3"},Z={class:"d-flex align-items-center mb-3"},Q={class:"mb-0"},X={class:"w-100 d-flex gap-3 flex-column p-3 border border-1 border-secondary-subtle rounded-3",style:{height:"400px","overflow-y":"scroll"}},Y={key:0,class:"text-muted m-auto"};function ee(s,e,d,c,a,p){const o=f("LocaleText"),v=f("RemoteServer");return i(),n("div",J,[t("div",Z,[t("h5",Q,[l(o,{t:"Server List"})]),t("button",{onClick:e[0]||(e[0]=b=>this.store.addCrossServerConfiguration()),class:"btn bg-primary-subtle text-primary-emphasis border-1 borde
|