"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,r,t)=>{t.r(r),t.d(r,{config:()=>A,default:()=>E,routeModule:()=>v});vara={};t.r(a),t.d(a,{default:()=>b});vars=t(89947),n=t(2706),l=t(96762),i=t(29021),o=t.n(i),u=t(21820),c=t.n(u),d=t(79646),m=t(30944),p=t(4820),_=t(21724),f=t(98e3);functionh(e){returne?e.split("-").filter(e=>""!==e).map(e=>e.substr(0,1).toUpperCase()+e.substr(1).toLowerCase()).join(" "):null}asyncfunctionS({userId:e,database:r}){try{if(!e){console.log("No user Id provided");return}lett=(0,p.A)({userId:e});if(!t)throwError("User schema data not found!");leta=t.filter(e=>e.dbFullName===r.db_full_name)[0],s=await(0,m.A)({database:r.db_full_name,queryString:`SHOW TABLES FROM ${r.db_full_name}`});if(!s)throwError("No Existing Tables");for(lett=0;t<s.length;t++){letn=s[t],l=Object.values(n)[0];await(0,f.A)({dbFullName:"datasquirel",tableName:"user_database_tables",data:{user_id:e,db_id:r.id,db_slug:r.db_slug,table_name:h(l),table_slug:l}});leti={tableName:l,tableFullName:h(l)||"",fields:[],indexes:[]},o=await(0,m.A)({database:r.db_full_name,queryString:`SHOW COLUMNS FROM ${r.db_full_name}.${l}`});if(o)for(lete=0;e<o.length;e++){let{Field:r,Type:t,Null:a,Key:s,Default:n,Extra:l}=o[e],u={fieldName:r,dataType:t.toUpperCase()};a?.match(/^no$/i)&&(u.notNullValue=!0),s?.match(/^pri$/i)&&(u.primaryKey=!0),n?.toString()?.match(/./)&&(u.defaultValue=n),n?.toString()?.match(/timestamp/i)&&(deleteu.defaultValue,u.defaultValueLiteral=n),l?.toString()?.match(/auto_increment/i)&&(u.autoIncrement=!0),i.fields.push(u)}letu=await(0,m.A)({database:r.db_full_name,queryString:`SHOW INDEXES FROM ${r.db_full_name}.${l}`});if(u)for(lete=0;e<u.length;e++){let{Table:r,Key_name:t,Column_name:a,Null:s,Index_type:n,Index_comment:l}=u[e];if(!l?.match(/^schema_index$/))continue;letc={indexType:n?.match(/fulltext/i)?"fullText":"regular",indexName:t,indexTableFields:[]},d=o?.filter(e=>e.Field===a)[0],m=i.indexes?.filter(e=>e.indexName==t);m&&m[0]?m[0].indexTableFields?.push({value:a,dataType:d.Type.toUpperCase()}):(c.indexTableFields=[{value:a,dataType:d.Type.toUpperCase()}],i.indexes?.push(c))}a.tables.push(i)}return(0,_.A)({schemaData:t,userId:e}),!0}catch(e){returnconsole.log(e),!1}}varg=t(67619),y=t(69842);asyncfunctionb(e,r){if("POST"!==e.method)returnr.json({msg:"Failed!"});lett=await(0,y.A)(e,r,!0);if(!t)returnr.json({success:!1,msg:"Unauthorized"});let{database:a,fileBase64:s}=e.body;a?.db_full_name?.match(/datasquirel_user_.*/)||r.json({success:!1,msg:"Unauthorized"});try{lete=`user-${t.id}-temp-sql`,n=c().platform().match(/win/i)?"'C:\\Program Files\\MySQL\\MySQL Server 8.0\\bin\\mysql.exe'":"mysql";o().writeFileSync(`./.tmp/${e}.sql`,s,"base64");letl={cwd:process.cwd()};c().platform().match(/win/i)&&(l.shell="bash.exe"),(0,d.execSync)(`${n} -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`,l);leti=awaitS({database:a,userId:t.id});r.json({success:!!i})}catch(e){console.log(e),(0,g.A)({component:"/api/importDatabase/catch-error",message:e.message,user:t}),r.json({success:!1,msg:"Import Failed!"})}}letE=(0,l.M)(a,"default"),A=(0,l.M)(a,"config"),v=news.PagesAPIRouteModule({definition:{kind:n.A.PAGES_API,page:"/api/importDatabase",pathname:"/api/importDatabase",bundlePath:"",filename:""},userland:a})},69842:(e,r,t)=>{t.d(r,{A:()=>o});vara=t(48786),s=t(95969),n=t(29021),l=t.n(n),i=t(89159);asyncfunctiono(e,r,t){try{let{keyCookieName:n,csrfCookieName:o}=(0,i.A)();if(!e.cookies?.[n]?.match(/./))throwError("Request Cookies not Found!");letu=(0,s.A)({encryptedString:e.cookies[n]});if(!u)