"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")},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")},47122:(e,a,r)=>{r.r(a),r.d(a,{config:()=>N,default:()=>E,routeModule:()=>S});vart={};r.r(t),r.d(t,{default:()=>h});vars=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);r(29021),r(33873);let{execSync:p}=r(79646);asyncfunctionh(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:t}=e.body,s=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===s),h=e[n];if(!h)throwError("No Target Database Found!");letE=h.tables.findIndex(e=>e.tableName===t.tableName);if(E>=0?e[n].tables[E]=t:e[n].tables.push(t),t?.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:s,tableName:t.tableName,tableNameFull:t.tableNameFull}):r.childrenTables=[{dbNameFull:s,tableName:t.tableName,tableNameFull:t.tableFullName}]}if(h.childrenDatabases)for(leta=0;a<h.childrenDatabases.length;a++){lets=h.childrenDatabases[a];try{leta=e.findIndex(e=>e.dbFullName===s.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,s.dbFullName]),d=await(0,_.A)("SELECT * FROM user_database_tables WHERE db_id=? AND user_id=? AND table_slug=?",[l[0].id,r.id,t.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:t.tableFullName,table_slug:t.tableName}})}catch(e){(0,i.default)({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:t.tableFullName,table_slug:t.tableName};t?.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:s}),a.json({success:!0})}catch(e){console.log(e.message),(0,i.default)({component:"/api/addUserTable/main-catch-error",message:e.message,user:r}),a.json({success:!1,msg:"Database Files could not be written!"})}}letE=(0,d.M)(t,"default"),N=(0,d.M)(t,"config"),S=news.PagesAPIRouteModule({definition:{kind:l.A.PAGES_API,page:"/api/addUserTable",pathname:"/api/addUserTable",bundlePath:"",filename:""},userland:t})},69842:(e,a,r)=>{r.d(a,{A:()=>n});vart=r(48786),s=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,s.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)))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(r&&!d().existsSync(`${c}/${u.csrf_k}`))throwError("Key not found in Auth Keys Folder!");if(0==u.verification_status&&!r){lete=await(0,t.A)(`SELECT verification_status FROM users WHERE id='${u.