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

1 line
5.1 KiB
JavaScript
Raw Normal View History

2025-01-14 06:19:19 +00:00
"use strict";(()=>{var e={};e.id=3133,e.ids=[3133],e.modules={75600:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},79428:e=>{e.exports=require("buffer")},79646:e=>{e.exports=require("child_process")},55511:e=>{e.exports=require("crypto")},29021:e=>{e.exports=require("fs")},33873:e=>{e.exports=require("path")},96762:(e,r)=>{Object.defineProperty(r,"M",{enumerable:!0,get:function(){return function e(r,t){return t in r?r[t]:"then"in r&&"function"==typeof r.then?r.then(r=>e(r,t)):"function"==typeof r&&"default"===t?r:void 0}}})},25477:(e,r,t)=>{t.r(r),t.d(r,{config:()=>E,default:()=>p,routeModule:()=>S});var s={};t.r(s),t.d(s,{default:()=>f});var a=t(89947),o=t(2706),n=t(96762),i=t(60125),d=t(67619),l=t(69842),u=t(76856);let c=t(29021);t(33873);let{execSync:_}=t(79646);async function f(e,r){if("POST"!==e.method)return r.json({msg:"Failed!"});let t=await (0,l.A)(e,r,!0);if(!t)return r.json({success:!1,msg:"Unauthorized"});let{tableData:s}=e.body,a=e.body.database,o=e.body.dbSlug;e.body.delegated;let n=a.replace(/[^a-z\_0-9]/g,"");try{let d=await (0,i.A)({request:e,user:t,databaseSlug:o,query:e.query}),l=d?.rootUserId?d.rootUserId:t.id,_=`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${l}/main.json`,f=JSON.parse(c.readFileSync(_,"utf-8")),p=f.findIndex(e=>e.dbFullName===a),E=f[p].tables.findIndex(e=>e.childTable&&e.childTableDbFullName===s.childTableDbFullName&&e.childTableName===s.childTableName&&e.tableName===s.tableName);f[p].tables[E]=s,c.writeFileSync(`${_}`,JSON.stringify(f),"utf8"),await (0,u.A)({userId:l,targetDatabase:n}),r.json({success:!0})}catch(e){console.log(e.message),(0,d.default)({component:"/api/addApiKey/catch-error",message:e.message,user:t}),r.json({success:!1,msg:"Foreign Key update Failed."})}}let p=(0,n.M)(s,"default"),E=(0,n.M)(s,"config"),S=new a.PagesAPIRouteModule({definition:{kind:o.A.PAGES_API,page:"/api/updateClonedTableForeignKeys",pathname:"/api/updateClonedTableForeignKeys",bundlePath:"",filename:""},userland:s})},60125:(e,r,t)=>{t.d(r,{A:()=>a});var s=t(95969);async function a({request:e,databaseSlug:r,user:t,query:a}){try{let o=t.id,n=null;if(!a?.delegated)return{dbUserId:o};let i=a.dbUserId,d=`${process.env.DSQL_USER_DB_PREFIX}${i}_${r}`,l=`${process.env.DSQL_USER_DELEGATED_DB_COOKIE_PREFIX}${d}`;try{if(!e.cookies?.[l])throw Error("Cookie not present");let t=(0,s.A)({encryptedString:e.cookies[l]});if(!t)throw Error("Invalid Token");if((n=JSON.parse(t)).databaseSlug===r)return{dbUserId:o=n.rootUserId,rootUserId:n.rootUserId,rootUserName:n.rootUserName,rootUserEmail:n.rootUserEmail,rootUserImage:n.rootUserImage,databaseFullName:n.databaseFullName,databaseSlug:n.databaseSlug,allowedTables:n.allowedTables,priviledges:n.priviledges,database:n.databaseSlug,delegated:!0}}catch(e){}return{dbUserId:o}}catch(e){return null}}},69842:(e,r,t)=>{t.d(r,{A:()=>d});var s=t(48786),a=t(95969),o=t(29021),n=t.n(o),i=t(89159);async function d(e,r,t){try{let{keyCookieName:o,csrfCookieName:d}=(0,i.A)();if(!e.cookies?.[o]?.match(/./))throw Error("Request Cookies not Found!");let l=(0,a.A)({encryptedString:e.cookies[o]});if(!l)throw Error("Couldn't decrypt auth cookie!");let u=JSON.parse(l);if(!u.csrf_k)throw Error("No `csrf_k` present in user Object!");if(t&&!Object.keys(e.headers).find(e=>e.includes(u.csrf_k)))throw Error("Deep Auth Failed. `csrf` key not found in request headers!");let c=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!c)throw Error("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable.");if(t&&!n().existsSync(`${c}/${u.csrf_k}`))throw Error("Key not found in Auth Keys Folder!");if(0==u.verification_status&&!t){let e=await (0,s.A)(`SELECT verification_status FROM users WHERE id='${u.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}if(u?.date&&Date.now()-u.date>6048e5)throw Error("Key expired!");return u}catch(e){return console.log(`userAuth Error: ${e.message}`),null}}},89159:(e,r,t)=>{t.d(r,{A:()=>s});function s(e){let r=process.env.DSQL_COOKIES_PREFIX||"dsql_",t=process.env.DSQL_COOKIES_KEY_NAME||"key",s