Files
WGDashboard/src/static/dist/WGDashboardAdmin/assets/signin-CWJBzqzY.js

2 lines
12 KiB
JavaScript
Raw Normal View History

import{_ as v,G as p,A as I,c as a,a as t,t as T,n as C,m as u,y as c,b as l,h as g,d as x,F as k,i as w,f as i,D as L,j as $,a1 as E,v as M,e as D,w as A,T as U,z as B,g as y}from"./index-B8BTG8Ck.js";import{M as R}from"./message-v6gYq2BV.js";import{d as _}from"./dayjs.min-DBUL_c4Y.js";import{L as S}from"./localeText-B8Zr5hW3.js";const O={name:"RemoteServer",components:{LocaleText:S},props:{server:Object},data(){return{active:!1,startTime:void 0,endTime:void 0,errorMsg:"",refreshing:!1}},methods:{addHeaders(){this.server.headers||(this.server.headers={}),this.server.headers[I().toString()]={key:"",value:""}},async handshake(){this.active=!1,this.server.host&&this.server.apiKey&&(this.refreshing=!0,this.startTime=void 0,this.endTime=void 0,this.startTime=_(),await fetch(`${this.server.host}/api/handshake`,{headers:this.getHeaders,method:"GET",signal:AbortSignal.timeout(5e3)}).then(s=>{if(s.status===200)return s.json();throw new Error(s.statusText)}).then(()=>{this.endTime=_(),this.active=!0}).catch(s=>{this.active=!1,this.errorMsg=s}),this.refreshing=!1)},async connect(){await fetch(`${this.server.host}/api/authenticate`,{headers:this.getHeaders,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?`${_().subtract(this.startTime).millisecond()}ms`:this.refreshing?p("Pinging..."):this.errorMsg?this.errorMsg:"N/A"},getHeaders(){let s={"Content-Type":"application/json","wg-dashboard-apikey":this.server.apiKey};if(this.server.headers)for(let e of Object.values(this.server.headers))e.key&&e.value&&!Object.keys(s).includes(e.key)&&(s[e.key]=e.value);return s}}},P={class:"card rounded-3"},j={class:"gap-2 d-flex align-items-center"},q={key:0,class:"spin ms-auto text-white"},H={class:"card-body"},G={class:"d-flex gap-2 w-100 remoteServerContainer flex-column"},N={class:"d-flex gap-3 align-items-center flex-grow-1"},K={class:"d-flex gap-3 align-items-center flex-grow-1"},z={class:"d-flex gap-2 button-group"},W={class:"card rounded-3"},F={class:"card-body d-flex gap-2 flex-column"},J={class:"d-flex gap-2"},Z={class:"flex-grow-1"},Q=["onUpdate:modelValue"],X={class:"flex-grow-1"},Y=["onUpdate:modelValue"],ee=["onClick"];function te(s,e,m,h,d,f){const r=g("LocaleText");return i(),a("div",P,[t("div",{class:C(["card-header",[this.active?"text-bg-success":"text-bg-danger"]])},[t("div",j,[e[12]||(e[12]=t("i",{class:"bi bi-person-walking"},null,-1)),t("small",null,T(this.getHandshakeTime),1),this.refreshing?(i(),a("div",q,[...e[10]||(e[10]=[t("i",{class:"bi bi-arrow-clockwise"},null,-1)])])):(i(),a("a",{key:1,role:"button",onClick:e[0]||(e[0]=n=>this.handshake()),class:"text-white text-decoration-none ms-auto disabled"},[...e[11]||(e[11]=[t("i",{class:"bi bi-arrow-clockwise me"},null,-1)])]))])],2),t("div",H,[t("div",G,[t("div",N,[e[13]||(e[13]=t("small",null,[t("i",{class:"bi bi-hdd-rack-fill"})],-1)),u(t("input",{class:"form-control form-control-sm rounded-3",onBlur:e[1]||(e[1]=n=>this.handshake()),"onUpdate:modelValue":e[2]||(e[2]=n=>this.server.host=n),type:"url"},null,544),[[c,this.server.host]])]),t("div",K,[e[14]||(e[14]=t("i",{class:"bi bi-key-fill"},null,-1)),u(t("input",{class:"form-control form-control-sm rounded-3 font-monospace",onBlur:e[3]||(e[3]=n=>this.handshake()),"onUpdate:modelValue":e[4]||(e[4]=n=>this.server.apiKey=n),type:"text"},null,544),[[c,this.server.apiKey]])]),t("div",z,[t("button",{style:{flex:"1 0 0"},onClick:e[5]||(e[5]=n=>this.$emit("delete")),class:"ms-auto btn btn-sm bg-danger-subtle text-danger-emphasis border-1 border-danger-subtle rounded-3"},[e[15]||(e[15]=t("i",{class:"bi bi-trash me-2"},null,-1)),l(r,{t:"Delete"})]),t("button",{style:{flex:"1 0 0"},onClick:e[6]||(e[6]=n=>this.connect()),class:C([{disabled:!this.active},"ms-auto btn btn-sm bg-success-subtle text-success-emphasis border-1 border-success-subtle rounded-3"])},[e[16]||(e[16]=t("i",{class:"bi bi-arrow-right-circle me