"use strict";(()=>{vare={};e.id=8275,e.ids=[8275],e.modules={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")},55511:e=>{e.exports=require("crypto")},29021:e=>{e.exports=require("fs")},33873:e=>{e.exports=require("path")},47122:(e,a,r)=>{r.r(a),r.d(a,{config:()=>E,default:()=>h,routeModule:()=>N});vars={};r.r(s),r.d(s,{default:()=>p});vart=r(89947),l=r(2706),d=r(96762),i=r(67619),n=r(69842),o=r(4820),u=r(27825),c=r.n(u),b=r(21724),_=r(48786),m=r(98e3),f=r(76856);asyncfunctionp(e,a){if("POST"!==e.method)returna.json({msg:"Failed!"});letr=await(0,n.A)(e,a,!0);if(!r)returnconsole.log("No User"),a.json({success:!1,msg:"Unauthorized"});let{payload:s}=e.body,t=e.body.dbFullName.replace(/[^a-z\_0-9]/g,""),l=e.body.dbSlug,d=e.body.dbId,u=e.body.parentDatabase,p=e.body.parentTable;try{lete=(0,o.A)({userId:r.id});if(!e)throwError("No User Schema found!");letn=e.findIndex(e=>e.dbFullName===t),h=e[n];if(!h)throwError("No Target Database Found!");letE=h.tables.findIndex(e=>e.tableName===s.tableName);if(E>=0?e[n].tables[E]=s:e[n].tables.push(s),s?.childTable){leta=e.find(e=>e.dbFullName===u),r=a?.tables.find(e=>{if(e.tableName===p)return!0});if(!r)throwError("Child Table Parent Doesn't Exist!");r.childrenTables?.[0]?r.childrenTables.push({dbNameFull:t,tableName:s.tableName,tableNameFull:s.tableNameFull}):r.childrenTables=[{dbNameFull:t,tableName:s.tableName,tableNameFull:s.tableFullName}]}if(h.childrenDatabases)for(leta=0;a<h.childrenDatabases.length;a++){lett=h.childrenDatabases[a];try{leta=e.findIndex(e=>e.dbFullName===t.dbFullName);e[a]&&(e[a].tables=c().cloneDeep(h.tables));letl=await(0,_.A)("SELECT * FROM user_databases WHERE user_id = ? AND db_full_name = ?",[r.id,t.dbFullName]),d=await(0,_.A)("SELECT * FROM user_database_tables WHERE db_id=? AND user_id=? AND table_slug=?",[l[0].id,r.id,s.tableName]);if(d?.[0])continue;await(0,m.A)({dbFullName:"datasquirel",tableName:"user_database_tables",data:{user_id:r.id,db_id:l[0].id,db_slug:l[0].db_slug,table_name:s.tableFullName,table_slug:s.tableName}})}catch(e){(0,i.A)({component:"/api/addUserTable/lines-124-140",message:e.message,user:r})}}(0,b.A)({userId:r.id,schemaData:e});letN={user_id:r.id,db_id:d,db_slug:l,table_name:s.tableFullName,table_slug:s.tableName};s?.childTable&&(N.child_table="1",N.child_table_parent_database=u,N.child_table_parent_table=p),await(0,m.A)({dbFullName:"datasquirel",tableName:"user_database_tables",data:N}),await(0,f.A)({userId:r.id,targetDatabase:t}),a.json({success:!0})}catch(e){console.log(e.message),(0,i.A)({component:"/api/addUserTable/main-catch-error",message:e.message,user:r}),a.json({success:!1,msg:"Database Files could not be written!"})}}leth=(0,d.M)(s,"default"),E=(0,d.M)(s,"config"),N=newt.PagesAPIRouteModule({definition:{kind:l.A.PAGES_API,page:"/api/addUserTable",pathname:"/api/addUserTable",bundlePath:"",filename:""},userland:s})},69842:(e,a,r)=>{r.d(a,{A:()=>n});vars=r(48786),t=r(95969),l=r(29021),d=r.n(l),i=r(89159);asyncfunctionn(e,a,r){try{let{keyCookieName:l,csrfCookieName:n}=(0,i.A)();if(!e.cookies?.[l]?.match(/./))throwError("Request Cookies not Found!");leto=(0,t.A)({encryptedString:e.cookies[l]});if(!o)throwError("Couldn't decrypt auth cookie!");letu=JSON.parse(o);if(!u.csrf_k)throwError("No `csrf_k` present in user Object!");if(r&&!Object.keys(e.headers).find(e=>e.includes(u.csrf_k)))throwconsole.log("req.headers",e.headers),console.log("userObject",u),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_PATH env variable not found. Please set this variable.");if(r&&!d().existsSync(`${c}/${u.csrf_k}`))throwError("Key not found in Auth Keys Folder!");if(0==u.verification_status&&!r){lete=await(0,s.A)(`SELECT verification_status FROM users WHERE id='${u.id}'`);e&&e[0]&&1==e[0].verification