"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,r,a)=>{a.r(r),a.d(r,{config:()=>p,default:()=>m,routeModule:()=>S});vars={};a.r(s),a.d(s,{default:()=>f});vart=a(89947),i=a(2706),o=a(96762),n=a(48786),u=a(67619),l=a(69842),d=a(98e3),c=a(14160),_=a(76856);letE=a(29021);a(33873);let{execSync:b}=a(79646);asyncfunctionf(e,r){if("POST"!==e.method)returnr.json({msg:"Failed!"});leta=await(0,l.A)(e,r,!0);if(!a)returnr.json({success:!1,msg:"Unauthorized"});lets=await(0,n.A)("SELECT * FROM users WHERE id = ?",[a.id]),t=s?.[0],{db_name:i,db_slug:o,db_description:b,db_image:f,duplicate:m,keepUpdated:p,keepDataUpdated:S}=e.body;if(o.match(/[^a-zA-Z0-9-_]/))returnr.json({success:!1,msg:"Input Error"});letA=`datasquirel_user_${a.id}_${o}`,D=await(0,c.A)(`CREATE DATABASE IF NOT EXISTS \`${A}\` CHARACTER SET utf8mb4 COLLATE utf8mb4_bin`);if(!D?.affectedRows)returnr.json({success:!1,msg:"Database Could Not be created!"});leth={user_id:a.id,db_name:i,db_slug:o,db_full_name:A,db_description:b,db_image:f};m&&p&&(h.active_clone="1",h.active_clone_parent_db=m),m&&S&&(h.active_data="1");letN=await(0,d.A)({dbFullName:"datasquirel",tableName:"user_databases",data:h});if(N.insertId)try{lete=`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${a.id}/main.json`,s=JSON.parse(E.readFileSync(e,"utf8")),n={dbName:i,dbSlug:o,dbFullName:A,dbDescription:b,dbImage:f,tables:[]};if(m)try{lete=s.filter(e=>e.dbFullName===m)[0];n.tables=e.tables,p&&(n.childDatabase=!0,n.childDatabaseDbFullName=m,S&&(n.updateData=!0),e.childrenDatabases?e.childrenDatabases.push({dbFullName:A}):e.childrenDatabases=[{dbFullName:A}]);for(lete=0;e<n.tables.length;e++){letr=n.tables[e];await(0,d.A)({dbFullName:"datasquirel",tableName:"user_database_tables",data:{user_id:a.id,db_id:N.insertId,db_slug:o,table_name:r.tableFullName,table_slug:r.tableName}})}}catch(e){(0,u.default)({component:"/api/createUserDatabase/lines-117-159",message:e.message,user:a})}s.push(n),E.writeFileSync(`${e}`,JSON.stringify(s),"utf8"),m&&await(0,_.A)({userId:a.id,targetDatabase:A});letl=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(l.error)throwError(l.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"),r.json({success:!0})}catch(e){(0,u.default)({component:"/api/createUserDatabase/main-catch-error",message:e.message,user:a}),r.json({success:!1,msg:"Database Files could not be written!"})}elser.json({success:!1,msg:"Database Could Not Be Recorded!"})}letm=(0,o.M)(s,"default"),p=(0,o.M)(s,"config"),S=newt.PagesAPIRouteModule({definition:{kind:i.A.PAGES_API,page:"/api/createUserDatabase",pathname:"/api/createUserDatabase",bundlePath:"",filename:""},userland:s})},69842:(e,r,a)=>{a.d(r,{A:()=>u});vars=a(48786),t=a(95969),i=a(29021),o=a.n(i),n=a(89159);asyncfunctionu(e,r,a){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(a&&!Object.keys(e.headers).find(e=>e.includes(d.csrf_k)))throwError("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_PATHe