"use strict";(()=>{vare={};e.id=8893,e.ids=[8893],e.modules={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,r,t)=>{t.r(r),t.d(r,{config:()=>R,default:()=>g,routeModule:()=>N});vara={};t.r(a),t.d(a,{default:()=>h});vars=t(89947),l=t(2706),n=t(96762),i=t(51348),o=t.n(i),u=t(77538),c=t.n(u),d=t(6420),p=t.n(d),m=t(47670),_=t.n(m),S=t(51926),b=t.n(S);letf=t(29021),E=t(33873),{execSync:D}=t(79646);asyncfunctionh(e,r){if("POST"!==e.method)returnr.json({msg:"Failed!"});lett=awaitp()(e,r,!0);if(!t)returnr.json({success:!1,msg:"Unauthorized"});leta=awaito()("SELECT * FROM users WHERE id = ?",[t.id]),s=a?.[0],{db_name:l,db_slug:n,db_description:i,db_image:u,duplicate:d,keepUpdated:m,keepDataUpdated:S}=e.body;if(n.match(/[^a-zA-Z0-9-_]/))returnr.json({success:!1,msg:"Input Error"});leth=`datasquirel_user_${t.id}_${n}`,g=awaitb()(`CREATE DATABASE IF NOT EXISTS \`${h}\` CHARACTER SET utf8mb4 COLLATE utf8mb4_bin`);if(!g?.affectedRows)returnr.json({success:!1,msg:"Database Could Not be created!"});letR={user_id:t.id,db_name:l,db_slug:n,db_full_name:h,db_description:i,db_image:u};d&&m&&(R.active_clone="1",R.active_clone_parent_db=d),d&&S&&(R.active_data="1");letN=await_()({dbFullName:"datasquirel",tableName:"user_databases",data:R});if(N.insertId)try{lete=`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${t.id}/main.json`,a=JSON.parse(f.readFileSync(e,"utf8")),o={dbName:l,dbSlug:n,dbFullName:h,dbDescription:i,dbImage:u,tables:[]};if(d)try{lete=a.filter(e=>e.dbFullName===d)[0];o.tables=e.tables,m&&(o.childDatabase=!0,o.childDatabaseDbFullName=d,S&&(o.updateData=!0),e.childrenDatabases?e.childrenDatabases.push({dbFullName:h}):e.childrenDatabases=[{dbFullName:h}]);for(lete=0;e<o.tables.length;e++){letr=o.tables[e];await_()({dbFullName:"datasquirel",tableName:"user_database_tables",data:{user_id:t.id,db_id:N.insertId,db_slug:n,table_name:r.tableFullName,table_slug:r.tableName}})}}catch(e){c()({component:"/api/createUserDatabase/lines-117-159",message:e.message,user:t})}if(a.push(o),f.writeFileSync(`${e}`,JSON.stringify(a),"utf8"),d){lete=E.join(process.cwd(),"/shell");D(`node createDbFromSchema.js --user ${t.id} --database ${h}`,{cwd:e})}letp=awaitb()(`GRANT ALL PRIVILEGES ON ${h}.* TO '${process.env.DSQL_DB_FULL_ACCESS_USERNAME}'@'${process.env.DSQL_DB_TARGET_IP_ADDRESS||"%"}' WITH GRANT OPTION`);if(p.error)throwError(p.error);letg=awaitb()(`GRANT SELECT ON ${h}.* TO '${process.env.DSQL_DB_READ_ONLY_USERNAME}'@'${process.env.DSQL_DB_TARGET_IP_ADDRESS||"%"}'`);if(g.error)throwError(g.error);s?.mariadb_user&&s?.mariadb_pass&&awaitb()(`GRANT ALL PRIVILEGES ON ${h}.* TO '${s.mariadb_user}'@'${s.mariadb_host}'`),awaitb()("FLUSH PRIVILEGES"),r.json({success:!0})}catch(e){c()({component:"/api/createUserDatabase/main-catch-error",message:e.message,user:t}),r.json({success:!1,msg:"Database Files could not be written!"})}elser.json({success:!1,msg:"Database Could Not Be Recorded!"})}letg=(0,n.M)(a,"default"),R=(0,n.M)(a,"config"),N=news.PagesAPIRouteModule({definition:{kind:l.A.PAGES_API,page:"/api/createUserDatabase",pathname:"/api/createUserDatabase",bundlePath:"",filename:""},userland:a})},77538:(e,r,t)=>{leta=t(29021),{IncomingMessage:s}=t(81630);e.exports=asyncfunction({user:e,message:r,component:t,noMail:s,req:l}){letn=newDate,i=(()=>{if(!l)returnnull;try{lete=l.headers["x-forwarded-for"],r=l.headers["x-real-ip"],t=l.headers["cf-connecting-ip"],a=Array.isArray(e)?e[0]:e?.split(",")[0],s=t||a||r||l.socket.remoteAddress;if(!s)returnnull;returnString(s)}catch(e){returnnull}})();try{lets=`🚀 SERVER ERROR ===========================