"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,s)=>{s.r(a),s.d(a,{config:()=>S,default:()=>h,routeModule:()=>E});vart={};s.r(t),s.d(t,{default:()=>N});varr=s(89947),l=s(2706),d=s(96762),i=s(67619),n=s(69842),u=s(4820),o=s(27825),b=s.n(o),c=s(21724),_=s(48786),m=s(98e3),f=s(76856);s(29021),s(33873);let{execSync:p}=s(79646);asyncfunctionN(e,a){if("POST"!==e.method)returna.json({msg:"Failed!"});lets=await(0,n.A)(e,a,!0);if(!s)returnconsole.log("No User"),a.json({success:!1,msg:"Unauthorized"});let{payload:t}=e.body,r=e.body.dbFullName.replace(/[^a-z\_0-9]/g,""),l=e.body.dbSlug,d=e.body.dbId,o=e.body.parentDatabase,p=e.body.parentTable;try{lete=(0,u.A)({userId:s.id});if(!e)throwError("No User Schema found!");letn=e.findIndex(e=>e.dbFullName===r),N=e[n];if(!N)throwError("No Target Database Found!");leth=N.tables.findIndex(e=>e.tableName===t.tableName);if(h>=0?e[n].tables[h]=t:e[n].tables.push(t),t?.childTable){leta=e.find(e=>e.dbFullName===o),s=a?.tables.find(e=>{if(e.tableName===p)return!0});if(!s)throwError("Child Table Parent Doesn't Exist!");s.childrenTables?.[0]?s.childrenTables.push({dbNameFull:r,tableName:t.tableName,tableNameFull:t.tableNameFull}):s.childrenTables=[{dbNameFull:r,tableName:t.tableName,tableNameFull:t.tableFullName}]}if(N.childrenDatabases)for(leta=0;a<N.childrenDatabases.length;a++){letr=N.childrenDatabases[a];try{leta=e.findIndex(e=>e.dbFullName===r.dbFullName);e[a]&&(e[a].tables=b().cloneDeep(N.tables));letl=await(0,_.A)("SELECT * FROM user_databases WHERE user_id = ? AND db_full_name = ?",[s.id,r.dbFullName]),d=await(0,_.A)("SELECT * FROM user_database_tables WHERE db_id=? AND user_id=? AND table_slug=?",[l[0].id,s.id,t.tableName]);if(d?.[0])continue;await(0,m.A)({dbFullName:"datasquirel",tableName:"user_database_tables",data:{user_id:s.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:s})}}(0,c.A)({userId:s.id,schemaData:e});letS={user_id:s.id,db_id:d,db_slug:l,table_name:t.tableFullName,table_slug:t.tableName};t?.childTable&&(S.child_table="1",S.child_table_parent_database=o,S.child_table_parent_table=p),await(0,m.A)({dbFullName:"datasquirel",tableName:"user_database_tables",data:S}),await(0,f.A)({userId:s.id,targetDatabase:r}),a.json({success:!0})}catch(e){console.log(e.message),(0,i.default)({component:"/api/addUserTable/main-catch-error",message:e.message,user:s}),a.json({success:!1,msg:"Database Files could not be written!"})}}leth=(0,d.M)(t,"default"),S=(0,d.M)(t,"config"),E=newr.PagesAPIRouteModule({definition:{kind:l.A.PAGES_API,page:"/api/addUserTable",pathname:"/api/addUserTable",bundlePath:"",filename:""},userland:t})},69842:(e,a,s)=>{s.d(a,{A:()=>n});vart=s(48786),r=s(95969),l=s(29021),d=s.n(l),i=s(89159);asyncfunctionn(e,a,s){let{keyCookieName:l,csrfCookieName:n}=(0,i.A)();if(!e.cookies?.[l]?.match(/./))returnnull;letu=(0,r.A)({encryptedString:e.cookies[l]});if(!u)returnnull;leto=JSON.parse(u);if(!o.csrf_k||s&&!Object.keys(e.headers).find(e=>e.includes(o.csrf_k)))returnnull;letb=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!b)returnconsole.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(s&&!d().existsSync(`${b}/${o.csrf_k}`))returnnull;if(0==o.verification_status&&!s){lete=await(0,t.A)(`SELECT verification_status FROM users WHERE id='${o.id}'`);e&&e[0]&&1==e[0].verification_status&&a.setHeader("Set-Cookie",["user_refresh=1"])}returno?.date&&Date.now()-o.date>6048e5?null:o}},89159:(e,a,s)=>{s.d(a,{A:()=>t});functiont(e){leta=process.env.DSQ