dsql-admin/dsql-app/.local_dist/server/pages/api/user-schema/replace-database-schema.js
Benjamin Toby 8b7ea057d0 Updates
2024-12-06 14:24:26 +01:00

1 line
4.3 KiB
JavaScript

"use strict";(()=>{var e={};e.id=4105,e.ids=[4105],e.modules={60818:e=>{e.exports=require("dotenv")},27825:e=>{e.exports=require("lodash")},75600:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},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")},81630:e=>{e.exports=require("http")},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}}})},46127:(e,r,t)=>{t.r(r),t.d(r,{config:()=>v,default:()=>b,routeModule:()=>D});var s={};t.r(s),t.d(s,{default:()=>m});var a=t(89947),n=t(2706),i=t(96762),o=t(6420),c=t.n(o),u=t(48225),l=t.n(u);t(27825);var d=t(51348),f=t.n(d),p=t(33873),_=t.n(p);t(79646);var S=t(19261),E=t.n(S);let h=t(29021);async function m(e,r){if("POST"!==e.method)return r.json({user:null,msg:"Registration Failed!"});let t=await c()(e,r,!0);if(!t)return r.json({success:!1,msg:"Unauthorized"});let s=e.body.schema,a=e.body.dbId;try{let e=await f()("SELECT * FROM user_databases WHERE user_id = ? AND id = ?",[t.id,a]);if(!e?.[0])throw Error("Invalid Database");let n=e[0],i=_().resolve(process.cwd(),`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${t.id}/main.json`),o=JSON.parse(h.readFileSync(i,"utf-8")),c=o.find(e=>e.dbFullName==n.db_full_name);if(!c)throw Error("This Database doesn't exist");if(c.tables=s.tables,c.childrenDatabases)for(let e=0;e<c.childrenDatabases.length;e++){let{dbFullName:r}=c.childrenDatabases[e],t=o.find(e=>e.dbFullName===r);if(!t||!t.tables){c.childrenDatabases?.splice(e,1);continue}t.tables=s.tables}h.writeFileSync(`${i}`,JSON.stringify(o),"utf8"),await E()({userId:t.id,targetDatabase:n.db_full_name}),r.json({success:!0})}catch(s){l()({component:"/api/acceptUserInvitation/catch-error",message:s.message,user:t,req:e}),r.json({success:!1})}}let b=(0,i.M)(s,"default"),v=(0,i.M)(s,"config"),D=new a.PagesAPIRouteModule({definition:{kind:n.A.PAGES_API,page:"/api/user-schema/replace-database-schema",pathname:"/api/user-schema/replace-database-schema",bundlePath:"",filename:""},userland:s})},6420:(e,r,t)=>{t(81630);let s=t(51348),a=t(72835),n=t(29021),i=t(31341);async function o(e,r,t,o){let{keyCookieName:c,csrfCookieName:u}=i();if(!e.cookies?.[c]?.match(/./))return null;let l=a({encryptedString:e.cookies[c]});if(!l)return null;let d=JSON.parse(l);if(!d.csrf_k||t&&!e.headers["x-csrf-auth"]?.match(RegExp(`${d.csrf_k}`)))return null;let f=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!f)return console.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(t&&!n.existsSync(`${f}/${d.csrf_k}`))return null;if(0==d.verification_status&&!t){let e=await s(`SELECT verification_status FROM users WHERE id='${d.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}return d?.date&&Date.now()-d.date>6048e5?null:d}e.exports=o},31341:e=>{e.exports=function(){let e=process.env.DSQL_COOKIES_PREFIX||"dsql_";return{keyCookieName:e+(process.env.DSQL_COOKIES_KEY_NAME||"key"),csrfCookieName:e+(process.env.DSQL_COOKIES_CSRF_NAME||"csrf")}}},51348:(e,r,t)=>{let s=t(9973),a=t(21580),n=s({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_USERNAME,password:process.env.DSQL_DB_PASSWORD,database:process.env.DSQL_DB_NAME,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void 0,charset:"utf8mb4",ssl:a()}});async function i(...e){try{let r=await n.query(...e);return await n.end(),JSON.parse(JSON.stringify(r))}catch(e){return console.log("DB Error =>",e),{success:!1,error:e.message}}}e.exports=i},21580:(e,r,t)=>{let s=t(29021);e.exports=function(){let e=process.env.DSQL_SSL_DIR;if(!e?.match(/./))return;let r=`${e}/ca-cert.pem`;if(!s.existsSync(r)){console.log(`${r} does not exist`);return}return{ca:s.readFileSync(`${e}/ca-cert.pem`)}}},2706:(e,r)=>{var t;Object.defineProperty(r,"A",{enumerable:!0,get:function(){return t}}),function(e){e.PAGES="PAGES",e.PAGES_API="PAGES_API",e.APP_PAGE="APP_PAGE",e.APP_ROUTE="APP_ROUTE",e.IMAGE="IMAGE"}(t||(t={}))},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,[2451],()=>t(46127));module.exports=s})();