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

1 line
4.8 KiB
JavaScript
Raw Normal View History

2025-01-13 08:00:21 +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 a={};t.r(a),t.d(a,{default:()=>f});var s=t(89947),n=t(2706),o=t(96762),i=t(60125),l=t(67619),d=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,d.A)(e,r,!0);if(!t)return r.json({success:!1,msg:"Unauthorized"});let{tableData:a}=e.body,s=e.body.database,n=e.body.dbSlug;e.body.delegated;let o=s.replace(/[^a-z\_0-9]/g,"");try{let l=await (0,i.A)({request:e,user:t,databaseSlug:n,query:e.query}),d=l?.rootUserId?l.rootUserId:t.id,_=`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${d}/main.json`,f=JSON.parse(c.readFileSync(_,"utf-8")),p=f.findIndex(e=>e.dbFullName===s),E=f[p].tables.findIndex(e=>e.childTable&&e.childTableDbFullName===a.childTableDbFullName&&e.childTableName===a.childTableName&&e.tableName===a.tableName);f[p].tables[E]=a,c.writeFileSync(`${_}`,JSON.stringify(f),"utf8"),await (0,u.A)({userId:d,targetDatabase:o}),r.json({success:!0})}catch(e){console.log(e.message),(0,l.default)({component:"/api/addApiKey/catch-error",message:e.message,user:t}),r.json({success:!1,msg:"Foreign Key update Failed."})}}let p=(0,o.M)(a,"default"),E=(0,o.M)(a,"config"),S=new s.PagesAPIRouteModule({definition:{kind:n.A.PAGES_API,page:"/api/updateClonedTableForeignKeys",pathname:"/api/updateClonedTableForeignKeys",bundlePath:"",filename:""},userland:a})},60125:(e,r,t)=>{t.d(r,{A:()=>s});var a=t(95969);async function s({request:e,databaseSlug:r,user:t,query:s}){try{let n=t.id,o=null;if(!s?.delegated)return{dbUserId:n};let i=s.dbUserId,l=`${process.env.DSQL_USER_DB_PREFIX}${i}_${r}`,d=`${process.env.DSQL_USER_DELEGATED_DB_COOKIE_PREFIX}${l}`;try{if(!e.cookies?.[d])throw Error("Cookie not present");let t=(0,a.A)({encryptedString:e.cookies[d]});if(!t)throw Error("Invalid Token");if((o=JSON.parse(t)).databaseSlug===r)return{dbUserId:n=o.rootUserId,rootUserId:o.rootUserId,rootUserName:o.rootUserName,rootUserEmail:o.rootUserEmail,rootUserImage:o.rootUserImage,databaseFullName:o.databaseFullName,databaseSlug:o.databaseSlug,allowedTables:o.allowedTables,priviledges:o.priviledges,database:o.databaseSlug,delegated:!0}}catch(e){}return{dbUserId:n}}catch(e){return null}}},69842:(e,r,t)=>{t.d(r,{A:()=>l});var a=t(48786),s=t(95969),n=t(29021),o=t.n(n),i=t(89159);async function l(e,r,t){let{keyCookieName:n,csrfCookieName:l}=(0,i.A)();if(!e.cookies?.[n]?.match(/./))return null;let d=(0,s.A)({encryptedString:e.cookies[n]});if(!d)return null;let u=JSON.parse(d);if(!u.csrf_k||t&&!Object.keys(e.headers).find(e=>e.includes(u.csrf_k)))return null;let c=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!c)return console.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(t&&!o().existsSync(`${c}/${u.csrf_k}`))return null;if(0==u.verification_status&&!t){let e=await (0,a.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"])}return u?.date&&Date.now()-u.date>6048e5?null:u}},89159:(e,r,t)=>{t.d(r,{A:()=>a});function a(e){let r=process.env.DSQL_COOKIES_PREFIX||"dsql_",t=process.env.DSQL_COOKIES_KEY_NAME||"key",a=process.env.DSQL_COOKIES_CSRF_NAME||"csrf",s=process.env.DSQL_COOKIES_ONE_TIME_CODE_NAME||"one-time-code",n=e?.database?.replace(/^datasquirel_user_\d+_/,"")||process.env.DSQL_DB_NAME?.replace(/^datasquirel_user_\d+_/,""),o=r;e?.userId&&(o+=`user_${e.userId}_`),n&&(o+=`${n}_`),o+=t;let i=r;e?.userI