dsql-admin/dsql-app/.local_dist/server/pages/api/getDelegatedDatabases.js
Benjamin Toby 3ffd2d6777 Updates
2024-12-05 08:03:33 +01:00

8 lines
4.1 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 a=r(89947),i=r(2706),n=r(96762),u=r(51348),l=r.n(u),o=r(6420),_=r.n(o);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 l()(`
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}'
`),a=[];if(t&&t[0])for(let e=0;e<t.length;e++){let s=t[e],{database_access:r,user_id:i,user_priviledge:n}=s;if(!r?.match(/./))continue;let u=await l()(`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];a.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:n})}}s.json({success:!0,databases:a})}let d=(0,n.M)(t,"default"),f=(0,n.M)(t,"config"),p=new a.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),a=r(72907),i=r(29021);async function n(e,s,r,n){if(!e.cookies?.datasquirelAuthKey?.match(/./))return null;let u=a(e.cookies.datasquirelAuthKey);if(!u)return null;let l=JSON.parse(u);if(!l.csrf_k||r&&!e.headers["x-csrf-auth"]?.match(RegExp(`${l.csrf_k}`)))return null;let o=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!o)return console.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(r&&!i.existsSync(`${o}/${l.csrf_k}`))return null;if(0==l.verification_status&&!r){let e=await t(`SELECT verification_status FROM users WHERE id='${l.id}'`);e&&e[0]&&1==e[0].verification_status&&s.setHeader("Set-Cookie",["user_refresh=1"])}return l?.date&&Date.now()-l.date>6048e5?null:l}e.exports=n},72907:(e,s,r)=>{let{scryptSync:t,createDecipheriv:a}=r(55511),{Buffer:i}=r(79428);e.exports=e=>{let s=a("aes-192-cbc",t(process.env.DSQL_ENCRYPTION_PASSWORD||"",process.env.DSQL_ENCRYPTION_SALT||"",24),i.alloc(16,0));try{let r=s.update(e,"hex","utf8");return r+=s.final("utf8")}catch(e){return null}}},51348:(e,s,r)=>{let t=r(9973),a=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:a()}});async function n(...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=n},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})();