dsql-admin/dsql-app/.local_dist/server/pages/api/getDelegatedDatabases.js
Benjamin Toby 7a06e83a46 Updates
2024-12-08 20:56:57 +01:00

8 lines
4.9 KiB
JavaScript

"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,s)=>{Object.defineProperty(s,"M",{enumerable:!0,get:function(){return function e(s,r){return r in s?s[r]:"then"in s&&"function"==typeof s.then?s.then(s=>e(s,r)):"function"==typeof s&&"default"===r?s:void 0}}})},1199:(e,s,r)=>{r.r(s),r.d(s,{config:()=>f,default:()=>d,routeModule:()=>p});var t={};r.r(t),r.d(t,{default:()=>c});var n=r(89947),a=r(2706),i=r(96762),u=r(51348),o=r.n(u),l=r(6420),_=r.n(l);async function c(e,s){if("GET"!==e.method)return s.json({msg:"Failed!"});let r=await _()(e,s);if(!r)return s.json({success:!1,msg:"Unauthorized"});let t=await o()(`
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
user_users.invited_user_id='${r.id}'
`),n=[];if(t&&t[0])for(let e=0;e<t.length;e++){let s=t[e],{database_access:r,user_id:a,user_priviledge:i}=s;if(!r?.match(/./))continue;let u=await o()(`SELECT * FROM user_databases WHERE (${r.split("|").map(e=>`db_slug='${e}'`).join(" OR ")}) AND user_id=${a}`);for(let e=0;e<u.length;e++){let r=u[e];n.push({id:r.id,user_id:s.user_id,first_name:s.first_name,last_name:s.last_name,email:s.email,image_thumbnail:s.image_thumbnail,db_name:r.db_name,db_slug:r.db_slug,db_full_name:r.db_full_name,db_image:r.db_image,db_description:r.db_description,date_created:r.date_created,user_priviledge:i})}}s.json({success:!0,databases:n})}let d=(0,i.M)(t,"default"),f=(0,i.M)(t,"config"),p=new n.PagesAPIRouteModule({definition:{kind:a.A.PAGES_API,page:"/api/getDelegatedDatabases",pathname:"/api/getDelegatedDatabases",bundlePath:"",filename:""},userland:t})},6420:(e,s,r)=>{r(81630);let t=r(51348),n=r(72835),a=r(29021),i=r(31341);async function u(e,s,r,u){let{keyCookieName:o,csrfCookieName:l}=i();if(!e.cookies?.[o]?.match(/./))return null;let _=n({encryptedString:e.cookies[o]});if(!_)return null;let c=JSON.parse(_);if(!c.csrf_k||r&&!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(r&&!a.existsSync(`${d}/${c.csrf_k}`))return null;if(0==c.verification_status&&!r){let e=await t(`SELECT verification_status FROM users WHERE id='${c.id}'`);e&&e[0]&&1==e[0].verification_status&&s.setHeader("Set-Cookie",["user_refresh=1"])}return c?.date&&Date.now()-c.date>6048e5?null:c}e.exports=u},31341:e=>{e.exports=function(e){let s=process.env.DSQL_COOKIES_PREFIX||"dsql_",r=process.env.DSQL_COOKIES_KEY_NAME||"key",t=process.env.DSQL_COOKIES_CSRF_NAME||"csrf",n=s;e?.userId&&(n+=`user_${e.userId}_`),e?.database&&(n+=`${e.database}_`),n+=r;let a=s;return e?.userId&&(a+=`user_${e.userId}_`),e?.database&&(a+=`${e.database}_`),{keyCookieName:n,csrfCookieName:a+=t}}},72835:(e,s,r)=>{let{scryptSync:t,createDecipheriv:n}=r(55511),{Buffer:a}=r(79428);e.exports=({encryptedString:e,encryptionKey:s,encryptionSalt:r})=>{if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let i=s||process.env.DSQL_ENCRYPTION_PASSWORD,u=r||process.env.DSQL_ENCRYPTION_SALT,o=process.env.DSQL_ENCRYPTION_KEY_LENGTH?Number(process.env.DSQL_ENCRYPTION_KEY_LENGTH):24;if(!i?.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(i,u,o),a.alloc(16,0));try{let s=l.update(e,"hex","utf8");return s+=l.final("utf8")}catch(s){return console.log("Error in decrypting =>",s.message),e}}},51348:(e,s,r)=>{let t=r(9973),n=r(21580),a=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 i(...e){try{let s=await a.query(...e);return await a.end(),JSON.parse(JSON.stringify(s))}catch(e){return console.log("DB Error =>",e),{success:!1,error:e.message}}}e.exports=i},21580:(e,s,r)=>{let t=r(29021);e.exports=function(){let e=process.env.DSQL_SSL_DIR;if(!e?.match(/./))return;let s=`${e}/ca-cert.pem`;if(!t.existsSync(s)){console.log(`${s} does not exist`);return}return{ca:t.readFileSync(`${e}/ca-cert.pem`)}}},2706:(e,s)=>{var r;Object.defineProperty(s,"A",{enumerable:!0,get:function(){return r}}),function(e){e.PAGES="PAGES",e.PAGES_API="PAGES_API",e.APP_PAGE="APP_PAGE",e.APP_ROUTE="APP_ROUTE",e.IMAGE="IMAGE"}(r||(r={}))},89947:(e,s,r)=>{e.exports=r(75600)}};var s=require("../../webpack-api-runtime.js");s.C(e);var r=s(s.s=1199);module.exports=r})();