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

16 lines
5.4 KiB
JavaScript
Raw Normal View History

2025-01-14 15:27:08 +00:00
"use strict";(()=>{var e={};e.id=3e3,e.ids=[3e3],e.modules={39908:e=>{e.exports=require("@moduletrace/datasquirel/dist/users/user-auth")},75600:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},9973:e=>{e.exports=require("serverless-mysql")},29021:e=>{e.exports=require("fs")},96762:(e,r)=>{Object.defineProperty(r,"M",{enumerable:!0,get:function(){return function e(r,s){return s in r?r[s]:"then"in r&&"function"==typeof r.then?r.then(r=>e(r,s)):"function"==typeof r&&"default"===s?r:void 0}}})},96257:(e,r,s)=>{s.r(r),s.d(r,{config:()=>S,default:()=>_,routeModule:()=>f});var t={};s.r(t),s.d(t,{default:()=>p});var n=s(89947),a=s(2706),o=s(96762),i=s(29021),l=s.n(i),c=s(48786),u=s(67619),d=s(69842),D=s(14160);async function p(e,r){if("POST"!==e.method)return r.json({msg:"Failed!"});let s=await (0,d.A)(e,r,!0);if(!s)return r.json({success:!1,msg:"Unauthorized"});let{id:t,db_slug:n,db_full_name:a}=e.body;if(!a.match(`user_${s.id}_`))throw Error("Database doesn't belong to user");await (0,D.A)(`DROP DATABASE \`${a}\``),await (0,c.A)("DELETE FROM user_databases WHERE id = ?",[t]),await (0,c.A)("DELETE FROM user_users WHERE user_id = ? AND `database` = ?",[s.id,n]);try{let e;let t=`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${s.id}/main.json`,n=JSON.parse(l().readFileSync(t,"utf8")),o=n.filter((r,s)=>{if(r.dbFullName===a)return e=s,!0});if(o[0].childDatabase){let e=n.filter(e=>e.dbFullName===o[0].childDatabaseDbFullName)[0],r=e.childrenDatabases?.findIndex(e=>e.dbFullName===o[0].childDatabaseDbFullName);e.childrenDatabases&&"number"==typeof r&&e.childrenDatabases.splice(r,1)}n.splice(e,1),l().writeFileSync(`${t}`,JSON.stringify(n),"utf8"),r.json({success:!0})}catch(e){(0,u.A)({component:"/api/deleteUserDatabase/main-catch-error",message:e.message,user:s}),r.json({success:!1,msg:"File Updates Failed"})}}let _=(0,o.M)(t,"default"),S=(0,o.M)(t,"config"),f=new n.PagesAPIRouteModule({definition:{kind:a.A.PAGES_API,page:"/api/deleteUserDatabase",pathname:"/api/deleteUserDatabase",bundlePath:"",filename:""},userland:t})},69842:(e,r,s)=>{s.d(r,{A:()=>a});var t=s(39908),n=s.n(t);async function a(e,r,s){let t=n()({req:e,level:s?"deep":void 0});return console.log(t),t.payload}},14160:(e,r,s)=>{s.d(r,{A:()=>i});var t=s(29021),n=s.n(t),a=s(67619),o=s(47546);async function i(e){let r;"production".match(/dev/)&&n().appendFileSync("./.tmp/sqlQuery.sql",e+"\n"+Date()+"\n\n\n","utf8");try{r=await (0,o.A)(e)}catch(e){(0,a.A)({component:"noDatabaseDbHandler",message:e.message}),console.log("ERROR in noDatabaseDbHandler =>",e.message)}return r||null}},67619:(e,r,s)=>{s.d(r,{A:()=>a});var t=s(29021),n=s.n(t);async function a({user:e,message:r,component:s,noMail:t,req:a}){let o=new Date,i=(()=>{if(!a)return null;try{let e=a.headers["x-forwarded-for"],r=a.headers["x-real-ip"],s=a.headers["cf-connecting-ip"],t=Array.isArray(e)?e[0]:e?.split(",")[0],n=s||t||r||a.socket.remoteAddress;if(!n)return null;return String(n)}catch(e){return null}})();try{let t=`🚀 SERVER ERROR ===========================
2024-12-08 19:56:57 +00:00
Error Message: ${r}
2025-01-14 15:27:08 +00:00
Component: ${s}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(t+=`
2024-12-08 19:56:57 +00:00
User Id: ${e?.id}
User Name: ${e?.first_name} ${e?.last_name}
2025-01-14 15:27:08 +00:00
User Email: ${e?.email}`),a?.url&&(t+=`
URL: ${a.url}`),a?.body&&(t+=`
Request Body: ${JSON.stringify(a.body,null,4)}`),i&&(t+=`
IP: ${i}`),t+=`
2025-01-14 06:19:19 +00:00
Date: ${o.toDateString()}
2025-01-14 15:27:08 +00:00
========================================`,n().existsSync("./.tmp/error.log")||n().writeFileSync("./.tmp/error.log","","utf-8");let l=n().readFileSync("./.tmp/error.log","utf-8");n().writeFileSync("./.tmp/error.log",t),n().appendFileSync("./.tmp/error.log",`
2024-12-08 19:56:57 +00:00
2025-01-14 15:27:08 +00:00
${l}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},48786:(e,r,s)=>{s.d(r,{A:()=>n});var t=s(7447);async function n(...e){let r=(0,t.A)();try{if(!r)throw Error("No Connection provided to DB_HANDLER function!");let s=await r.query(...e);return JSON.parse(JSON.stringify(s))}catch(e){return console.log("DB Error =>",e),{success:!1,error:e.message}}finally{await r?.end()}}},47546:(e,r,s)=>{s.d(r,{A:()=>n});var t=s(7447);function n(...e){let r=(0,t.A)();try{return new Promise((s,t)=>{r.query(...e).then(e=>{r.end(),s(JSON.parse(JSON.stringify(e)))}).catch(e=>{r.end(),s({error:e.message,sql:e.sql})})})}catch(e){return{success:!1,error:e.message}}finally{r?.end()}}},7447:(e,r,s)=>{s.d(r,{A:()=>a});var t=s(9973),n=s.n(t);function a(e){return e?.ro?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: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"}})}},2706:(e,r)=>{Object.defineProperty(r,"A",{enumerable:!0,get:function(){return s}});var s=function(e){return e.PAGES="PAGES",e.PAGES_API="PAGES_API",e.APP_PAGE="APP_PAGE",e.APP_ROUTE="APP_ROUTE",e.IMAGE="IMAGE",e}({})},89947:(e,r,s)=>{e.exports=s(75600)}};var r=require("../../webpack-api-runtime.js");r.C(e);var s=r(r.s=96257);module.exports=s})();