"use strict";(()=>{vare={};e.id=7214,e.ids=[7214],e.modules={75600:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},72583:e=>{e.exports=require("sanitize-html")},9973:e=>{e.exports=require("serverless-mysql")},79428:e=>{e.exports=require("buffer")},79646:e=>{e.exports=require("child_process")},55511:e=>{e.exports=require("crypto")},29021:e=>{e.exports=require("fs")},81630:e=>{e.exports=require("http")},21820:e=>{e.exports=require("os")},33873:e=>{e.exports=require("path")},96762:(e,t)=>{Object.defineProperty(t,"M",{enumerable:!0,get:function(){returnfunctione(t,r){returnrint?t[r]:"then"int&&"function"==typeoft.then?t.then(t=>e(t,r)):"function"==typeoft&&"default"===r?t:void0}}})},29750:(e,t,r)=>{r.r(t),r.d(t,{config:()=>h,default:()=>E,routeModule:()=>y});vars={};r.r(s),r.d(s,{default:()=>g});varn=r(89947),a=r(2706),o=r(96762),i=r(33364),l=r.n(i),c=r(48225),u=r.n(c),p=r(6420),d=r.n(p),S=r(57638),_=r.n(S);letm=r(29021),f=r(21820);r(33873);let{execSync:D}=r(79646);asyncfunctiong(e,t){if("POST"!==e.method)returnt.json({msg:"Failed!"});letr=awaitd()(e,t,!0);if(!r)returnt.json({success:!1,msg:"Unauthorized"});let{id:s,db_name:n,db_slug:a,db_description:o,db_image:i,db_full_name:c,active_clone:p,active_clone_parent_db:S}=e.body;c?.match(/datasquirel_user_.*/)||t.json({success:!1,msg:"Unauthorized"});letg=`datasquirel_user_${r.id}_${a}`;if(awaitl()({dbFullName:"datasquirel",tableName:"user_databases",identifierColumnName:"id",identifierValue:s,data:{db_name:n,db_slug:a,db_description:o,db_image:i,db_full_name:g}}),c&&c!==g){console.log("Renaming Database");lete=f.platform().match(/win/i)?"'C:\\Program Files\\MySQL\\MySQL Server 8.0\\bin\\mysql.exe'":"mysql",t=f.platform().match(/win/i)?"'C:\\Program Files\\MySQL\\MySQL Server 8.0\\bin\\mysqldump.exe'":"mysqldump";try{await_()({queryString:`CREATE DATABASE \`${g}\` CHARACTER SET utf8mb4 COLLATE utf8mb4_bin`,database:c});letr={cwd:process.cwd()};f.platform().match(/win/i)&&(r.shell="bash.exe");lets=`${t} -u ${process.env.DSQL_DB_USERNAME} -h ${process.env.DSQL_DB_HOST} -p${process.env.DSQL_DB_PASSWORD}${c} > tmpDbFile.sql`;console.log(`updateUserDatabase.js exe => ${s}`),D(s,r),D(`${e} -u ${process.env.DSQL_DB_USERNAME} -h ${process.env.DSQL_DB_HOST} -p${process.env.DSQL_DB_PASSWORD}${g} < tmpDbFile.sql`,r),await_()({queryString:`DROP DATABASE \`${c}\``,database:c})}catch(e){u()({component:"/api/updateUserDatabase/lines-88-111",message:e.message,user:r})}}try{lete=`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${r.id}/main.json`,s=JSON.parse(m.readFileSync(e,"utf8")),l=s.filter(e=>e.dbFullName===c);if(l[0].dbName=n,l[0].dbFullName=g,l[0].dbDescription=o,l[0].dbImage=i,l[0].dbSlug=a,p){lete=s.filter(e=>e.dbFullName===l[0].childDatabaseDbFullName)[0],t=e.childrenDatabases?.find(e=>e.dbFullName===c);t&&(t.dbFullName=g)}m.writeFileSync(`${e}`,JSON.stringify(s),"utf8"),t.json({success:!0})}catch(e){u()({component:"/api/updateUserDatabase/main-catch-error",message:e.message,user:r}),t.json({success:!1,msg:"Database Files could not be written!"})}}letE=(0,o.M)(s,"default"),h=(0,o.M)(s,"config"),y=newn.PagesAPIRouteModule({definition:{kind:a.A.PAGES_API,page:"/api/updateUserDatabase",pathname:"/api/updateUserDatabase",bundlePath:"",filename:""},userland:s})},6420:(e,t,r)=>{r(81630);lets=r(51348),n=r(72835),a=r(29021),o=r(31341);asyncfunctioni(e,t,r,i){let{keyCookieName:l,csrfCookieName:c}=o();if(!e.cookies?.[l]?.match(/./))returnnull;letu=n({encryptedString:e.cookies[l]});if(!u)returnnull;letp=JSON.parse(u);if(!p.csrf_k||r&&!e.headers["x-csrf-auth"]?.match(RegExp(`${p.csrf_k}`)))returnnull;letd=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!d)returnconsole.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(r&&!a.existsSync(`${d}/${p.csrf_k}`))returnnull;if(0==p.verification_status&&!r){lete=awaits(`SELECT verification_status FROM users WHERE id='${p.id}'`);e&&e[0]&&1==e[0].verification_status&&t.setHeader("Set-Cookie",["user_refresh=1"])}returnp?.date&&Date.now()-p.date>6048