"use strict";(()=>{vare={};e.id=8675,e.ids=[8675],e.modules={39908:e=>{e.exports=require("@moduletrace/datasquirel/dist/users/user-auth")},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")},21820:e=>{e.exports=require("os")},33873:e=>{e.exports=require("path")},54356:(e,t,r)=>{r.r(t),r.d(t,{config:()=>$,default:()=>v,routeModule:()=>A});vara={};r.r(a),r.d(a,{default:()=>S});vars=r(89947),l=r(2706),n=r(96762),i=r(29021),o=r.n(i),u=r(21820),d=r.n(u),c=r(79646),m=r(30944),p=r(4820),f=r(21724),g=r(98e3);functionb(e){returne?e.split("-").filter(e=>""!==e).map(e=>e.substr(0,1).toUpperCase()+e.substr(1).toLowerCase()).join(" "):null}asyncfunctionh({userId:e,database:t}){try{if(!e){console.log("No user Id provided");return}letr=(0,p.A)({userId:e});if(!r)throwError("User schema data not found!");leta=r.filter(e=>e.dbFullName===t.db_full_name)[0],s=await(0,m.A)({database:t.db_full_name,queryString:`SHOW TABLES FROM ${t.db_full_name}`});if(!s)throwError("No Existing Tables");for(letr=0;r<s.length;r++){letl=s[r],n=Object.values(l)[0];await(0,g.A)({dbFullName:"datasquirel",tableName:"user_database_tables",data:{user_id:e,db_id:t.id,db_slug:t.db_slug,table_name:b(n),table_slug:n}});leti={tableName:n,tableFullName:b(n)||"",fields:[],indexes:[]},o=await(0,m.A)({database:t.db_full_name,queryString:`SHOW COLUMNS FROM ${t.db_full_name}.${n}`});if(o)for(lete=0;e<o.length;e++){let{Field:t,Type:r,Null:a,Key:s,Default:l,Extra:n}=o[e],u={fieldName:t,dataType:r.toUpperCase()};a?.match(/^no$/i)&&(u.notNullValue=!0),s?.match(/^pri$/i)&&(u.primaryKey=!0),l?.toString()?.match(/./)&&(u.defaultValue=l),l?.toString()?.match(/timestamp/i)&&(deleteu.defaultValue,u.defaultValueLiteral=l),n?.toString()?.match(/auto_increment/i)&&(u.autoIncrement=!0),i.fields.push(u)}letu=await(0,m.A)({database:t.db_full_name,queryString:`SHOW INDEXES FROM ${t.db_full_name}.${n}`});if(u)for(lete=0;e<u.length;e++){let{Table:t,Key_name:r,Column_name:a,Null:s,Index_type:l,Index_comment:n}=u[e];if(!n?.match(/^schema_index$/))continue;letd={indexType:l?.match(/fulltext/i)?"fullText":"regular",indexName:r,indexTableFields:[]},c=o?.filter(e=>e.Field===a)[0],m=i.indexes?.filter(e=>e.indexName==r);m&&m[0]?m[0].indexTableFields?.push({value:a,dataType:c.Type.toUpperCase()}):(d.indexTableFields=[{value:a,dataType:c.Type.toUpperCase()}],i.indexes?.push(d))}a.tables.push(i)}return(0,f.A)({schemaData:r,userId:e}),!0}catch(e){returnconsole.log(e),!1}}vary=r(67619),_=r(69842);asyncfunctionS(e,t){if("POST"!==e.method)returnt.json({msg:"Failed!"});letr=await(0,_.A)(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=d().platform().match(/win/i)?"'C:\\Program Files\\MySQL\\MySQL Server 8.0\\bin\\mysql.exe'":"mysql";o().writeFileSync(`./.tmp/${e}.sql`,s,"base64");letn={cwd:process.cwd()};d().platform().match(/win/i)&&(n.shell="bash.exe"),(0,c.execSync)(`${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=awaith({database:a,userId:r.id});t.json({success:!!i})}catch(e){console.log(e),(0,y.A)({component:"/api/importDatabase/catch-error",message:e.message,user:r}),t.json({success:!1,msg:"Import Failed!"})}}letv=(0,n.M)(a,"default"),$=(0,n.M)(a,"config"),A=news.PagesAPIRouteModule({definition:{kind:l.A.PAGES_API,page:"/api/importDatabase",pathname:"/api/importDatabase",bundlePath:"",filename:""},userland:a})},69842:(e,t,r)=>{r.d(t,{A:()=>l});vara=r(39908),s=r.n(a);asyncfunctionl(e,t,r){leta=s()({req:e,level:r?"deep":void0});returnconsole.log(a),a.payload}},4820:(e,t,r)=>{r.d(t,{A:()=>o});vara=r(67619),s=r(29021)