"use strict";(()=>{var e={};e.id=8675,e.ids=[8675],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")},21820:e=>{e.exports=require("os")},33873:e=>{e.exports=require("path")},75588:(e,t,r)=>{r.r(t),r.d(t,{config:()=>g,default:()=>S,routeModule:()=>b});var a={};r.r(a),r.d(a,{default:()=>h});var s=r(89947),l=r(2706),n=r(96762),i=r(72350),o=r.n(i),u=r(77538),c=r.n(u),d=r(6420),p=r.n(d);let m=r(29021),f=r(21820),{execSync:_}=r(79646);async function h(e,t){if("POST"!==e.method)return t.json({msg:"Failed!"});let r=await p()(e,t,!0);if(!r)return t.json({success:!1,msg:"Unauthorized"});let{database:a,fileBase64:s}=e.body;a?.db_full_name?.match(/datasquirel_user_.*/)||t.json({success:!1,msg:"Unauthorized"});try{let e=`user-${r.id}-temp-sql`,l=f.platform().match(/win/i)?"'C:\\Program Files\\MySQL\\MySQL Server 8.0\\bin\\mysql.exe'":"mysql";m.writeFileSync(`./.tmp/${e}.sql`,s,"base64");let n={cwd:process.cwd()};f.platform().match(/win/i)&&(n.shell="bash.exe"),_(`${l} -u ${process.env.DSQL_DB_USERNAME} -h ${process.env.DSQL_DB_HOST} -p${process.env.DSQL_DB_PASSWORD} ${a.db_full_name} < .tmp/${e}.sql`,n);let i=await o()({database:a,userId:r.id});t.json({success:!!i})}catch(e){console.log(e),c()({component:"/api/importDatabase/catch-error",message:e.message,user:r}),t.json({success:!1,msg:"Import Failed!"})}}let S=(0,n.M)(a,"default"),g=(0,n.M)(a,"config"),b=new s.PagesAPIRouteModule({definition:{kind:l.A.PAGES_API,page:"/api/importDatabase",pathname:"/api/importDatabase",bundlePath:"",filename:""},userland:a})},72350:(e,t,r)=>{let a=r(57638),s=r(41709),{default:l}=r(49827),{default:n}=r(19857),i=r(47670);e.exports=async function({userId:e,database:t}){try{if(!e){console.log("No user Id provided");return}let r=l({userId:e});if(!r)throw Error("User schema data not found!");let o=r.filter(e=>e.dbFullName===t.db_full_name)[0],u=await a({database:t.db_full_name,queryString:"SHOW TABLES"});if(!u)throw Error("No Existing Tables");for(let r=0;re.Field===a)[0],u=c.indexes?.filter(e=>e.indexName==r);u&&u[0]?u[0].indexTableFields?.push({value:a,dataType:o.Type.toUpperCase()}):(i.indexTableFields=[{value:a,dataType:o.Type.toUpperCase()}],c.indexes?.push(i))}o.tables.push(c)}return n({schemaData:r,userId:e}),!0}catch(e){return console.log(e),!1}}},49827:(e,t,r)=>{r.r(t),r.d(t,{default:()=>n});let a=r(77538),s=r(29021),l=r(33873);function n({userId:e}){try{let t=l.resolve(process.cwd(),`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${e}/main.json`);return JSON.parse(s.readFileSync(t,"utf-8"))}catch(e){return a({component:"/functions/backend/grabUserSchemaData",message:e.message}),null}}},77538:(e,t,r)=>{let a=r(29021),{IncomingMessage:s}=r(81630);e.exports=async function({user:e,message:t,component:r,noMail:s,req:l}){let n=new Date,i=(()=>{if(!l)return null;try{let e=l.headers["x-forwarded-for"],t=l.headers["x-real-ip"],r=l.headers["cf-connecting-ip"],a=Array.isArray(e)?e[0]:e?.split(",")[0],s=r||a||t||l.socket.remoteAddress;if(!s)return null;return String(s)}catch(e){return null}})();try{let s=`🚀 SERVER ERROR =========================== Error Message: ${t} Component: ${r}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(s+=` User Id: ${e?.id} User Name: ${e?.first_name} ${e?.last_name} User Email: ${e?.email}`),l?.url&&(s+=` URL: ${l.url}`),l?.body&&(s+=` Request Body: ${JSON.stringify(l.body,null,4)}`),i&&(s+=` IP: ${i}`),s+=` Date: ${n.toDateString()} ========================================`,a.existsSync("./.tmp/error.log")||a.writeFileSync("./.tmp/error.log","","utf-8");let o=a.readFileSync("./.tmp/error.log","utf-8");a.writeFileSync("./.tmp/error.log",s),a.appendFileSync("./.tmp/error.log",` ${o}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},19857:(e,t,r)=>{r.r(t),r.d(t,{default:()=>n});let a=r(77538),s=r(29021),l=r(33873);function n({userId:e,schemaData:t}){try{let r=l.resolve(process.cwd(),`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${e}/main.json`);return s.writeFileSync(r,JSON.stringify(t),"utf8"),!0}catch(e){return a({component:"/functions/backend/setUserSchemaData",message:e.message}),!1}}},6420:(e,t,r)=>{r(81630);let a=r(51348),s=r(72907),l=r(29021);async function n(e,t,r,n){if(!e.cookies?.datasquirelAuthKey?.match(/./))return null;let i=s(e.cookies.datasquirelAuthKey);if(!i)return null;let o=JSON.parse(i);if(!o.csrf_k||r&&!e.headers["x-csrf-auth"]?.match(RegExp(`${o.csrf_k}`)))return null;let u=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!u)return console.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(r&&!l.existsSync(`${u}/${o.csrf_k}`))return null;if(0==o.verification_status&&!r){let e=await a(`SELECT verification_status FROM users WHERE id='${o.id}'`);e&&e[0]&&1==e[0].verification_status&&t.setHeader("Set-Cookie",["user_refresh=1"])}return o?.date&&Date.now()-o.date>6048e5?null:o}e.exports=n},72907:(e,t,r)=>{let{scryptSync:a,createDecipheriv:s}=r(55511),{Buffer:l}=r(79428);e.exports=e=>{let t=s("aes-192-cbc",a(process.env.DSQL_ENCRYPTION_PASSWORD||"",process.env.DSQL_ENCRYPTION_SALT||"",24),l.alloc(16,0));try{let r=t.update(e,"hex","utf8");return r+=t.final("utf8")}catch(e){return null}}},30003:e=>{e.exports=/^id$|^uuid$|^date_created$|^date_created_code$|^date_created_timestamp$|^date_updated$|^date_updated_code$|^date_updated_timestamp$/},6061:(e,t,r)=>{let a=r(72907),s=r(30003);e.exports=async function({unparsedResults:e,tableSchema:t}){let r=[];try{for(let l=0;l",t.message),e}}},57638:(e,t,r)=>{r(29021);let a=r(6061),s=r(48225),l=r(51348),n=r(21339);e.exports=async function({queryString:e,queryValuesArray:t,database:r,tableSchema:i}){let o;let u=!!r?.match(/^datasquirel$/),c=u?l:n;try{o=e&&t&&Array.isArray(t)&&t[0]?u?await c(e,t):await c({paradigm:"Full Access",database:r,queryString:e,queryValues:t}):u?await c(e):await c({paradigm:"Full Access",database:r,queryString:e})}catch(e){s({component:"varDatabaseDbHandler/lines-29-32",message:e.message})}if(o&&i)try{let e=o;return await a({unparsedResults:e,tableSchema:i})}catch(e){return console.log("\x1b[31mvarDatabaseDbHandler ERROR\x1b[0m =>",r,e),s({component:"varDatabaseDbHandler/lines-52-53",message:e.message}),null}else if(o)return o;else return null}},41709:e=>{e.exports=function(e){return e?e.split("-").filter(e=>""!==e).map(e=>e.substr(0,1).toUpperCase()+e.substr(1).toLowerCase()).join(" "):null}}};var t=require("../../webpack-api-runtime.js");t.C(e);var r=e=>t(t.s=e),a=t.X(0,[4050],()=>r(75588));module.exports=a})();