"use strict";(()=>{vare={};e.id=8675,e.ids=[8675],e.modules={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:()=>y,default:()=>h,routeModule:()=>E});vara={};r.r(a),r.d(a,{default:()=>b});vars=r(89947),l=r(2706),n=r(96762),i=r(30944),o=r(4820),u=r(21724),d=r(98e3);functionc(e){returne?e.split("-").filter(e=>""!==e).map(e=>e.substr(0,1).toUpperCase()+e.substr(1).toLowerCase()).join(" "):null}asyncfunctionm({userId:e,database:t}){try{if(!e){console.log("No user Id provided");return}letr=(0,o.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,i.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,d.A)({dbFullName:"datasquirel",tableName:"user_database_tables",data:{user_id:e,db_id:t.id,db_slug:t.db_slug,table_name:c(n),table_slug:n}});leto={tableName:n,tableFullName:c(n)||"",fields:[],indexes:[]},u=await(0,i.A)({database:t.db_full_name,queryString:`SHOW COLUMNS FROM ${t.db_full_name}.${n}`});if(u)for(lete=0;e<u.length;e++){let{Field:t,Type:r,Null:a,Key:s,Default:l,Extra:n}=u[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),o.fields.push(i)}letm=await(0,i.A)({database:t.db_full_name,queryString:`SHOW INDEXES FROM ${t.db_full_name}.${n}`});if(m)for(lete=0;e<m.length;e++){let{Table:t,Key_name:r,Column_name:a,Null:s,Index_type:l,Index_comment:n}=m[e];if(!n?.match(/^schema_index$/))continue;leti={indexType:l?.match(/fulltext/i)?"fullText":"regular",indexName:r,indexTableFields:[]},d=u?.filter(e=>e.Field===a)[0],c=o.indexes?.filter(e=>e.indexName==r);c&&c[0]?c[0].indexTableFields?.push({value:a,dataType:d.Type.toUpperCase()}):(i.indexTableFields=[{value:a,dataType:d.Type.toUpperCase()}],o.indexes?.push(i))}a.tables.push(o)}return(0,u.A)({schemaData:r,userId:e}),!0}catch(e){returnconsole.log(e),!1}}varp=r(67619),_=r(69842);letf=r(29021),S=r(21820),{execSync:g}=r(79646);asyncfunctionb(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=S.platform().match(/win/i)?"'C:\\Program Files\\MySQL\\MySQL Server 8.0\\bin\\mysql.exe'":"mysql";f.writeFileSync(`./.tmp/${e}.sql`,s,"base64");letn={cwd:process.cwd()};S.platform().match(/win/i)&&(n.shell="bash.exe"),g(`${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=awaitm({database:a,userId:r.id});t.json({success:!!i})}catch(e){console.log(e),(0,p.default)({component:"/api/importDatabase/catch-error",message:e.message,user:r}),t.json({success:!1,msg:"Import Failed!"})}}leth=(0,n.M)(a,"default"),y=(0,n.M)(a,"config"),E=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:()=>o});vara=r(48786),s=r(95969),l=r(29021),n=r.n(l),i=r(89159);asyncfunctiono(e,t,r){let{keyCookieName:l,csrfCookieName:o}=(0,i.A)();if(!e.cookies?.[l]?.match(/./))returnnull;letu=(0,s.A)({encryptedString:e.cookies[l]});if(!u)returnnull;letd=JSON.parse(u);if(!d.csrf_k||r&&!