"use strict";(()=>{vare={};e.id=8893,e.ids=[8893],e.modules={60818:e=>{e.exports=require("dotenv")},27825:e=>{e.exports=require("lodash")},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")},33873:e=>{e.exports=require("path")},34932:(e,s,a)=>{a.r(s),a.d(s,{config:()=>A,default:()=>R,routeModule:()=>g});varr={};a.r(r),a.d(r,{default:()=>N});vart=a(89947),i=a(2706),n=a(96762),l=a(51348),o=a.n(l),u=a(48225),d=a.n(u),c=a(6420),_=a.n(c),b=a(47670),p=a.n(b),S=a(51926),m=a.n(S),E=a(19261),f=a.n(E);letD=a(29021);a(33873);let{execSync:h}=a(79646);asyncfunctionN(e,s){if("POST"!==e.method)returns.json({msg:"Failed!"});leta=await_()(e,s,!0);if(!a)returns.json({success:!1,msg:"Unauthorized"});letr=awaito()("SELECT * FROM users WHERE id = ?",[a.id]),t=r?.[0],{db_name:i,db_slug:n,db_description:l,db_image:u,duplicate:c,keepUpdated:b,keepDataUpdated:S}=e.body;if(n.match(/[^a-zA-Z0-9-_]/))returns.json({success:!1,msg:"Input Error"});letE=`datasquirel_user_${a.id}_${n}`,h=awaitm()(`CREATE DATABASE IF NOT EXISTS \`${E}\` CHARACTER SET utf8mb4 COLLATE utf8mb4_bin`);if(!h?.affectedRows)returns.json({success:!1,msg:"Database Could Not be created!"});letN={user_id:a.id,db_name:i,db_slug:n,db_full_name:E,db_description:l,db_image:u};c&&b&&(N.active_clone="1",N.active_clone_parent_db=c),c&&S&&(N.active_data="1");letR=awaitp()({dbFullName:"datasquirel",tableName:"user_databases",data:N});if(R.insertId)try{lete=`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${a.id}/main.json`,r=JSON.parse(D.readFileSync(e,"utf8")),o={dbName:i,dbSlug:n,dbFullName:E,dbDescription:l,dbImage:u,tables:[]};if(c)try{lete=r.filter(e=>e.dbFullName===c)[0];o.tables=e.tables,b&&(o.childDatabase=!0,o.childDatabaseDbFullName=c,S&&(o.updateData=!0),e.childrenDatabases?e.childrenDatabases.push({dbFullName:E}):e.childrenDatabases=[{dbFullName:E}]);for(lete=0;e<o.tables.length;e++){lets=o.tables[e];awaitp()({dbFullName:"datasquirel",tableName:"user_database_tables",data:{user_id:a.id,db_id:R.insertId,db_slug:n,table_name:s.tableFullName,table_slug:s.tableName}})}}catch(e){d()({component:"/api/createUserDatabase/lines-117-159",message:e.message,user:a})}r.push(o),D.writeFileSync(`${e}`,JSON.stringify(r),"utf8"),c&&awaitf()({userId:a.id,targetDatabase:E});let_=awaitm()(`GRANT ALL PRIVILEGES ON ${E}.* TO '${process.env.DSQL_DB_FULL_ACCESS_USERNAME}'@'${process.env.DSQL_DB_TARGET_IP_ADDRESS||"%"}' WITH GRANT OPTION`);if(_.error)throwError(_.error);leth=awaitm()(`GRANT SELECT ON ${E}.* TO '${process.env.DSQL_DB_READ_ONLY_USERNAME}'@'${process.env.DSQL_DB_TARGET_IP_ADDRESS||"%"}'`);if(h.error)throwError(h.error);t?.mariadb_user&&t?.mariadb_pass&&awaitm()(`GRANT ALL PRIVILEGES ON ${E}.* TO '${t.mariadb_user}'@'${t.mariadb_host}'`),awaitm()("FLUSH PRIVILEGES"),s.json({success:!0})}catch(e){d()({component:"/api/createUserDatabase/main-catch-error",message:e.message,user:a}),s.json({success:!1,msg:"Database Files could not be written!"})}elses.json({success:!1,msg:"Database Could Not Be Recorded!"})}letR=(0,n.M)(r,"default"),A=(0,n.M)(r,"config"),g=newt.PagesAPIRouteModule({definition:{kind:i.A.PAGES_API,page:"/api/createUserDatabase",pathname:"/api/createUserDatabase",bundlePath:"",filename:""},userland:r})},6420:(e,s,a)=>{a(81630);letr=a(51348),t=a(72835),i=a(29021),n=a(31341);asyncfunctionl(e,s,a,l){let{keyCookieName:o,csrfCookieName:u}=n();if(!e.cookies?.[o]?.match(/./))returnnull;letd=t({encryptedString:e.cookies[o]});if(!d)returnnull;letc=JSON.parse(d);if(!c.csrf_k||a&&!e.headers["x-csrf-auth"]?.match(RegExp(`${c.csrf_k}`)))returnnull;let_=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!_)returnconsole.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(a&&!i.existsSync(`${_}/${c.csrf_