"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")},81630:e=>{e.exports=require("http")},33873:e=>{e.exports=require("path")},13441:(e,a,t)=>{t.r(a),t.d(a,{config:()=>F,default:()=>E,routeModule:()=>D});varr={};t.r(r),t.d(r,{default:()=>y});varl=t(89947),s=t(2706),n=t(96762),i=t(77538),d=t.n(i),u=t(6420),o=t.n(u),c=t(49827),b=t(27825),m=t.n(b),f=t(19857),p=t(51348),_=t.n(p),h=t(47670),g=t.n(h);t(29021);letN=t(33873),{execSync:S}=t(79646);asyncfunctiony(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:r}=e.body,l=e.body.dbFullName.replace(/[^a-z\_0-9]/g,""),s=e.body.dbSlug,n=e.body.dbId,i=e.body.parentDatabase,u=e.body.parentTable;try{lete=(0,c.default)({userId:t.id});if(!e)throwError("No User Schema found!");leto=e.findIndex(e=>e.dbFullName===l),b=e[o];if(!b)throwError("No Target Database Found!");letp=b.tables.findIndex(e=>e.tableName===r.tableName);if(p>=0?e[o].tables[p]=r:e[o].tables.push(r),r?.childTable){leta=e.find(e=>e.dbFullName===i),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:l,tableName:r.tableName,tableNameFull:r.tableNameFull}):t.childrenTables=[{dbNameFull:l,tableName:r.tableName,tableNameFull:r.tableFullName}]}if(b.childrenDatabases)for(leta=0;a<b.childrenDatabases.length;a++){letl=b.childrenDatabases[a];try{leta=e.findIndex(e=>e.dbFullName===l.dbFullName);e[a]&&(e[a].tables=m().cloneDeep(b.tables));lets=await_()("SELECT * FROM user_databases WHERE user_id = ? AND db_full_name = ?",[t.id,l.dbFullName]),n=await_()("SELECT * FROM user_database_tables WHERE db_id=? AND user_id=? AND table_slug=?",[s[0].id,t.id,r.tableName]);if(n?.[0])continue;awaitg()({dbFullName:"datasquirel",tableName:"user_database_tables",data:{user_id:t.id,db_id:s[0].id,db_slug:s[0].db_slug,table_name:r.tableFullName,table_slug:r.tableName}})}catch(e){d()({component:"/api/addUserTable/lines-124-140",message:e.message,user:t})}}(0,f.default)({userId:t.id,schemaData:e});leth={user_id:t.id,db_id:n,db_slug:s,table_name:r.tableFullName,table_slug:r.tableName};r?.childTable&&(h.child_table="1",h.child_table_parent_database=i,h.child_table_parent_table=u),awaitg()({dbFullName:"datasquirel",tableName:"user_database_tables",data:h});lety=N.join(process.cwd(),"/shell");S(`node createDbFromSchema.js --user ${t.id} --database ${l}${r?.childTable?" --clone":""}`,{cwd:y}),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!"})}}letE=(0,n.M)(r,"default"),F=(0,n.M)(r,"config"),D=newl.PagesAPIRouteModule({definition:{kind:s.A.PAGES_API,page:"/api/addUserTable",pathname:"/api/addUserTable",bundlePath:"",filename:""},userland:r})},49827:(e,a,t)=>{t.r(a),t.d(a,{default:()=>n});letr=t(77538),l=t(29021),s=t(33873);functionn({userId:e}){try{leta=s.resolve(process.cwd(),`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${e}/main.json`);returnJSON.parse(l.readFileSync(a,"utf-8"))}catch(e){returnr({component:"/functions/backend/grabUserSchemaData",message:e.message}),null}}},77538:(e,a,t)=>{letr=t(29021),{IncomingMessage:l}=t(81630);e.exports=asyncfunction({user:e,message:a,component:t,noMail:l,req:s}){letn=newDate,i=(()=>{if(!s)returnnull;try{lete=s.headers["x-forwarded-for"],a=s.headers["x-real-ip"],t=s.headers["cf-connecting-ip"],r=Array.isArray(e)?e[0]:e?.split(",")[0],l=t||r||a||s.socket.remoteAddress;if(!l)returnnull;returnString(l)}catch(e){returnnull}})();try{letl=`<EFBFBD><EFBFBD>