"use strict";(()=>{var e={};e.id=3e3,e.ids=[3e3],e.modules={28187:e=>{e.exports=require("@moduletrace/datasquirel")},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")},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,a){return a in r?r[a]:"then"in r&&"function"==typeof r.then?r.then(r=>e(r,a)):"function"==typeof r&&"default"===a?r:void 0}}})},96257:(e,r,a)=>{a.r(r),a.d(r,{config:()=>E,default:()=>D,routeModule:()=>f});var t={};a.r(t),a.d(t,{default:()=>S});var i=a(89947),s=a(2706),n=a(96762),o=a(29021),l=a.n(o),d=a(67619),u=a(69842),c=a(6346),_=a(28187),p=a.n(_);async function S(e,r){if("POST"!==e.method)return r.json({msg:"Failed!"});let{user:a}=await (0,u.A)(e,r,!0);if(!a)return r.json({success:!1,msg:"Unauthorized"});let{id:t,db_slug:i,db_full_name:s}=e.body;if(!s.match(`user_${a.id}_`))throw Error("Database doesn't belong to user");await p().utils.connDbHandler(global.DSQL_DB_CONN,`DROP DATABASE \`${s}\``),await p().utils.connDbHandler(global.DSQL_DB_CONN,"DELETE FROM user_databases WHERE id = ? AND user_id = ?",[t,a.id]),await p().utils.connDbHandler(global.DSQL_DB_CONN,"DELETE FROM user_database_tables WHERE db_id = ? AND user_id = ?",[t,a.id]),await p().utils.connDbHandler(global.DSQL_DB_CONN,"DELETE FROM user_users WHERE user_id = ? AND `database` = ?",[a.id,i]);try{let e;let{userSchemaMainJSONFilePath:t}=(0,c.A)({userId:a.id});if(!t)throw Error("`userSchemaMainJSONFilePath` path not found");let i=JSON.parse(l().readFileSync(t,"utf8")),n=i.filter((r,a)=>{if(r.dbFullName===s)return e=a,!0});if(n[0].childDatabase){let e=i.filter(e=>e.dbFullName===n[0].childDatabaseDbFullName)[0],r=e.childrenDatabases?.findIndex(e=>e.dbFullName===n[0].childDatabaseDbFullName);e.childrenDatabases&&"number"==typeof r&&e.childrenDatabases.splice(r,1)}i.splice(e,1),l().writeFileSync(`${t}`,JSON.stringify(i),"utf8"),r.json({success:!0})}catch(e){(0,d.A)({component:"/api/deleteUserDatabase/main-catch-error",message:e.message,user:a}),r.json({success:!1,msg:"File Updates Failed"})}}let D=(0,n.M)(t,"default"),E=(0,n.M)(t,"config"),f=new i.PagesAPIRouteModule({definition:{kind:s.A.PAGES_API,page:"/api/deleteUserDatabase",pathname:"/api/deleteUserDatabase",bundlePath:"",filename:""},userland:t})},55153:(e,r,a)=>{a.d(r,{On:()=>i.a,_n:()=>n}),a(76102);var t=a(65967),i=a.n(t);a(30889);var s=a(93726);let n=a.n(s)()},69842:(e,r,a)=>{a.d(r,{A:()=>n});var t=a(39383),i=a.n(t),s=a(55153);async function n(e,r,a,t){let n=i()({req:e,level:a?"deep":void 0}),o={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.env.DSQL_HOST,DSQL_STATIC_HOST:process.env.DSQL_STATIC_HOST,DSQL_GOOGLE_CLIENT_ID:process.env.DSQL_GOOGLE_CLIENT_ID,DSQL_TINY_MCE_API_KEY:process.env.DSQL_TINY_MCE_API_KEY};return t&&n.payload?.id&&(0,s._n)(process.env.DSQL_SU_USER_ID)!==n.payload.id?{user:null,appData:o}:{user:n.payload,appData:o}}},67619:(e,r,a)=>{a.d(r,{A:()=>s});var t=a(29021),i=a.n(t);async function s({user:e,message:r,component:a,noMail:t,req:s}){let n=new Date,o=(()=>{if(!s)return null;try{let e=s.headers["x-forwarded-for"],r=s.headers["x-real-ip"],a=s.headers["cf-connecting-ip"],t=Array.isArray(e)?e[0]:e?.split(",")[0],i=a||t||r||s.socket.remoteAddress;if(!i)return null;return String(i)}catch(e){return null}})();try{let t=`🚀 SERVER ERROR ===========================
Error Message: ${r}
Component: ${a}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(t+=`
User Id: ${e?.id}
User Name: ${e?.first_name} ${e?.last_name}
User Email: ${e?.email}`),s?.url&&(t+=`
URL: ${s.url}`),s?.body&&(t+=`
Request Body: ${JSON.stringify(s.body,null,4)}`),o&&(t+=`
IP: ${o}`),t+=`
Date: ${n.toDateString()}
========================================`,i().existsSync("./.tmp/error.log")||i().writeFileSync("./.tmp/error.log","","utf-8");let l=i().readFileSync("./.tmp/error.log","utf-8");i().writeFileSync("./.tmp/error.log",t),i().appendFileSync("./.tmp/error.log",`




${l}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},6346:(e,r,a)=>{a.d(r,{A:()=>s});var t=a(33873),i=a.n(t);function s(e){let r=process.env.DSQL_APP_DIR,a=process.env.DSQL_DB_SCHEMA_DIR,t=".tmp";if(!r)throw Error("Please provide the `DSQL_APP_DIR` env variable.");if(!a)throw Error("Please provide the `DSQL_DB_SCHEMA_DIR` env variable.");let s=i().join(r,"package-shared"),n=i().join(s,"types/dsql.ts"),o=i().join(a,"main.json"),l=i().join(s,"data/defaultFields.json"),d=i().join(a,"users"),u=e?.user?.id?i().join(d,`user-${e.user.id}`):e?.userId?i().join(d,`user-${e.userId}`):void 0,c=u?i().join(u,"main.json"):void 0,_=u?i().join(u,"media"):void 0,p=u?i().join(u,"export"):void 0,S=p?i().join(p,"sql"):void 0,D=S?i().join(S,t):void 0,E=D?i().join(D,"schema.json"):void 0,f="db-export.zip",m=S?i().join(S,f):void 0,b="db-export.zip",A=S?i().join(S,b):void 0;return{schemasDir:a,userDirPath:u,mainShemaJSONFilePath:o,mainDbTypeDefFile:n,tempDirName:t,defaultTableFieldsJSONFilePath:l,usersSchemaDir:d,userSchemaMainJSONFilePath:c,userPrivateMediaDir:_,userPrivateExportsDir:p,userPrivateSQLExportsDir:S,userPrivateTempSQLExportsDir:D,userPrivateTempJSONSchemaFilePath:E,userPrivateDbExportZipFileName:f,userPrivateDbExportZipFilePath:m,userPrivateDbImportZipFileName:b,userPrivateDbImportZipFilePath:A,dbNginxLoadBalancerConfigFile:i().join(r,"docker/mariadb/load-balancer/config/template/nginx.conf")}}},2706:(e,r)=>{Object.defineProperty(r,"A",{enumerable:!0,get:function(){return a}});var a=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,a)=>{e.exports=a(75600)}};var r=require("../../webpack-api-runtime.js");r.C(e);var a=r(r.s=96257);module.exports=a})();