import{m as o}from"./module.esm-uXcmRlT3.js";import{m as c}from"./module.esm-D2wLF7YV.js";const h="/install/api";async function n(r="GET",t,e={}){const s={method:r,headers:{"Content-Type":"application/json",Accept:"application/json"}};if(!(t instanceof URL))try{t=new URL(t)}catch{t=new URL((h+"/"+t).replace(/([^:]\/)\/+/g,"$1"),window.location.origin)}return e.params&&(Object.keys(e.params).forEach(i=>t.searchParams.append(i,e.params[i])),delete e.params),e={...s,...e},e.body&&(e.body instanceof FormData?delete e.headers["Content-Type"]:e.body instanceof URLSearchParams?e.headers["Content-Type"]="application/x-www-form-urlencoded":e.headers["Content-Type"]==="application/json"&&typeof e.body!="string"&&(e.body=JSON.stringify(e.body))),fetch(t,{...s,...e}).then(i=>{if(i.ok)return i;throw i})}function m(r,t={},e={}){return n("GET",r,{...e,params:t})}function d(r,t={},e={}){return n("POST",r,{...e,body:t})}function u(r,t={},e={}){return n("PUT",r,{...e,body:t})}function f(r,t){return n("DELETE",r,t)}const a={get:m,post:d,put:u,delete:f},p="68747470733a2f2f6170692e61696b6565646f2e636f6d2f6c6963656e736573";function g(r){let t="";for(let e=0;e<r.length;e+=2)t+=String.fromCharCode(parseInt(r.substr(e,2),16));return t}const l=g(p);function w(){o.data("installer",(r="dev",t=null)=>({step:"welcome",model:{license:null,db:{driver:"pdo_mysql",host:"localhost",port:3306,name:"aikeedo",user:null,password:null},account:{first_name:null,last_name:null,email:null,password:null},ratios:{token:1875e-7,image:2,audio:.2475},migrate:null,hasData:null},isProcessing:!1,requirements:null,error:null,init(){this.$refs.loading.remove()},view(e){this.error=null,this.step=e},viewRequirement(){this.isProcessing=!0,a.get("/requirements").then(e=>e.json()).then(e=>{this.isProcessing=!1,this.requirements=e,this.view(this.step=="requirements"&&this.requirements.is_satisfied?"license":"requirements")})},submitLicenseForm(){this.isProcessing=!0,this.error=null,fetch(`${l}/${this.model.license}`).then(async e=>{if(this.isProcessing=!1,e.ok){this.view("db");return}try{let s=await e.json();this.error=s.message||"Invalid license key"}catch{this.error="Unable to verify license key"}}).catch(e=>{this.isProcessing=!1,this.error="Unexpected error occurred! Please try again later.",console.error(e)})},submitDbForm(){this.isProcessing=!0,this.error=null,a.post("/database",this.model.db).then(e=>e.json()).then(e=>{this.isProcessing=!1,this.model.migrate=e.migrate,this.model.hasData=e.has_data,e.user&&(this.model.account.email=e.user.email,this.model.account.first_name=e.user.first_name,this.model.account.last_name=e.user.last_name),this.view(this.model.migrate?"migration":"account")}).catch(e=>{this.isProcessing=!1,this.error="Unexpected error occurred! Please try again later.",console.error(e),e.json().then(s=>this.error=s.message||this.error)})},async install(){this.isProcessing=!0;try{await a.post("/env",this.model),await a.post("/database/scheme",{migrate:this.model.migrate}),this.model.migrate||await a.post("/users",this.model.account),await a.post("/presets/import"),await a.post("/activate",{license:this.model.license})}catch(s){this.isProcessing=!1,this.error="Unexpected error occurred! Please try again later.",this.view("failure"),console.error(s),s.json().then(i=>this.error=i.message||this.error);return}let e=null;try{e=(await(await fetch("https://free.freeipapi.com/api/json/")).json()).ipAddress}catch(s){console.error(s)}try{await fetch(`${l}/${this.model.license}/activate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({license:this.model.license,domain:window.location.hostname,server_ip:t,client_ip:e,email:this.model.account.email,first_name:this.model.account.first_name,last_name:this.model.account.last_name,version:r})})}catch(s){console.error(s)}this.isProcessing=!1,this.view("success")}}))}w();o.plugin(c);o.start();
