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

8 lines
4.8 KiB
JavaScript
Raw Normal View History

2024-12-06 13:24:26 +00:00
"use strict";(()=>{var e={};e.id=7258,e.ids=[7258],e.modules={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")},55511:e=>{e.exports=require("crypto")},29021:e=>{e.exports=require("fs")},81630:e=>{e.exports=require("http")},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}}})},1199:(e,r,s)=>{s.r(r),s.d(r,{config:()=>f,default:()=>d,routeModule:()=>p});var t={};s.r(t),s.d(t,{default:()=>c});var n=s(89947),i=s(2706),a=s(96762),u=s(51348),o=s.n(u),l=s(6420),_=s.n(l);async function c(e,r){if("GET"!==e.method)return r.json({msg:"Failed!"});let s=await _()(e,r);if(!s)return r.json({success:!1,msg:"Unauthorized"});let t=await o()(`
2024-12-05 07:03:33 +00:00
SELECT
user_users.user_id,user_users.database_access,user_users.user_id,user_users.user_priviledge,users.first_name,users.last_name,users.email,users.image_thumbnail
FROM
user_users JOIN users ON user_users.user_id=users.id
WHERE
2024-12-06 13:24:26 +00:00
user_users.invited_user_id='${s.id}'
`),n=[];if(t&&t[0])for(let e=0;e<t.length;e++){let r=t[e],{database_access:s,user_id:i,user_priviledge:a}=r;if(!s?.match(/./))continue;let u=await o()(`SELECT * FROM user_databases WHERE (${s.split("|").map(e=>`db_slug='${e}'`).join(" OR ")}) AND user_id=${i}`);for(let e=0;e<u.length;e++){let s=u[e];n.push({id:s.id,user_id:r.user_id,first_name:r.first_name,last_name:r.last_name,email:r.email,image_thumbnail:r.image_thumbnail,db_name:s.db_name,db_slug:s.db_slug,db_full_name:s.db_full_name,db_image:s.db_image,db_description:s.db_description,date_created:s.date_created,user_priviledge:a})}}r.json({success:!0,databases:n})}let d=(0,a.M)(t,"default"),f=(0,a.M)(t,"config"),p=new n.PagesAPIRouteModule({definition:{kind:i.A.PAGES_API,page:"/api/getDelegatedDatabases",pathname:"/api/getDelegatedDatabases",bundlePath:"",filename:""},userland:t})},6420:(e,r,s)=>{s(81630);let t=s(51348),n=s(72835),i=s(29021),a=s(31341);async function u(e,r,s,u){let{keyCookieName:o,csrfCookieName:l}=a();if(!e.cookies?.[o]?.match(/./))return null;let _=n({encryptedString:e.cookies[o]});if(!_)return null;let c=JSON.parse(_);if(!c.csrf_k||s&&!e.headers["x-csrf-auth"]?.match(RegExp(`${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(s&&!i.existsSync(`${d}/${c.csrf_k}`))return null;if(0==c.verification_status&&!s){let e=await t(`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}e.exports=u},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")}}},72835:(e,r,s)=>{let{scryptSync:t,createDecipheriv:n}=s(55511),{Buffer:i}=s(79428);e.exports=({encryptedString:e,encryptionKey:r,encryptionSalt:s})=>{if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let a=r||process.env.DSQL_ENCRYPTION_PASSWORD,u=s||process.env.DSQL_ENCRYPTION_SALT,o=process.env.DSQL_ENCRYPTION_KEY_LENGTH?Number(process.env.DSQL_ENCRYPTION_KEY_LENGTH):24;if(!a?.match(/.{8,}/))return console.log("Decrption key is invalid"),e;if(!u?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let l=n("aes-192-cbc",t(a,u,o),i.alloc(16,0));try{let r=l.update(e,"hex","utf8");return r+=l.final("utf8")}catch(r){return console.log("Error in decrypting =>",r.message),e}}},51348:(e,r,s)=>{let t=s(9973),n=s(21580),i=t({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:n()}});async function a(...e){try{let r=await i.query(...e);return await i.end(),JSON.parse(JSON.stringify(r))}catch(e){return console.log("DB Error =>",e),{success:!1,error:e.message}}}e.exports=a},21580:(e,r,s)=>{let t=s(29021);e.exports=function(){let e=process.env.DSQL_SSL_DIR;if(!e?.match(/./))return;let r=`${e}/ca-cert.pem`;if(!t.existsSync(r)){console.log(`${r} does not exist`);return}return{ca:t.readFileSync(`${e}/ca-cert.pem`)}}},2706:(e,r)=>{var s;Object.defineProperty(r,"A",{enumerable:!0,get:function(){return s}}),function(e){e.PAGES="PAGES",e.PAGES_API="PAGES_API",e.APP_PAGE="APP_PAGE",e.APP_ROUTE="APP_ROUTE",e.IMAGE="IMAGE"}(s||(s={}))},89947:(e,r,s)=>{e.exports=s(75600)}};var r=require("../../webpack-api-runtime.js");r.C(e);var s=r(r.s=1199);module.exports=s})();