1import{d as O,f as q,p as n,G as l,k as c,y as _,u as a,af as R,I as j,F as v,L as f,C as u,av as z,r as i,P as G,c as F,aw as H,B as V,g as J,m as d}from"./vendor-D7HY6vXs.js";/* empty css */import{n as Q}from"./index-DAxIWTJb.js";import{u as W,c as m,m as I,r as S}from"./index-DBE2nJWm.js";import{u as X}from"./vendor-i18n-BAJQGTf1.js";import{U as Y}from"./UserAgentBlocks-Df6Z-aHy.js";import{A as Z}from"./Autocompletes-ymBfTEty.js";import{s as ee,e as se,i as te,f as k,c as ae,b as le}from"./vendor-servebolt-BwnDPTSW.js";import"./vendor-auth0-B88dyU-W.js";import"./vendor-toast-BA6wVAZy.js";const re={class:"max-w-[100%] md:max-w-[50%] md:min-w-[550px]"},oe={class:"mb-[50px] md:mb-[86px] flex flex-col"},ne={class:"mt-2 pt-5 w-full max-w-[700px]"},ie={class:"flex flex-col md:flex-row items-center pb-4 mb-4"},de={class:"flex-1 w-full flex flex-col"},ue={class:"flex-1"},ce={class:"error-msg"},me={class:"flex flex-col md:flex-row items-center pb-4 mb-4"},pe={class:"flex-1 w-full flex flex-col"},ve={class:"flex-1"},fe={class:"text-xs font-normal leading-none text-gray-500"},xe={class:"error-msg"},he={class:"flex flex-col md:flex-row items-center pb-4 mb-4"},ge={class:"flex-1 w-full flex flex-col"},be={class:"flex-1"},$e={class:"error-msg"},ye={class:"flex flex-col md:flex-row items-center pb-4 mb-4"},we={class:"flex-1 w-full flex flex-col"},Ae={class:"flex-1"},_e={class:"error-msg"},Fe={class:"flex-1 flex items-center mr-[24px] flex-row"},M="all",Ee=O({__name:"UserAgentCreateView",setup(Ve){const{t:h}=X({useScope:"global"}),g=H(),b=z(),x=i(),U=i(),p=i(!1),$=J(),y=b.state.accessTokenObject?.isServeboltAdmin||b.state.accessTokenObject?.isServeboltStaff,o=G({userAgent:i(""),serverId:i(M),reasonField:i(""),expirationField:i("")}),C=e=>e?e.split(` 2`).map(t=>t.trim()).filter(t=>t.length>0).every(t=>t.length<=500):!1,L=F(()=>({userAgent:{required:m.withMessage("The User Agent field cannot be empty",S),maxLength:m.withMessage("User Agent cannot be longer than 15000 characters.",I(15e3)),eachLineMaxLength:m.withMessage("Each line must be 500 characters or less.",C)},serverId:{serverIsValid:m.withMessage("Selected server is invalid",D)},reasonField:{required:m.withMessage("The reason cannot be empty",S),maxLength:m.withMessage("Reason cannot be longer than 128 characters.",I(128))},expirationField:{}})),r=W(L,o,{$lazy:!0}),T=i([{label:"1 hour",value:"1"},{label:"3 hours",value:"3"},{label:"24 hours",value:"24"},{label:"48 hours",value:"48"},{label:"3 days",value:"72"},{label:"7 days",value:"168"},{label:"14 days",value:"336"},{label:"Never",value:"0"}]),w=i([]),P=F(()=>o.userAgent&&o.serverId&&o.reasonField);q(()=>{B()});async function B(){try{const e=await new Z().getServers("",y);x.value=e.getData(),U.value=x.value.map(s=>s.hostname+" ("+s.ip+")"),w.value=e.getData().map(s=>({label:`${s.hostname}`,value:s.id}))}catch(e){console.error("Error loading servers:",e)}}function D(e){return e===null?!1:e===M?!0:x.value.map(t=>t.id).includes(e)}function E(){let e;if(e={},o.userAgent&&(e.userAgentList=o.userAgent.split(` 3`).map(s=>s.trim()).filter(s=>s.length>0)),typeof o.serverId=="number"&&(e.serverId=o.serverId),o.reasonField&&(e.reason=o.reasonField),o.expirationField){const s=parseInt(o.expirationField);s===0?delete e.expiresAt:e.expiresAt=s*3600}return{data:{attributes:e}}}async function A(e){if(e.preventDefault(),!!await a(r).$validate()){p.value=!0;try{const s=E();await new Y().create(s,y),await $?.appContext?.config?.globalProperties?.$servebolt.prompt.open({textParam:h("userAgentAdded"),typeParam:"confirm",iconNameParam:"active"}),g.push({name:"user-agent"})}catch(s){await $?.appContext?.config?.globalProperties?.$servebolt.prompt.open({titleParam:h("couldNotAddUserAgent"),textParam:Q(s.response),typeParam:"confirm"})}finally{p.value=!1}}}function K(){g.push({name:"user-agent"})}function N(e){e.key==="Enter"&&!e.shiftKey&&!(e.target instanceof HTMLTextAreaElement)&&A(e)}return(e,s)=>(d(),n("div",re,[l("div",oe,[c(a(ee),{class:"md:mt-0"},{default:_(()=>[V(u(e.$t("addUserAgent")),1)]),_:1}),c(a(se),{href:"https://webtools.docs.r99.no/docs/block-ips/"},{default:_(()=>[V(u(e.$t("documentation")),1)]),_:1})]),l("div",ne,[l("form",{onSubmit:j(A,["prevent"]),onKeyup:R(N,["enter"])},[l("div",ie,[l("div",de,[l("div",ue,[c(a(te),{type:"textarea",label:e.$t("userAgent"),maxlength:15e3,modelValue:a(r).userAgent.$model,"onUpdate:modelValue":s[0]||(s[0]=t=>
3a(r).userAgent.$model=t),invalid:a(r).userAgent.$invalid,placeholder:e.$t("userAgent")},null,8,["label","modelValue","invalid","placeholder"])]),(d(!0),n(v,null,f(a(r).userAgent.$errors,t=>(d(),n("div",{class:"text-invalid mx-2",key:t.$uid},[l("div",ce,u(t.$message),1)]))),128))])]),l("div",me,[l("div",pe,[l("div",ve,[c(a(k),{modelValue:a(r).serverId.$model,"onUpdate:modelValue":s[1]||(s[1]=t=>a(r).serverId.$model=t),invalid:a(r).serverId.$invalid,label:e.$t("server"),sid:"server",dataKey:"label",inputValue:"value",placeholder:e.$t("server"),searchable:"",options:w.value},null,8,["modelValue","invalid","label","placeholder","options"]),l("span",fe,u(e.$t("leaveEmptyToApplyBlockToAllServers")),1)]),(d(!0),n(v,null,f(a(r).serverId.$errors,t=>(d(),n("div",{class:"text-invalid",key:t.$uid},[l("div",xe,u(t.$message),1)]))),128))])]),l("div",he,[l("div",ge,[l("div",be,[c(a(ae),{modelValue:a(r).reasonField.$model,"onUpdate:modelValue":s[2]||(s[2]=t=>a(r).reasonField.$model=t),invalid:a(r).reasonField.$invalid,sid:"reason",onBlur:a(r).reasonField.$commit,placeholder:e.$t("reason"),label:e.$t("reason")},null,8,["modelValue","invalid","onBlur","placeholder","label"])]),(d(!0),n(v,null,f(a(r).reasonField.$errors,t=>(d(),n("div",{class:"text-invalid mx-2",key:t.$uid},[l("div",$e,u(t.$message),1)]))),128))])]),l("div",ye,[l("div",we,[l("div",Ae,[c(a(k),{modelValue:o.expirationField,"onUpdate:modelValue":s[3]||(s[3]=t=>o.expirationField=t),label:e.$t("expires"),sid:"expires",dataKey:"label",inputValue:"value",placeholder:e.$t("expires"),options:T.value},null,8,["modelValue","label","placeholder","options"])]),(d(!0),n(v,null,f(a(r).expirationField.$errors,t=>(d(),n("div",{class:"text-invalid",key:t.$uid},[l("div",_e,u(t.$message),1)]))),128))])]),l("div",Fe,[l("span",{onClick:K,class:"mr-2.5 cursor-pointer"},u(e.$t("back")),1),c(a(le),{size:"lg",type:"outline",btnType:"submit",disabled:!P.value||a(r).$invalid||p.value,text:p.value?e.$t("submitting"):e.$t("submit")},null,8,["disabled","text"])])],32)])]))}});export{Ee as default}; 4//# sourceMappingURL=UserAgentCreateView-DeVhxVbE.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.