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

16 lines
13 KiB
JavaScript
Raw Normal View History

2025-02-19 19:38:56 +00:00
"use strict";(()=>{var e={};e.id=7214,e.ids=[7214],e.modules={76102:e=>{e.exports=require("@moduletrace/datasquirel/dist/client")},39383:e=>{e.exports=require("@moduletrace/datasquirel/dist/package-shared/actions/users/user-auth")},65967:e=>{e.exports=require("@moduletrace/datasquirel/dist/package-shared/utils/ejson")},93726:e=>{e.exports=require("@moduletrace/datasquirel/dist/package-shared/utils/numberfy")},30889:e=>{e.exports=require("@moduletrace/datasquirel/dist/package-shared/utils/slugify")},75600:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},72583:e=>{e.exports=require("sanitize-html")},9973:e=>{e.exports=require("serverless-mysql")},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")},21820:e=>{e.exports=require("os")},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}}})},53382:(e,r,t)=>{t.r(r),t.d(r,{config:()=>g,default:()=>f,routeModule:()=>L});var a={};t.r(a),t.d(a,{default:()=>m});var n=t(89947),s=t(2706),o=t(96762),l=t(29021),i=t.n(l),c=t(21820),u=t.n(c),_=t(79646),d=t(30802),p=t(67619),S=t(69842),D=t(30944);async function m(e,r){if("POST"!==e.method)return r.json({msg:"Failed!"});let{user:t}=await (0,S.A)(e,r,!0);if(!t)return r.json({success:!1,msg:"Unauthorized"});let{id:a,db_name:n,db_slug:s,db_description:o,db_image:l,db_full_name:c,active_clone:m,active_clone_parent_db:f}=e.body;c?.match(/datasquirel_user_.*/)||r.json({success:!1,msg:"Unauthorized"});let g=`datasquirel_user_${t.id}_${s}`;if(await (0,d.A)({dbFullName:"datasquirel",tableName:"user_databases",identifierColumnName:"id",identifierValue:a,data:{db_name:n,db_slug:s,db_description:o,db_image:l,db_full_name:g}}),c&&c!==g){console.log("Renaming Database");let e=u().platform().match(/win/i)?"'C:\\Program Files\\MySQL\\MySQL Server 8.0\\bin\\mysql.exe'":"mysql",r=u().platform().match(/win/i)?"'C:\\Program Files\\MySQL\\MySQL Server 8.0\\bin\\mysqldump.exe'":"mysqldump";try{await (0,D.A)({queryString:`CREATE DATABASE \`${g}\` CHARACTER SET utf8mb4 COLLATE utf8mb4_bin`});let t={cwd:process.cwd()};u().platform().match(/win/i)&&(t.shell="bash.exe");let a=`${r} -u ${process.env.DSQL_DB_USERNAME} -h ${process.env.DSQL_DB_HOST} -p${process.env.DSQL_DB_PASSWORD} ${c} > tmpDbFile.sql`;console.log(`updateUserDatabase.ts exe => ${a}`),(0,_.execSync)(a,t),(0,_.execSync)(`${e} -u ${process.env.DSQL_DB_USERNAME} -h ${process.env.DSQL_DB_HOST} -p${process.env.DSQL_DB_PASSWORD} ${g} < tmpDbFile.sql`,t),await (0,D.A)({queryString:`DROP DATABASE \`${c}\``})}catch(e){(0,p.A)({component:"/api/updateUserDatabase/lines-88-111",message:e.message,user:t})}}try{let e=`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${t.id}/main.json`,a=JSON.parse(i().readFileSync(e,"utf8")),u=a.filter(e=>e.dbFullName===c);if(u[0].dbName=n,u[0].dbFullName=g,u[0].dbDescription=o,u[0].dbImage=l,u[0].dbSlug=s,m){let e=a.filter(e=>e.dbFullName===u[0].childDatabaseDbFullName)[0],r=e.childrenDatabases?.find(e=>e.dbFullName===c);r&&(r.dbFullName=g)}i().writeFileSync(`${e}`,JSON.stringify(a),"utf8"),r.json({success:!0})}catch(e){(0,p.A)({component:"/api/updateUserDatabase/main-catch-error",message:e.message,user:t}),r.json({success:!1,msg:"Database Files could not be written!"})}}let f=(0,o.M)(a,"default"),g=(0,o.M)(a,"config"),L=new n.PagesAPIRouteModule({definition:{kind:s.A.PAGES_API,page:"/api/updateUserDatabase",pathname:"/api/updateUserDatabase",bundlePath:"",filename:""},userland:a})},55153:(e,r,t)=>{t.d(r,{On:()=>n.a,_n:()=>o}),t(76102);var a=t(65967),n=t.n(a);t(30889);var s=t(93726);let o=t.n(s)()},69842:(e,r,t)=>{t.d(r,{A:()=>o});var a=t(39383),n=t.n(a),s=t(55153);async function o(e,r,t,a){let o=n()({req:e,level:t?"deep":void 0}),l={DSQL_REMOTE_SQL_HOST:process.env.DSQL_REMOTE_SQL_HOST,DSQL_SU_USER_ID:process.env.DSQL_SU_USER_ID,DSQL_HOST_ENV:process.env.DSQL_HOST_ENV,DSQL_HOST:process
2025-01-14 06:19:19 +00:00
Error Message: ${r}
2025-02-19 19:38:56 +00:00
Component: ${t}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(a+=`
2024-12-08 19:56:57 +00:00
User Id: ${e?.id}
User Name: ${e?.first_name} ${e?.last_name}
2025-02-19 19:38:56 +00:00
User Email: ${e?.email}`),s?.url&&(a+=`
URL: ${s.url}`),s?.body&&(a+=`
Request Body: ${JSON.stringify(s.body,null,4)}`),l&&(a+=`
IP: ${l}`),a+=`
2025-01-14 06:19:19 +00:00
Date: ${o.toDateString()}
2025-02-19 19:38:56 +00:00
========================================`,n().existsSync("./.tmp/error.log")||n().writeFileSync("./.tmp/error.log","","utf-8");let i=n().readFileSync("./.tmp/error.log","utf-8");n().writeFileSync("./.tmp/error.log",a),n().appendFileSync("./.tmp/error.log",`
2024-12-08 19:56:57 +00:00
2025-02-19 19:38:56 +00:00
${i}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},30944:(e,r,t)=>{t.d(r,{A:()=>l});var a=t(43775),n=t(67619),s=t(7447),o=t(64292);async function l({queryString:e,queryValuesArray:r,database:t,tableSchema:l,debug:i}){let c=(0,s.A)({fa:!0});global.DSQL_USE_LOCAL&&(c=(0,s.A)({local:!0})),t?.match(/^datasquirel$/)&&(c=(0,s.A)()),i&&(console.log("varDatabaseDbHandler:query:",e),console.log("varDatabaseDbHandler:values:",r),console.log("varDatabaseDbHandler:CONNECTION:",c.getConfig()));let u=await (0,o.A)(c,e,r);if(i&&console.log("varDatabaseDbHandler:results:",u),u&&l)try{return await (0,a.A)({unparsedResults:u,tableSchema:l})}catch(e){return console.log("\x1b[31mvarDatabaseDbHandler ERROR\x1b[0m =>",t,e),global.ERROR_CALLBACK?.("VarDb Handler Error",e),(0,n.A)({component:"varDatabaseDbHandler/lines-52-53",message:e.message}),null}else if(u)return u;else return null}},95969:(e,r,t)=>{t.d(r,{A:()=>o});var a=t(55511),n=t(79428),s=t(31542);function o({encryptedString:e,encryptionKey:r,encryptionSalt:t}){if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let{key:o,salt:l,keyLen:i,algorithm:c,bufferAllocSize:u}=(0,s.A)({encryptionKey:r});if(!o?.match(/.{8,}/))return console.log("Decrption key is invalid"),e;if(!l?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let _=(0,a.scryptSync)(o,l,i),d=n.Buffer.alloc(u,0),p=(0,a.createDecipheriv)(c,_,d);try{let r=p.update(e,"hex","utf8");return r+=p.final("utf8")}catch(r){return console.log("Error in decrypting =>",r.message),global.ERROR_CALLBACK?.("Error Decrypting data",r),e}}},68829:(e,r,t)=>{t.d(r,{A:()=>o});var a=t(55511),n=t(79428),s=t(31542);function o({data:e,encryptionKey:r,encryptionSalt:t}){if(!e?.match(/./))return console.log("Encryption string is invalid"),e;let{key:o,salt:l,keyLen:i,algorithm:c,bufferAllocSize:u}=(0,s.A)({encryptionKey:r});if(!o?.match(/.{8,}/))return console.log("Encryption key is invalid"),e;if(!l?.match(/.{8,}/))return console.log("Encryption salt is invalid"),e;let _=(0,a.scryptSync)(o,l,i),d=n.Buffer.alloc(u,0),p=(0,a.createCipheriv)(c,_,d);try{let r=p.update(e,"utf8","hex");return r+=p.final("hex")}catch(r){return console.log("Error in encrypting =>",r.message),global.ERROR_CALLBACK?.("Error Encrypting Data",r),e}}},52939:(e,r,t)=>{t.d(r,{A:()=>a});function a({dbContext:e,dbFullName:r}){return!e?.match(/dsql.user/i)&&(!!global.DSQL_USE_LOCAL||!r||!!r.match(/^datasquirel$/))}},64292:(e,r,t)=>{async function a(e,r,t){try{if(!e)throw Error("No Connection Found!");if(!r)throw Error("Query String Required!");if("string"==typeof r){let a=await e.query(n(r),t);return JSON.parse(JSON.stringify(a))}if("object"!=typeof r)return null;{let t=[];for(let a=0;a<r.length;a++)try{let s=r[a],o=await e.query(n(s.query),s.values);t.push(JSON.parse(JSON.stringify(o)))}catch(e){global.ERROR_CALLBACK?.("Connection DB Handler Query Error",e),t.push(null)}return t}}catch(e){return global.ERROR_CALLBACK?.("Connection DB Handler Error",e),null}finally{e?.end()}}function n(e){return e.replace(/\n/gm,"").replace(/ {2,}/g,"").trim()}t.d(r,{A:()=>a})},7447:(e,r,t)=>{t.d(r,{A:()=>s});var a=t(9973),n=t.n(a);function s(e){return global.DSQL_USE_LOCAL||e?.local?global.DSQL_DB_CONN||n()({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_USERNAME,password:process.env.DSQL_DB_PASSWORD,database:e?.noDb?void 0:process.env.DSQL_DB_NAME,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void 0,charset:"utf8mb4"}}):e?.ro?global.DSQL_READ_ONLY_DB_CONN||n()({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_READ_ONLY_USERNAME,password:process.env.DSQL_DB_READ_ONLY_PASSWORD,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void 0,charset:"utf8mb4"}}):e?.fa?global.DSQL_FULL_ACCESS_DB_CONN||n()({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_FULL_ACCESS_USERNAME,password:process.env.DSQL_DB_FULL_ACCESS_PASSWORD,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void 0,charset:"utf8mb4"}}):global.DSQL_DB_CONN||n()({config:{host:process.env.DSQL_DB_HOST,user:proces