"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")},55511:e=>{e.exports=require("crypto")},29021:e=>{e.exports=require("fs")},33873:e=>{e.exports=require("path")},8325:(e,r,s)=>{s.r(r),s.d(r,{config:()=>p,default:()=>A,routeModule:()=>S});vara={};s.r(a),s.d(a,{default:()=>m});vart=s(89947),i=s(2706),o=s(96762),n=s(29021),u=s.n(n),l=s(48786),d=s(67619),c=s(69842),_=s(98e3),b=s(14160),E=s(76856);asyncfunctionm(e,r){if("POST"!==e.method)returnr.json({msg:"Failed!"});lets=await(0,c.A)(e,r,!0);if(!s)returnr.json({success:!1,msg:"Unauthorized"});leta=await(0,l.A)("SELECT * FROM users WHERE id = ?",[s.id]),t=a?.[0],{db_name:i,db_slug:o,db_description:n,db_image:m,duplicate:A,keepUpdated:p,keepDataUpdated:S}=e.body;if(o.match(/[^a-zA-Z0-9-_]/))returnr.json({success:!1,msg:"Input Error"});letf=`datasquirel_user_${s.id}_${o}`,D=await(0,b.A)(`CREATE DATABASE IF NOT EXISTS \`${f}\` CHARACTER SET utf8mb4 COLLATE utf8mb4_bin`);if(!D?.affectedRows)returnr.json({success:!1,msg:"Database Could Not be created!"});leth={user_id:s.id,db_name:i,db_slug:o,db_full_name:f,db_description:n,db_image:m};A&&p&&(h.active_clone="1",h.active_clone_parent_db=A),A&&S&&(h.active_data="1");letN=await(0,_.A)({dbFullName:"datasquirel",tableName:"user_databases",data:h});if(N.insertId)try{lete=`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${s.id}/main.json`,a=JSON.parse(u().readFileSync(e,"utf8")),l={dbName:i,dbSlug:o,dbFullName:f,dbDescription:n,dbImage:m,tables:[]};if(A)try{lete=a.filter(e=>e.dbFullName===A)[0];l.tables=e.tables,p&&(l.childDatabase=!0,l.childDatabaseDbFullName=A,S&&(l.updateData=!0),e.childrenDatabases?e.childrenDatabases.push({dbFullName:f}):e.childrenDatabases=[{dbFullName:f}]);for(lete=0;e<l.tables.length;e++){letr=l.tables[e];await(0,_.A)({dbFullName:"datasquirel",tableName:"user_database_tables",data:{user_id:s.id,db_id:N.insertId,db_slug:o,table_name:r.tableFullName,table_slug:r.tableName}})}}catch(e){(0,d.A)({component:"/api/createUserDatabase/lines-117-159",message:e.message,user:s})}a.push(l),u().writeFileSync(`${e}`,JSON.stringify(a),"utf8"),A&&await(0,E.A)({userId:s.id,targetDatabase:f});letc=await(0,b.A)(`GRANT ALL PRIVILEGES ON ${f}.* TO '${process.env.DSQL_DB_FULL_ACCESS_USERNAME}'@'${process.env.DSQL_DB_TARGET_IP_ADDRESS||"%"}' WITH GRANT OPTION`);if(c.error)throwError(c.error);letD=await(0,b.A)(`GRANT SELECT ON ${f}.* 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,b.A)(`GRANT ALL PRIVILEGES ON ${f}.* TO '${t.mariadb_user}'@'${t.mariadb_host}'`),await(0,b.A)("FLUSH PRIVILEGES"),r.json({success:!0})}catch(e){(0,d.A)({component:"/api/createUserDatabase/main-catch-error",message:e.message,user:s}),r.json({success:!1,msg:"Database Files could not be written!"})}elser.json({success:!1,msg:"Database Could Not Be Recorded!"})}letA=(0,o.M)(a,"default"),p=(0,o.M)(a,"config"),S=newt.PagesAPIRouteModule({definition:{kind:i.A.PAGES_API,page:"/api/createUserDatabase",pathname:"/api/createUserDatabase",bundlePath:"",filename:""},userland:a})},69842:(e,r,s)=>{s.d(r,{A:()=>u});vara=s(48786),t=s(95969),i=s(29021),o=s.n(i),n=s(89159);asyncfunctionu(e,r,s){try{let{keyCookieName:i,csrfCookieName:u}=(0,n.A)();if(!e.cookies?.[i]?.match(/./))throwError("Request Cookies not Found!");letl=(0,t.A)({encryptedString:e.cookies[i]});if(!l)throwError("Couldn't decrypt auth cookie!");letd=JSON.parse(l);if(!d.csrf_k)throwError("No `csrf_k` present in user Object!");if(s&&!Object.keys(e.headers).find(e=>e.includes(d.csrf_k)))throwconsole.log("req.headers",e.headers),console.log("userObject",d),Error("Deep Auth Failed. `csrf` key not found in request headers!");letc=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!c)throwError("DSQL_USER_LOGIN_KEYS_PATHenvvariablenotfo