"use strict";(()=>{vare={};e.id=8275,e.ids=[8275],e.modules={60818:e=>{e.exports=require("dotenv")},27825:e=>{e.exports=require("lodash")},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")},81630:e=>{e.exports=require("http")},33873:e=>{e.exports=require("path")},13441:(e,a,t)=>{t.r(a),t.d(a,{config:()=>I,default:()=>v,routeModule:()=>T});vars={};t.r(s),t.d(s,{default:()=>x});varr=t(89947),l=t(2706),i=t(96762),n=t(48225),d=t.n(n),u=t(6420),o=t.n(u),b=t(2258),c=t.n(b),_=t(27825),m=t.n(_),p=t(78634),f=t.n(p),N=t(51348),h=t.n(N),E=t(47670),S=t.n(E),g=t(19261),D=t.n(g);t(29021),t(33873);let{execSync:F}=t(79646);asyncfunctionx(e,a){if("POST"!==e.method)returna.json({msg:"Failed!"});lett=awaito()(e,a,!0);if(!t)returnconsole.log("No User"),a.json({success:!1,msg:"Unauthorized"});let{payload:s}=e.body,r=e.body.dbFullName.replace(/[^a-z\_0-9]/g,""),l=e.body.dbSlug,i=e.body.dbId,n=e.body.parentDatabase,u=e.body.parentTable;try{lete=c()({userId:t.id});if(!e)throwError("No User Schema found!");leto=e.findIndex(e=>e.dbFullName===r),b=e[o];if(!b)throwError("No Target Database Found!");let_=b.tables.findIndex(e=>e.tableName===s.tableName);if(_>=0?e[o].tables[_]=s:e[o].tables.push(s),s?.childTable){leta=e.find(e=>e.dbFullName===n),t=a?.tables.find(e=>{if(e.tableName===u)return!0});if(!t)throwError("Child Table Parent Doesn't Exist!");t.childrenTables?.[0]?t.childrenTables.push({dbNameFull:r,tableName:s.tableName,tableNameFull:s.tableNameFull}):t.childrenTables=[{dbNameFull:r,tableName:s.tableName,tableNameFull:s.tableFullName}]}if(b.childrenDatabases)for(leta=0;a<b.childrenDatabases.length;a++){letr=b.childrenDatabases[a];try{leta=e.findIndex(e=>e.dbFullName===r.dbFullName);e[a]&&(e[a].tables=m().cloneDeep(b.tables));letl=awaith()("SELECT * FROM user_databases WHERE user_id = ? AND db_full_name = ?",[t.id,r.dbFullName]),i=awaith()("SELECT * FROM user_database_tables WHERE db_id=? AND user_id=? AND table_slug=?",[l[0].id,t.id,s.tableName]);if(i?.[0])continue;awaitS()({dbFullName:"datasquirel",tableName:"user_database_tables",data:{user_id:t.id,db_id:l[0].id,db_slug:l[0].db_slug,table_name:s.tableFullName,table_slug:s.tableName}})}catch(e){d()({component:"/api/addUserTable/lines-124-140",message:e.message,user:t})}}f()({userId:t.id,schemaData:e});letp={user_id:t.id,db_id:i,db_slug:l,table_name:s.tableFullName,table_slug:s.tableName};s?.childTable&&(p.child_table="1",p.child_table_parent_database=n,p.child_table_parent_table=u),awaitS()({dbFullName:"datasquirel",tableName:"user_database_tables",data:p}),awaitD()({userId:t.id,targetDatabase:r}),a.json({success:!0})}catch(e){console.log(e.message),d()({component:"/api/addUserTable/main-catch-error",message:e.message,user:t}),a.json({success:!1,msg:"Database Files could not be written!"})}}letv=(0,i.M)(s,"default"),I=(0,i.M)(s,"config"),T=newr.PagesAPIRouteModule({definition:{kind:l.A.PAGES_API,page:"/api/addUserTable",pathname:"/api/addUserTable",bundlePath:"",filename:""},userland:s})},6420:(e,a,t)=>{t(81630);lets=t(51348),r=t(72835),l=t(29021),i=t(31341);asyncfunctionn(e,a,t,n){let{keyCookieName:d,csrfCookieName:u}=i();if(!e.cookies?.[d]?.match(/./))returnnull;leto=r({encryptedString:e.cookies[d]});if(!o)returnnull;letb=JSON.parse(o);if(!b.csrf_k||t&&!e.headers["x-csrf-auth"]?.match(RegExp(`${b.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(t&&!l.existsSync(`${c}/${b.csrf_k}`))returnnull;if(0==b.verification_status&&!t){lete=awaits(`SELECT verification_status FROM users WHERE id='${b.id}'`);e&&e[0]&&1==e[0].verification_status&&a.setHeader("Set-Cookie",["user_refresh=1"])}returnb?.date&&Date.now()-b.date>6048e5?null:b}e.exports=n},3134