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

8 lines
5.2 KiB
JavaScript
Raw Normal View History

2024-12-15 11:27:16 +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,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:()=>p,default:()=>d,routeModule:()=>f});var t={};r.r(t),r.d(t,{default:()=>c});var n=r(89947),i=r(2706),a=r(96762),u=r(51348),_=r.n(u),o=r(6420),l=r.n(o);async function c(e,s){if("GET"!==e.method)return s.json({msg:"Failed!"});let r=await l()(e,s);if(!r)return s.json({success:!1,msg:"Unauthorized"});let t=await _()(`
2024-12-08 19:56:57 +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
user_users.invited_user_id='${r.id}'
2024-12-15 11:27:16 +00:00
`),n=[];if(t&&t[0])for(let e=0;e<t.length;e++){let s=t[e],{database_access:r,user_id:i,user_priviledge:a}=s;if(!r?.match(/./))continue;let u=await _()(`SELECT * FROM user_databases WHERE (${r.split("|").map(e=>`db_slug='${e}'`).join(" OR ")}) AND user_id=${i}`);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:a})}}s.json({success:!0,databases:n})}let d=(0,a.M)(t,"default"),p=(0,a.M)(t,"config"),f=new n.PagesAPIRouteModule({definition:{kind:i.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),i=r(29021),a=r(31341);async function u(e,s,r,u){let{keyCookieName:_,csrfCookieName:o}=a();if(!e.cookies?.[_]?.match(/./))return null;let l=n({encryptedString:e.cookies[_]});if(!l)return null;let c=JSON.parse(l);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&&!i.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=process.env.DSQL_COOKIES_ONE_TIME_CODE_NAME||"one-time-code",i=e?.database?.replace(/^datasquirel_user_\d+_/,"")||process.env.DSQL_DB_NAME?.replace(/^datasquirel_user_\d+_/,""),a=s;e?.userId&&(a+=`user_${e.userId}_`),i&&(a+=`${i}_`),a+=r;let u=s;e?.userId&&(u+=`user_${e.userId}_`),i&&(u+=`${i}_`),u+=t;let _=s;return e?.userId&&(_+=`user_${e.userId}_`),i&&(_+=`${i}_`),{keyCookieName:a,csrfCookieName:u,oneTimeCodeName:_+=n}}},72835:(e,s,r)=>{let{scryptSync:t,createDecipheriv:n}=r(55511),{Buffer:i}=r(79428);e.exports=({encryptedString:e,encryptionKey:s,encryptionSalt:r})=>{if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let a=s||process.env.DSQL_ENCRYPTION_PASSWORD,u=r||process.env.DSQL_ENCRYPTION_SALT,_=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 o=n("aes-192-cbc",t(a,u,_),i.alloc(16,0));try{let s=o.update(e,"hex","utf8");return s+=o.final("utf8")}catch(s){return console.log("Error in decrypting =>",s.message),e}}},51348:(e,s,r)=>{let t=r(9973),n=r(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 s=await i.query(...e);return await i.end(),JSON.parse(JSON.stringify(s))}catch(e){return console.log("DB Error =>",e),{success:!1,error:e.message}}}e.exports=a},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})();