"use strict";(()=>{var e={};e.id=3382,e.ids=[3382],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")},9973:e=>{e.exports=require("serverless-mysql")},29021:e=>{e.exports=require("fs")},33873:e=>{e.exports=require("path")},96762:(e,r)=>{Object.defineProperty(r,"M",{enumerable:!0,get:function(){return function e(r,s){return s in r?r[s]:"then"in r&&"function"==typeof r.then?r.then(r=>e(r,s)):"function"==typeof r&&"default"===s?r:void 0}}})},84612:(e,r,s)=>{s.r(r),s.d(r,{config:()=>f,default:()=>l,routeModule:()=>m});var t={};s.r(t),s.d(t,{default:()=>D});var n=s(89947),o=s(2706),a=s(96762),i=s(29021),u=s.n(i),_=s(33873),c=s.n(_),S=s(67619),d=s(69842),p=s(76856);async function D(e,r){if("POST"!==e.method)return r.json({msg:"Failed!"});let s=await (0,d.A)(e,r,!0);if(!s)return r.json({success:!1,msg:"Unauthorized"});let{database:t,fileBase64:n}=e.body;t?.db_full_name?.match(/datasquirel_user_.*/)||r.json({success:!1,msg:"Unauthorized"});try{let e=Buffer.from(n,"base64").toString("utf-8"),o=JSON.parse(e),a=c().resolve(String(process.env.DSQL_USER_DB_SCHEMA_PATH),`user-${s.id}/main.json`);if(!u().existsSync(a))return r.end();let i=JSON.parse(u().readFileSync(a,"utf-8")),_=i.find(e=>e.dbFullName==t.db_full_name);if(!_)throw Error("Database not found!");_.tables=o.tables,u().writeFileSync(a,JSON.stringify(i),"utf-8"),await (0,p.A)({userId:s.id,targetDatabase:t.db_full_name}),r.json({success:!0})}catch(e){console.log("JSON import ERROR =>",e.message),(0,S.A)({component:"/api/importDatabase/catch-error",message:e.message,user:s}),r.json({success:!1,msg:"Import Failed!"})}}let l=(0,a.M)(t,"default"),f=(0,a.M)(t,"config"),m=new n.PagesAPIRouteModule({definition:{kind:o.A.PAGES_API,page:"/api/importDatabaseSchema",pathname:"/api/importDatabaseSchema",bundlePath:"",filename:""},userland:t})},69842:(e,r,s)=>{s.d(r,{A:()=>o});var t=s(39908),n=s.n(t);async function o(e,r,s){let t=n()({req:e,level:s?"deep":void 0});return console.log(t),t.payload}},7447:(e,r,s)=>{s.d(r,{A:()=>o});var t=s(9973),n=s.n(t);function o(e){return e?.ro?DSQL_READ_ONLY_DB_CONN||n()({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_READ_ONLY_USERNAME,password:process.env.DSQL_DB_READ_ONLY_PASSWORD,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void 0,charset:"utf8mb4"}}):e?.fa?global.DSQL_FULL_ACCESS_DB_CONN||n()({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_FULL_ACCESS_USERNAME,password:process.env.DSQL_DB_FULL_ACCESS_PASSWORD,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void 0,charset:"utf8mb4"}}):global.DSQL_DB_CONN||n()({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_USERNAME,password:process.env.DSQL_DB_PASSWORD,database:e?.noDb?void 0:process.env.DSQL_DB_NAME,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void 0,charset:"utf8mb4"}})}},2706:(e,r)=>{Object.defineProperty(r,"A",{enumerable:!0,get:function(){return s}});var s=function(e){return e.PAGES="PAGES",e.PAGES_API="PAGES_API",e.APP_PAGE="APP_PAGE",e.APP_ROUTE="APP_ROUTE",e.IMAGE="IMAGE",e}({})},89947:(e,r,s)=>{e.exports=s(75600)}};var r=require("../../webpack-api-runtime.js");r.C(e);var s=e=>r(r.s=e),t=r.X(0,[9814],()=>s(84612));module.exports=t})();