"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,r)=>{r.r(s),r.d(s,{config:()=>R,default:()=>A,routeModule:()=>O});vara={};r.r(a),r.d(a,{default:()=>h});vart=r(89947),i=r(2706),n=r(96762),l=r(51348),u=r.n(l),o=r(48225),d=r.n(o),c=r(6420),_=r.n(c),p=r(47670),S=r.n(p),b=r(51926),m=r.n(b),E=r(19261),D=r.n(E);letf=r(29021);r(33873);let{execSync:N}=r(79646);asyncfunctionh(e,s){if("POST"!==e.method)returns.json({msg:"Failed!"});letr=await_()(e,s,!0);if(!r)returns.json({success:!1,msg:"Unauthorized"});leta=awaitu()("SELECT * FROM users WHERE id = ?",[r.id]),t=a?.[0],{db_name:i,db_slug:n,db_description:l,db_image:o,duplicate:c,keepUpdated:p,keepDataUpdated:b}=e.body;if(n.match(/[^a-zA-Z0-9-_]/))returns.json({success:!1,msg:"Input Error"});letE=`datasquirel_user_${r.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:r.id,db_name:i,db_slug:n,db_full_name:E,db_description:l,db_image:o};c&&p&&(h.active_clone="1",h.active_clone_parent_db=c),c&&b&&(h.active_data="1");letA=awaitS()({dbFullName:"datasquirel",tableName:"user_databases",data:h});if(A.insertId)try{lete=`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${r.id}/main.json`,a=JSON.parse(f.readFileSync(e,"utf8")),u={dbName:i,dbSlug:n,dbFullName:E,dbDescription:l,dbImage:o,tables:[]};if(c)try{lete=a.filter(e=>e.dbFullName===c)[0];u.tables=e.tables,p&&(u.childDatabase=!0,u.childDatabaseDbFullName=c,b&&(u.updateData=!0),e.childrenDatabases?e.childrenDatabases.push({dbFullName:E}):e.childrenDatabases=[{dbFullName:E}]);for(lete=0;e<u.tables.length;e++){lets=u.tables[e];awaitS()({dbFullName:"datasquirel",tableName:"user_database_tables",data:{user_id:r.id,db_id:A.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:r})}a.push(u),f.writeFileSync(`${e}`,JSON.stringify(a),"utf8"),c&&awaitD()({userId:r.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){d()({component:"/api/createUserDatabase/main-catch-error",message:e.message,user:r}),s.json({success:!1,msg:"Database Files could not be written!"})}elses.json({success:!1,msg:"Database Could Not Be Recorded!"})}letA=(0,n.M)(a,"default"),R=(0,n.M)(a,"config"),O=newt.PagesAPIRouteModule({definition:{kind:i.A.PAGES_API,page:"/api/createUserDatabase",pathname:"/api/createUserDatabase",bundlePath:"",filename:""},userland:a})},6420:(e,s,r)=>{r(81630);leta=r(51348),t=r(72835),i=r(29021),n=r(31341);asyncfunctionl(e,s,r,l){let{keyCookieName:u,csrfCookieName:o}=n();if(!e.cookies?.[u]?.match(/./))returnnull;letd=t({encryptedString:e.cookies[u]});if(!d)returnnull;letc=JSON.parse(d);if(!c.csrf_k||r&&!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(r&&!i.existsSync(`${_}/${c.csrf_