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

2 lines
14 KiB
JavaScript
Raw Normal View History

2026-06-26 20:22:50 +08:00
import{_ as x,G as v,A as D,c as i,a as t,t as V,n as T,m as p,y as b,b as a,h as g,d as _,F as $,i as w,f as r,D as E,j as C,$ as P,r as I,E as M,g as y,v as U,e as L,w as A,T as O,z as R}from"./index-DM7YJCOo.js";import{M as B}from"./message-BLvFM11v.js";import{d as S}from"./dayjs.min-DZl6XMNW.js";import{L as k}from"./localeText-BJvnc1lF.js";const j={name:"RemoteServer",components:{LocaleText:k},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[D().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=S(),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=S(),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?`${S().subtract(this.startTime).millisecond()}ms`:this.refreshing?v("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}}},q={class:"card rounded-3"},G={class:"gap-2 d-flex align-items-center"},H={key:0,class:"spin ms-auto text-white"},N={class:"card-body"},W={class:"d-flex gap-2 w-100 remoteServerContainer flex-column"},K={class:"d-flex gap-3 align-items-center flex-grow-1"},z={class:"d-flex gap-3 align-items-center flex-grow-1"},F={class:"d-flex gap-2 button-group"},J={class:"card rounded-3"},Q={class:"card-body d-flex gap-2 flex-column"},X={class:"d-flex gap-2"},Y={class:"flex-grow-1"},Z=["onUpdate:modelValue"],ee={class:"flex-grow-1"},te=["onUpdate:modelValue"],se=["onClick"];function oe(s,e,h,m,l,f){const o=g("LocaleText");return r(),i("div",q,[t("div",{class:T(["card-header",[this.active?"text-bg-success":"text-bg-danger"]])},[t("div",G,[e[12]||(e[12]=t("i",{class:"bi bi-person-walking"},null,-1)),t("small",null,V(this.getHandshakeTime),1),this.refreshing?(r(),i("div",H,[...e[10]||(e[10]=[t("i",{class:"bi bi-arrow-clockwise"},null,-1)])])):(r(),i("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",N,[t("div",W,[t("div",K,[e[13]||(e[13]=t("small",null,[t("i",{class:"bi bi-hdd-rack-fill"})],-1)),p(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),[[b,this.server.host]])]),t("div",z,[e[14]||(e[14]=t("i",{class:"bi bi-key-fill"},null,-1)),p(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),[[b,this.server.apiKey]])]),t("div",F,[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)),a(o,{t:"Delete"})]),t("button",{style:{flex:"1 0 0"},onClick:e[6]||(e[6]=n=>this.connect()),class:T([{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-