"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,a)=>{a.r(r),a.d(r,{config:()=>f,default:()=>A,routeModule:()=>p});vars={};a.r(s),a.d(s,{default:()=>m});vart=a(89947),i=a(2706),o=a(96762),n=a(29021),u=a.n(n),d=a(48786),l=a(67619),c=a(69842),_=a(98e3),E=a(14160),b=a(76856);asyncfunctionm(e,r){if("POST"!==e.method)returnr.json({msg:"Failed!"});leta=await(0,c.A)(e,r,!0);if(!a)returnr.json({success:!1,msg:"Unauthorized"});lets=await(0,d.A)("SELECT * FROM users WHERE id = ?",[a.id]),t=s?.[0],{db_name:i,db_slug:o,db_description:n,db_image:m,duplicate:A,keepUpdated:f,keepDataUpdated:p}=e.body;if(o.match(/[^a-zA-Z0-9-_]/))returnr.json({success:!1,msg:"Input Error"});letS=`datasquirel_user_${a.id}_${o}`,D=await(0,E.A)(`CREATE DATABASE IF NOT EXISTS \`${S}\` 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:S,db_description:n,db_image:m};A&&f&&(h.active_clone="1",h.active_clone_parent_db=A),A&&p&&(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-${a.id}/main.json`,s=JSON.parse(u().readFileSync(e,"utf8")),d={dbName:i,dbSlug:o,dbFullName:S,dbDescription:n,dbImage:m,tables:[]};if(A)try{lete=s.filter(e=>e.dbFullName===A)[0];d.tables=e.tables,f&&(d.childDatabase=!0,d.childDatabaseDbFullName=A,p&&(d.updateData=!0),e.childrenDatabases?e.childrenDatabases.push({dbFullName:S}):e.childrenDatabases=[{dbFullName:S}]);for(lete=0;e<d.tables.length;e++){letr=d.tables[e];await(0,_.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,l.A)({component:"/api/createUserDatabase/lines-117-159",message:e.message,user:a})}s.push(d),u().writeFileSync(`${e}`,JSON.stringify(s),"utf8"),A&&await(0,b.A)({userId:a.id,targetDatabase:S});letc=await(0,E.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);letD=await(0,E.A)(`GRANT SELECT ON ${S}.* 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,E.A)(`GRANT ALL PRIVILEGES ON ${S}.* TO '${t.mariadb_user}'@'${t.mariadb_host}'`),await(0,E.A)("FLUSH PRIVILEGES"),r.json({success:!0})}catch(e){(0,l.A)({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!"})}letA=(0,o.M)(s,"default"),f=(0,o.M)(s,"config"),p=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!");letd=(0,t.A)({encryptedString:e.cookies[i]});if(!d)throwError("Couldn't decrypt auth cookie!");letl=JSON.parse(d);if(!l.csrf_k)throwError("No `csrf_k` present in user Object!");if(a&&!Object.keys(e.headers).find(e=>e.includes(l.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_PATH env variable not found. Please set this variable.");if(a&&!o().existsSync(`${c}/${l.