"use strict";(()=>{vare={};e.id=8893,e.ids=[8893],e.modules={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")},33873:e=>{e.exports=require("path")},8325:(e,a,s)=>{s.r(a),s.d(a,{config:()=>p,default:()=>S,routeModule:()=>f});varr={};s.r(r),s.d(r,{default:()=>E});vart=s(89947),i=s(2706),n=s(96762),l=s(48786),u=s(67619),d=s(69842),o=s(98e3),c=s(14160),_=s(76856);letb=s(29021);s(33873);let{execSync:m}=s(79646);asyncfunctionE(e,a){if("POST"!==e.method)returna.json({msg:"Failed!"});lets=await(0,d.A)(e,a,!0);if(!s)returna.json({success:!1,msg:"Unauthorized"});letr=await(0,l.A)("SELECT * FROM users WHERE id = ?",[s.id]),t=r?.[0],{db_name:i,db_slug:n,db_description:m,db_image:E,duplicate:S,keepUpdated:p,keepDataUpdated:f}=e.body;if(n.match(/[^a-zA-Z0-9-_]/))returna.json({success:!1,msg:"Input Error"});letA=`datasquirel_user_${s.id}_${n}`,D=await(0,c.A)(`CREATE DATABASE IF NOT EXISTS \`${A}\` CHARACTER SET utf8mb4 COLLATE utf8mb4_bin`);if(!D?.affectedRows)returna.json({success:!1,msg:"Database Could Not be created!"});letN={user_id:s.id,db_name:i,db_slug:n,db_full_name:A,db_description:m,db_image:E};S&&p&&(N.active_clone="1",N.active_clone_parent_db=S),S&&f&&(N.active_data="1");letO=await(0,o.A)({dbFullName:"datasquirel",tableName:"user_databases",data:N});if(O.insertId)try{lete=`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${s.id}/main.json`,r=JSON.parse(b.readFileSync(e,"utf8")),l={dbName:i,dbSlug:n,dbFullName:A,dbDescription:m,dbImage:E,tables:[]};if(S)try{lete=r.filter(e=>e.dbFullName===S)[0];l.tables=e.tables,p&&(l.childDatabase=!0,l.childDatabaseDbFullName=S,f&&(l.updateData=!0),e.childrenDatabases?e.childrenDatabases.push({dbFullName:A}):e.childrenDatabases=[{dbFullName:A}]);for(lete=0;e<l.tables.length;e++){leta=l.tables[e];await(0,o.A)({dbFullName:"datasquirel",tableName:"user_database_tables",data:{user_id:s.id,db_id:O.insertId,db_slug:n,table_name:a.tableFullName,table_slug:a.tableName}})}}catch(e){(0,u.default)({component:"/api/createUserDatabase/lines-117-159",message:e.message,user:s})}r.push(l),b.writeFileSync(`${e}`,JSON.stringify(r),"utf8"),S&&await(0,_.A)({userId:s.id,targetDatabase:A});letd=await(0,c.A)(`GRANT ALL PRIVILEGES ON ${A}.* TO '${process.env.DSQL_DB_FULL_ACCESS_USERNAME}'@'${process.env.DSQL_DB_TARGET_IP_ADDRESS||"%"}' WITH GRANT OPTION`);if(d.error)throwError(d.error);letD=await(0,c.A)(`GRANT SELECT ON ${A}.* TO '${process.env.DSQL_DB_READ_ONLY_USERNAME}'@'${process.env.DSQL_DB_TARGET_IP_ADDRESS||"%"}'`);if(D.error)throwError(D.error);t?.mariadb_user&&t?.mariadb_pass&&await(0,c.A)(`GRANT ALL PRIVILEGES ON ${A}.* TO '${t.mariadb_user}'@'${t.mariadb_host}'`),await(0,c.A)("FLUSH PRIVILEGES"),a.json({success:!0})}catch(e){(0,u.default)({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!"})}letS=(0,n.M)(r,"default"),p=(0,n.M)(r,"config"),f=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:()=>u});varr=s(48786),t=s(95969),i=s(29021),n=s.n(i),l=s(89159);asyncfunctionu(e,a,s){let{keyCookieName:i,csrfCookieName:u}=(0,l.A)();if(!e.cookies?.[i]?.match(/./))returnnull;letd=(0,t.A)({encryptedString:e.cookies[i]});if(!d)returnnull;leto=JSON.parse(d);if(!o.csrf_k||s&&!Object.keys(e.headers).find(e=>e.includes(o.csrf_k)))returnnull;letc=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!c)returnconsole.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(s&&!n().existsSync(`${c}/${o.csrf_k}`))returnnull;if(0==o.verification_status&&!s){lete=await(0,r.A)(`SELECT veri