dsql-admin/dsql-app/.local_dist/server/pages/api/importDatabaseSchema.js

1 line
4.0 KiB
JavaScript
Raw Normal View History

2025-01-13 08:00:21 +00:00
"use strict";(()=>{var e={};e.id=3382,e.ids=[3382],e.modules={75600:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},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")},96762:(e,r)=>{Object.defineProperty(r,"M",{enumerable:!0,get:function(){return function e(r,t){return t in r?r[t]:"then"in r&&"function"==typeof r.then?r.then(r=>e(r,t)):"function"==typeof r&&"default"===t?r:void 0}}})},84612:(e,r,t)=>{t.r(r),t.d(r,{config:()=>S,default:()=>p,routeModule:()=>E});var s={};t.r(s),t.d(s,{default:()=>f});var n=t(89947),a=t(2706),i=t(96762),o=t(67619),u=t(69842),l=t(76856);let c=t(29021),d=t(33873);t(21820);let{execSync:_}=t(79646);async function f(e,r){if("POST"!==e.method)return r.json({msg:"Failed!"});let t=await (0,u.A)(e,r,!0);if(!t)return r.json({success:!1,msg:"Unauthorized"});let{database:s,fileBase64:n}=e.body;s?.db_full_name?.match(/datasquirel_user_.*/)||r.json({success:!1,msg:"Unauthorized"});try{let e=Buffer.from(n,"base64").toString("utf-8"),a=JSON.parse(e),i=d.resolve(String(process.env.DSQL_USER_DB_SCHEMA_PATH),`user-${t.id}/main.json`);if(!c.existsSync(i))return r.end();let o=JSON.parse(c.readFileSync(i,"utf-8")),u=o.find(e=>e.dbFullName==s.db_full_name);if(!u)throw Error("Database not found!");u.tables=a.tables,c.writeFileSync(i,JSON.stringify(o),"utf-8"),await (0,l.A)({userId:t.id,targetDatabase:s.db_full_name}),r.json({success:!0})}catch(e){console.log("JSON import ERROR =>",e.message),(0,o.default)({component:"/api/importDatabase/catch-error",message:e.message,user:t}),r.json({success:!1,msg:"Import Failed!"})}}let p=(0,i.M)(s,"default"),S=(0,i.M)(s,"config"),E=new n.PagesAPIRouteModule({definition:{kind:a.A.PAGES_API,page:"/api/importDatabaseSchema",pathname:"/api/importDatabaseSchema",bundlePath:"",filename:""},userland:s})},69842:(e,r,t)=>{t.d(r,{A:()=>u});var s=t(48786),n=t(95969),a=t(29021),i=t.n(a),o=t(89159);async function u(e,r,t){let{keyCookieName:a,csrfCookieName:u}=(0,o.A)();if(!e.cookies?.[a]?.match(/./))return null;let l=(0,n.A)({encryptedString:e.cookies[a]});if(!l)return null;let c=JSON.parse(l);if(!c.csrf_k||t&&!Object.keys(e.headers).find(e=>e.includes(c.csrf_k)))return null;let d=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!d)return console.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(t&&!i().existsSync(`${d}/${c.csrf_k}`))return null;if(0==c.verification_status&&!t){let e=await (0,s.A)(`SELECT verification_status FROM users WHERE id='${c.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}return c?.date&&Date.now()-c.date>6048e5?null:c}},89159:(e,r,t)=>{t.d(r,{A:()=>s});function s(e){let r=process.env.DSQL_COOKIES_PREFIX||"dsql_",t=process.env.DSQL_COOKIES_KEY_NAME||"key",s=process.env.DSQL_COOKIES_CSRF_NAME||"csrf",n=process.env.DSQL_COOKIES_ONE_TIME_CODE_NAME||"one-time-code",a=e?.database?.replace(/^datasquirel_user_\d+_/,"")||process.env.DSQL_DB_NAME?.replace(/^datasquirel_user_\d+_/,""),i=r;e?.userId&&(i+=`user_${e.userId}_`),a&&(i+=`${a}_`),i+=t;let o=r;e?.userId&&(o+=`user_${e.userId}_`),a&&(o+=`${a}_`),o+=s;let u=r;return e?.userId&&(u+=`user_${e.userId}_`),a&&(u+=`${a}_`),{keyCookieName:i,csrfCookieName:o,oneTimeCodeName:u+=n}}},48786:(e,r,t)=>{t.d(r,{A:()=>s});async function s(...e){let r=global.DSQL_DB_CONN;try{if(!r)throw Error("No Connection provided to DB_HANDLER function!");let t=await r.query(...e);return JSON.parse(JSON.stringify(t))}catch(e){return console.log("DB Error =>",e),{success:!1,error:e.message}}finally{await r?.end()}}},2706:(e,r)=>{Object.defineProperty(r,"A",{enumerable:!0,get:function(){return t}});var t=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,t)=>{e.exports=t(75600)}};var r=require("../../webpack-api-runtime.js");r.C(e);var t=e=>r(r.s=e),s=r.X(0,[2282],()=>t(84612));m