"use strict";(()=>{vare={};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});vara={};r.r(a),r.d(a,{default:()=>h});vars=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);letm=r(29021),f=r(21820),{execSync:_}=r(79646);asyncfunctionh(e,t){if("POST"!==e.method)returnt.json({msg:"Failed!"});letr=awaitp()(e,t,!0);if(!r)returnt.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{lete=`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");letn={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);leti=awaito()({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!"})}}letS=(0,n.M)(a,"default"),g=(0,n.M)(a,"config"),b=news.PagesAPIRouteModule({definition:{kind:l.A.PAGES_API,page:"/api/importDatabase",pathname:"/api/importDatabase",bundlePath:"",filename:""},userland:a})},72350:(e,t,r)=>{leta=r(57638),s=r(41709),{default:l}=r(49827),{default:n}=r(19857),i=r(47670);e.exports=asyncfunction({userId:e,database:t}){try{if(!e){console.log("No user Id provided");return}letr=l({userId:e});if(!r)throwError("User schema data not found!");leto=r.filter(e=>e.dbFullName===t.db_full_name)[0],u=awaita({database:t.db_full_name,queryString:"SHOW TABLES"});if(!u)throwError("No Existing Tables");for(letr=0;r<u.length;r++){letl=u[r],n=Object.values(l)[0];awaiti({dbFullName:"datasquirel",tableName:"user_database_tables",data:{user_id:e,db_id:t.id,db_slug:t.db_slug,table_name:s(n),table_slug:n}});letc={tableName:n,tableFullName:s(n)||"",fields:[],indexes:[]},d=awaita({database:t.db_full_name,queryString:`SHOW COLUMNS FROM ${n}`});if(d)for(lete=0;e<d.length;e++){let{Field:t,Type:r,Null:a,Key:s,Default:l,Extra:n}=d[e],i={fieldName:t,dataType:r.toUpperCase()};a?.match(/^no$/i)&&(i.notNullValue=!0),s?.match(/^pri$/i)&&(i.primaryKey=!0),l?.toString()?.match(/./)&&(i.defaultValue=l),l?.toString()?.match(/timestamp/i)&&(deletei.defaultValue,i.defaultValueLiteral=l),n?.toString()?.match(/auto_increment/i)&&(i.autoIncrement=!0),c.fields.push(i)}letp=awaita({database:t.db_full_name,queryString:`SHOW INDEXES FROM ${n}`});if(p)for(lete=0;e<p.length;e++){let{Table:t,Key_name:r,Column_name:a,Null:s,Index_type:l,Index_comment:n}=p[e];if(!n?.match(/^schema_index$/))continue;leti={indexType:l?.match(/fulltext/i)?"fullText":"regular",indexName:r,indexTableFields:[]},o=d?.filter(e=>e.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)}returnn({schemaData:r,userId:e}),!0}catch(e){returnconsole.log(e),!1}}},49827:(e,t,r)=>{r.r(t),r.d(t,{default:()=>n});leta=r(77538),s=r(29021),l=r(33873);functionn({userId:e}){try{lett=l.resolve(process.cwd(),`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${e}/main.json`);returnJSON.parse(s.readFileSync(t,"utf-8"))}catch(e){returna({component:"/functions/backend/grabUserSchemaData",message:e.message}),null}}},77538:(e,t,r)=>{leta=r(290