"use strict";(()=>{var e={};e.id=3382,e.ids=[3382],e.modules={76102:e=>{e.exports=require("@moduletrace/datasquirel/dist/client")},39383:e=>{e.exports=require("@moduletrace/datasquirel/dist/package-shared/actions/users/user-auth")},65967:e=>{e.exports=require("@moduletrace/datasquirel/dist/package-shared/utils/ejson")},93726:e=>{e.exports=require("@moduletrace/datasquirel/dist/package-shared/utils/numberfy")},30889:e=>{e.exports=require("@moduletrace/datasquirel/dist/package-shared/utils/slugify")},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")},55511:e=>{e.exports=require("crypto")},29021:e=>{e.exports=require("fs")},33873:e=>{e.exports=require("path")},84612:(e,r,s)=>{s.r(r),s.d(r,{config:()=>f,default:()=>m,routeModule:()=>D});var a={};s.r(a),s.d(a,{default:()=>S});var t=s(89947),i=s(2706),o=s(96762),u=s(29021),n=s.n(u),d=s(33873),l=s.n(d),_=s(67619),p=s(69842),c=s(10776);async function S(e,r){if("POST"!==e.method)return r.json({msg:"Failed!"});let{user:s,appData:a}=await (0,p.A)(e,r,!0);if(!s)return r.json({success:!1,msg:"Unauthorized"});let{database:t,fileBase64:i}=e.body;t?.db_full_name?.match(/datasquirel_user_.*/)||r.json({success:!1,msg:"Unauthorized"});try{let e=Buffer.from(i,"base64").toString("utf-8"),a=JSON.parse(e),o=l().resolve(String(process.env.DSQL_USER_DB_SCHEMA_PATH),`user-${s.id}/main.json`);if(!n().existsSync(o))return r.end();let u=JSON.parse(n().readFileSync(o,"utf-8")),d=u.find(e=>e.dbFullName==t.db_full_name);if(!d)throw Error("Database not found!");d.tables=a.tables,n().writeFileSync(o,JSON.stringify(u),"utf-8"),await (0,c.A)({userId:s.id,targetDatabase:t.db_full_name}),r.json({success:!0})}catch(e){console.log("JSON import ERROR =>",e.message),(0,_.A)({component:"/api/importDatabase/catch-error",message:e.message,user:s}),r.json({success:!1,msg:"Import Failed!"})}}let m=(0,o.M)(a,"default"),f=(0,o.M)(a,"config"),D=new t.PagesAPIRouteModule({definition:{kind:i.A.PAGES_API,page:"/api/importDatabaseSchema",pathname:"/api/importDatabaseSchema",bundlePath:"",filename:""},userland:a})},55153:(e,r,s)=>{s.d(r,{On:()=>t.a,_n:()=>o}),s(76102);var a=s(65967),t=s.n(a);s(30889);var i=s(93726);let o=s.n(i)()},69842:(e,r,s)=>{s.d(r,{A:()=>o});var a=s(39383),t=s.n(a),i=s(55153);async function o(e,r,s,a){let o=t()({req:e,level:s?"deep":void 0}),u={DSQL_REMOTE_SQL_HOST:process.env.DSQL_REMOTE_SQL_HOST,DSQL_SU_USER_ID:process.env.DSQL_SU_USER_ID,DSQL_HOST_ENV:process.env.DSQL_HOST_ENV,DSQL_HOST:process.env.DSQL_HOST,DSQL_STATIC_HOST:process.env.DSQL_STATIC_HOST,DSQL_GOOGLE_CLIENT_ID:process.env.DSQL_GOOGLE_CLIENT_ID,DSQL_TINY_MCE_API_KEY:process.env.DSQL_TINY_MCE_API_KEY};return a&&o.payload?.id&&(0,i._n)(process.env.DSQL_SU_USER_ID)!==o.payload.id?{user:null,appData:u}:{user:o.payload,appData:u}}}};var r=require("../../webpack-api-runtime.js");r.C(e);var s=e=>r(r.s=e),a=r.X(0,[6060,776],()=>s(84612));module.exports=a})();