dsql-admin/dsql-app/.local_dist/server/pages/api/connect/handshake.js

1 line
8.7 KiB
JavaScript
Raw Normal View History

2025-01-13 08:00:21 +00:00
"use strict";(()=>{var e={};e.id=4065,e.ids=[4065],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")},55511:e=>{e.exports=require("crypto")},29021:e=>{e.exports=require("fs")},33873:e=>{e.exports=require("path")},79551:e=>{e.exports=require("url")},28354:e=>{e.exports=require("util")},96762:(e,t)=>{Object.defineProperty(t,"M",{enumerable:!0,get:function(){return function e(t,r){return r in t?t[r]:"then"in t&&"function"==typeof t.then?t.then(t=>e(t,r)):"function"==typeof t&&"default"===r?t:void 0}}})},63177:(e,t,r)=>{r.r(t),r.d(t,{config:()=>y,default:()=>E,routeModule:()=>D});var n={};r.r(n),r.d(n,{default:()=>h});var s=r(89947),a=r(2706),o=r(96762),i=r(76856),l=r(29021),u=r.n(l),c=r(33873),d=r.n(c);let _=async({userId:e,dbSchema:t,targetDb:r})=>(await (0,i.A)({userId:e,targetDatabase:r}),`User ${e} Db Schema Updated`),f=async({userId:e,dbSchema:t,database:r})=>{let n=d().resolve(String(process.env.DSQL_USER_DB_SCHEMA_PATH),`user-${e}`,"main.json"),s=JSON.parse(u().readFileSync(n,"utf-8")),a=s.findIndex(e=>e.dbFullName==r.db_full_name);if(a<0)throw Error("Target Database not found in user schema data");let o={...s[a]};return s[a]=t,s[a].dbName=o.dbName,s[a].dbFullName=o.dbFullName,s[a].dbSlug=o.dbSlug,s[a].dbImage=o.dbImage,await _({dbSchema:s,userId:e,targetDb:r.db_full_name})};var p=r(67619),S=r(69842),g=r(30802);r(29021),r(28354);let{URL:m}=r(79551);async function h(e,t){if("POST"!==e.method)return t.json({msg:"Failed!"});let r=await (0,S.A)(e,t,!0);if(!r)return t.json({success:!1,msg:"Unauthorized"});let{url:n,key:s,database:a,dbSchema:o,type:i,remoteDbs:l,targetDb:u}=e.body;try{if(!u?.tables)throw Error("No Target Database");await (0,g.A)({tableName:"user_databases",data:{remote_connected:1,remote_connection_host:n,remote_connection_key:s,remote_connection_type:i,remote_db_full_name:u.dbFullName},identifierColumnName:"db_full_name",identifierValue:a.db_full_name}),await f({dbSchema:u,database:a,userId:r.id}),t.json({success:!0})}catch(e){console.log("Connect Handshake Error, =>",e.message),(0,p.default)({component:"/api/connect/verify/main-catch-error",message:e.message,user:r}),t.json({success:!1,msg:"Operation Failed!"})}}let E=(0,o.M)(n,"default"),y=(0,o.M)(n,"config"),D=new s.PagesAPIRouteModule({definition:{kind:a.A.PAGES_API,page:"/api/connect/handshake",pathname:"/api/connect/handshake",bundlePath:"",filename:""},userland:n})},69842:(e,t,r)=>{r.d(t,{A:()=>l});var n=r(48786),s=r(95969),a=r(29021),o=r.n(a),i=r(89159);async function l(e,t,r){let{keyCookieName:a,csrfCookieName:l}=(0,i.A)();if(!e.cookies?.[a]?.match(/./))return null;let u=(0,s.A)({encryptedString:e.cookies[a]});if(!u)return null;let c=JSON.parse(u);if(!c.csrf_k||r&&!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(r&&!o().existsSync(`${d}/${c.csrf_k}`))return null;if(0==c.verification_status&&!r){let e=await (0,n.A)(`SELECT verification_status FROM users WHERE id='${c.id}'`);e&&e[0]&&1==e[0].verification_status&&t.setHeader("Set-Cookie",["user_refresh=1"])}return c?.date&&Date.now()-c.date>6048e5?null:c}},89159:(e,t,r)=>{r.d(t,{A:()=>n});function n(e){let t=process.env.DSQL_COOKIES_PREFIX||"dsql_",r=process.env.DSQL_COOKIES_KEY_NAME||"key",n=process.env.DSQL_COOKIES_CSRF_NAME||"csrf",s=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+_/,""),o=t;e?.userId&&(o+=`user_${e.userId}_`),a&&(o+=`${a}_`),o+=r;let i=t;e?.userId&&(i+=`user_${e.userId}_`),a&&(i+=`${a}_`),i+=n;let l=t;return e?.userId&&(l+=`user_${e.userId}_`),a&&(l+=`${a}_`),{keyCookieName:o,csrfCookieName:i,oneTimeCodeName:l+=s}}},30802:(e,t,r)=>{r.d(t,{A:()=>c});var n=r(72583),s=r.n(n),a=r(92652),o=r(48786),i=r(37275),l=r(6