"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:()=>h});vart=a(89947),i=a(2706),n=a(96762),l=a(51348),o=a.n(l),u=a(48225),c=a.n(u),d=a(6420),_=a.n(d),p=a(47670),b=a.n(p),S=a(51926),m=a.n(S),E=a(19261),f=a.n(E);letD=a(29021);a(33873);let{execSync:N}=a(79646);asyncfunctionh(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:d,keepUpdated:p,keepDataUpdated:S}=e.body;if(n.match(/[^a-zA-Z0-9-_]/))returns.json({success:!1,msg:"Input Error"});letE=`datasquirel_user_${a.id}_${n}`,N=awaitm()(`CREATE DATABASE IF NOT EXISTS \`${E}\` CHARACTER SET utf8mb4 COLLATE utf8mb4_bin`);if(!N?.affectedRows)returns.json({success:!1,msg:"Database Could Not be created!"});leth={user_id:a.id,db_name:i,db_slug:n,db_full_name:E,db_description:l,db_image:u};d&&p&&(h.active_clone="1",h.active_clone_parent_db=d),d&&S&&(h.active_data="1");letR=awaitb()({dbFullName:"datasquirel",tableName:"user_databases",data:h});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(d)try{lete=r.filter(e=>e.dbFullName===d)[0];o.tables=e.tables,p&&(o.childDatabase=!0,o.childDatabaseDbFullName=d,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];awaitb()({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){c()({component:"/api/createUserDatabase/lines-117-159",message:e.message,user:a})}r.push(o),D.writeFileSync(`${e}`,JSON.stringify(r),"utf8"),d&&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);letN=awaitm()(`GRANT SELECT ON ${E}.* TO '${process.env.DSQL_DB_READ_ONLY_USERNAME}'@'${process.env.DSQL_DB_TARGET_IP_ADDRESS||"%"}'`);if(N.error)throwError(N.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){c()({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;letc=t({encryptedString:e.cookies[o]});if(!c)returnnull;letd=JSON.parse(c);if(!d.csrf_k||a&&!e.headers["x-csrf-auth"]?.match(RegExp(`${d.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(`${_}/${d.csrf_