"use strict";(()=>{var e={};e.id=4112,e.ids=[4112],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")},81630:e=>{e.exports=require("http")},55591:e=>{e.exports=require("https")},33873:e=>{e.exports=require("path")},63831:(e,r,t)=>{t.r(r),t.d(r,{config:()=>q,default:()=>g,routeModule:()=>b});var s={};t.r(s),t.d(s,{config:()=>h,default:()=>y});var a=t(89947),i=t(2706),l=t(96762),o=t(29021),n=t.n(o);t(27825);var u=t(14211),d=t.n(u),c=t(48225),p=t.n(c),m=t(77619),f=t.n(m);let h={api:{bodyParser:{sizeLimit:"50mb"}}};async function y(e,r){if("POST"!==e.method)return r.json({msg:"Failed!"});try{let t,{query:s,database:a,tableName:i,queryValues:l}=e.body,o=e.headers.authorization,u=f()({key:o,database:a,table:i,user_id:String(e.query.user_id)});if(!u?.user_id)throw Error("Api Credentials invalid!");let{user_id:c,full_access:p}=u;if(!p)return r.json({success:!1,msg:"Unauthorized"});let m=`datasquirel_user_${c}_${a}`,h=`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${c.toString().replace(/\//g,"")}/main.json`;if(n().existsSync(h))try{t=JSON.parse(n().readFileSync(h,"utf8")).filter(e=>e.dbFullName===m)[0]}catch(e){}let y=await d()({query:s,dbFullName:m,dbSchema:t,queryValues:l,tableName:i});r.json(y)}catch(t){p()({component:"/api/query/post/main-catch-error",message:t.message,req:e}),r.json({success:!1,msg:"Wrong Credentials"})}}let g=(0,l.M)(s,"default"),q=(0,l.M)(s,"config"),b=new a.PagesAPIRouteModule({definition:{kind:i.A.PAGES_API,page:"/api/query/[user_id]/post",pathname:"/api/query/[user_id]/post",bundlePath:"",filename:""},userland:s})},14211:(e,r,t)=>{let s=t(27825),a=t(48225),i=t(8238);e.exports=async function({query:e,dbFullName:r,queryValues:t,tableName:l,dbSchema:o,useLocal:n}){let u;if("string"==typeof e&&e?.match(/^create |^alter |^drop /i)||"object"==typeof e&&e?.action?.match(/^create |^alter |^drop /i))return{success:!1,msg:"Wrong Input"};try{let a,{result:d,error:c}=await i({dbFullName:r,query:e,dbSchema:o,queryValuesArray:t,tableName:l,local:n});if(u=d,c)throw c;if(o){let e=o.tables.find(e=>e.tableName===l);if(e){let r=s.cloneDeep(e);delete r.childTable,delete r.childTableDbFullName,delete r.childTableName,delete r.childrenTables,delete r.updateData,delete r.tableNameOld,delete r.indexes,a=r}}return{success:!0,payload:u,error:c,schema:l&&a?a:void 0}}catch(e){return a({component:"/api/query/post/lines-132-142",message:e.message}),{success:!1,payload:u,error:e.message}}}}};var r=require("../../../../webpack-api-runtime.js");r.C(e);var t=e=>r(r.s=e),s=r.X(0,[4050,8540],()=>t(63831));module.exports=s})();