"use strict";(()=>{vare={};e.id=8893,e.ids=[8893],e.modules={39908:e=>{e.exports=require("@moduletrace/datasquirel/dist/users/user-auth")},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")},55511:e=>{e.exports=require("crypto")},29021:e=>{e.exports=require("fs")},33873:e=>{e.exports=require("path")},8325:(e,a,s)=>{s.r(a),s.d(a,{config:()=>D,default:()=>_,routeModule:()=>E});varr={};s.r(r),s.d(r,{default:()=>A});vart=s(89947),i=s(2706),l=s(96762),n=s(29021),d=s.n(n),u=s(48786),o=s(67619),c=s(69842),b=s(98e3),m=s(14160),p=s(76856);asyncfunctionA(e,a){if("POST"!==e.method)returna.json({msg:"Failed!"});lets=await(0,c.A)(e,a,!0);if(!s)returna.json({success:!1,msg:"Unauthorized"});letr=await(0,u.A)("SELECT * FROM users WHERE id = ?",[s.id]),t=r?.[0],{db_name:i,db_slug:l,db_description:n,db_image:A,duplicate:_,keepUpdated:D,keepDataUpdated:E}=e.body;if(l.match(/[^a-zA-Z0-9-_]/))returna.json({success:!1,msg:"Input Error"});letS=`datasquirel_user_${s.id}_${l}`,f=await(0,m.A)(`CREATE DATABASE IF NOT EXISTS \`${S}\` CHARACTER SET utf8mb4 COLLATE utf8mb4_bin`);if(!f?.affectedRows)returna.json({success:!1,msg:"Database Could Not be created!"});letg={user_id:s.id,db_name:i,db_slug:l,db_full_name:S,db_description:n,db_image:A};_&&D&&(g.active_clone="1",g.active_clone_parent_db=_),_&&E&&(g.active_data="1");letN=await(0,b.A)({dbFullName:"datasquirel",tableName:"user_databases",data:g});if(N.insertId)try{lete=`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${s.id}/main.json`,r=JSON.parse(d().readFileSync(e,"utf8")),u={dbName:i,dbSlug:l,dbFullName:S,dbDescription:n,dbImage:A,tables:[]};if(_)try{lete=r.filter(e=>e.dbFullName===_)[0];u.tables=e.tables,D&&(u.childDatabase=!0,u.childDatabaseDbFullName=_,E&&(u.updateData=!0),e.childrenDatabases?e.childrenDatabases.push({dbFullName:S}):e.childrenDatabases=[{dbFullName:S}]);for(lete=0;e<u.tables.length;e++){leta=u.tables[e];await(0,b.A)({dbFullName:"datasquirel",tableName:"user_database_tables",data:{user_id:s.id,db_id:N.insertId,db_slug:l,table_name:a.tableFullName,table_slug:a.tableName}})}}catch(e){(0,o.A)({component:"/api/createUserDatabase/lines-117-159",message:e.message,user:s})}r.push(u),d().writeFileSync(`${e}`,JSON.stringify(r),"utf8"),_&&await(0,p.A)({userId:s.id,targetDatabase:S});letc=await(0,m.A)(`GRANT ALL PRIVILEGES ON ${S}.* TO '${process.env.DSQL_DB_FULL_ACCESS_USERNAME}'@'${process.env.DSQL_DB_TARGET_IP_ADDRESS||"%"}' WITH GRANT OPTION`);if(c.error)throwError(c.error);letf=await(0,m.A)(`GRANT SELECT ON ${S}.* TO '${process.env.DSQL_DB_READ_ONLY_USERNAME}'@'${process.env.DSQL_DB_TARGET_IP_ADDRESS||"%"}'`);if(f.error)throwError(f.error);t?.mariadb_user&&t?.mariadb_pass&&await(0,m.A)(`GRANT ALL PRIVILEGES ON ${S}.* TO '${t.mariadb_user}'@'${t.mariadb_host}'`),await(0,m.A)("FLUSH PRIVILEGES"),a.json({success:!0})}catch(e){(0,o.A)({component:"/api/createUserDatabase/main-catch-error",message:e.message,user:s}),a.json({success:!1,msg:"Database Files could not be written!"})}elsea.json({success:!1,msg:"Database Could Not Be Recorded!"})}let_=(0,l.M)(r,"default"),D=(0,l.M)(r,"config"),E=newt.PagesAPIRouteModule({definition:{kind:i.A.PAGES_API,page:"/api/createUserDatabase",pathname:"/api/createUserDatabase",bundlePath:"",filename:""},userland:r})},69842:(e,a,s)=>{s.d(a,{A:()=>i});varr=s(39908),t=s.n(r);asyncfunctioni(e,a,s){letr=t()({req:e,level:s?"deep":void0});returnconsole.log(r),r.payload}},14160:(e,a,s)=>{s.d(a,{A:()=>n});varr=s(29021),t=s.n(r),i=s(67619),l=s(47546);asyncfunctionn(e){leta;"production".match(/dev/)&&t().appendFileSync("./.tmp/sqlQuery.sql",e+"\n"+Date()+"\n\n\n","utf8");try{a=await(0,l.A)(e)}catch(e){(0,i.A)({component:"noDatabaseDbHandler",message:e.message}),console.log("ERROR in noDatabaseDbHandler =>",e.message)}returna||null}},47546:(e,a,s)=>{s.d(a,{A:()=>t});varr=s(7447);functiont(...e){leta=(0,r.A)();try{returnnewPromise((s,r)=>{a.query(...