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

16 lines
8.4 KiB
JavaScript
Raw Normal View History

2025-01-14 15:27:08 +00:00
"use strict";(()=>{var e={};e.id=5757,e.ids=[5757],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")},79428:e=>{e.exports=require("buffer")},55511:e=>{e.exports=require("crypto")},29021:e=>{e.exports=require("fs")},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}}})},96332:(e,r,t)=>{t.r(r),t.d(r,{config:()=>D,default:()=>f,routeModule:()=>S});var a={};t.r(a),t.d(a,{default:()=>_});var s=t(89947),n=t(2706),l=t(96762),o=t(29021),i=t.n(o),c=t(30944),u=t(67619),d=t(69842),p=t(48786);async function _(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 a=e.body,{id:s,user_id:n,table_name:l,table_slug:o,table_description:_}=a.table,{db_full_name:f}=a.database;await (0,c.A)({database:f,queryString:`DROP TABLE \`${f}\`.\`${o}\``});let D=s?[s]:[o,t.id,a.database.id];await (0,p.A)(s?"DELETE FROM user_database_tables WHERE id=?":"DELETE FROM user_database_tables WHERE table_slug=? AND user_id=? AND db_id=?",D);try{let e;let a=`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${t.id}/main.json`,s=JSON.parse(i().readFileSync(a,"utf8")),n=s.filter((e,r)=>{if(e.dbFullName===f)return!0}),l=n[0].tables.filter((r,t)=>{if(r?.tableName===o)return e=t,!0});if(l[0].childTable){let e;let r=s.filter(e=>e.dbFullName===l[0].childTableDbFullName)[0].tables.filter(e=>{if(e.tableName===l[0].childTableName)return!0})[0];r.childrenTables?.filter((r,t)=>{r.tableName===o&&(e=t)}),"number"==typeof e&&r.childrenTables?.splice(e,1)}if(n[0].tables.splice(e,1),n[0].childrenDatabases)for(let e=0;e<n[0].childrenDatabases.length;e++){let r=n[0].childrenDatabases[e];try{let e=s.filter(e=>e.dbFullName===r.dbFullName)[0];e.tables=n[0].tables,await (0,p.A)("DELETE FROM user_database_tables WHERE table_slug=? AND user_id=? AND db_slug=?",[o,t.id,e.dbSlug])}catch(e){(0,u.A)({component:"/api/deleteUserTable/lines-125-128",message:e.message,user:t})}}i().writeFileSync(`${a}`,JSON.stringify(s),"utf8"),r.json({success:!0})}catch(e){(0,u.A)({component:"/api/deleteUserTable/main-catch-error",message:e.message,user:t}),r.json({success:!1,msg:"File Updates Failed"})}}let f=(0,l.M)(a,"default"),D=(0,l.M)(a,"config"),S=new s.PagesAPIRouteModule({definition:{kind:n.A.PAGES_API,page:"/api/deleteUserTable",pathname:"/api/deleteUserTable",bundlePath:"",filename:""},userland:a})},69842:(e,r,t)=>{t.d(r,{A:()=>n});var a=t(39908),s=t.n(a);async function n(e,r,t){let a=s()({req:e,level:t?"deep":void 0});return console.log(a),a.payload}},43775:(e,r,t)=>{t.d(r,{A:()=>n});var a=t(95969);let s=/^id$|^uuid$|^date_created$|^date_created_code$|^date_created_timestamp$|^date_updated$|^date_updated_code$|^date_updated_timestamp$/;async function n({unparsedResults:e,tableSchema:r}){let t=[];try{for(let n=0;n<e.length;n++){let l=e[n],o=Object.keys(l);for(let e=0;e<o.length;e++){let t=o[e],n=r?.fields[e];if(t?.match(s))continue;let i=l[t];("number"==typeof i||i)&&n?.encrypted&&i?.match(/./)&&(l[t]=(0,a.A)({encryptedString:i}))}t.push(l)}return t}catch(r){return console.log("ERROR in parseDbResults Function =>",r.message),e}}},67619:(e,r,t)=>{t.d(r,{A:()=>n});var a=t(29021),s=t.n(a);async function n({user:e,message:r,component:t,noMail:a,req:n}){let l=new Date,o=(()=>{if(!n)return null;try{let e=n.headers["x-forwarded-for"],r=n.headers["x-real-ip"],t=n.headers["cf-connecting-ip"],a=Array.isArray(e)?e[0]:e?.split(",")[0],s=t||a||r||n.socket.remoteAddress;if(!s)return null;return String(s)}catch(e){return null}})();try{let a=`🚀 SERVER ERROR ===========================
2024-12-08 19:56:57 +00:00
Error Message: ${r}
2025-01-14 15:27:08 +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-01-14 15:27:08 +00:00
User Email: ${e?.email}`),n?.url&&(a+=`
URL: ${n.url}`),n?.body&&(a+=`
Request Body: ${JSON.stringify(n.body,null,4)}`),o&&(a+=`
IP: ${o}`),a+=`
2024-12-08 19:56:57 +00:00
Date: ${l.toDateString()}
2025-01-14 15:27:08 +00:00
========================================`,s().existsSync("./.tmp/error.log")||s().writeFileSync("./.tmp/error.log","","utf-8");let i=s().readFileSync("./.tmp/error.log","utf-8");s().writeFileSync("./.tmp/error.log",a),s().appendFileSync("./.tmp/error.log",`
2024-12-08 19:56:57 +00:00
2025-01-14 15:27:08 +00:00
${i}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},30944:(e,r,t)=>{t.d(r,{A:()=>o});var a=t(43775),s=t(67619),n=t(7447),l=t(64292);async function o({queryString:e,queryValuesArray:r,database:t,tableSchema:o,useLocal:i,debug:c}){let u=(0,n.A)({fa:!0});i&&(u=(0,n.A)({local:!0})),t?.match(/^datasquirel$/)&&(u=(0,n.A)()),c&&(console.log("varDatabaseDbHandler:query:",e),console.log("varDatabaseDbHandler:values:",r));let d=await (0,l.A)(u,e,r);if(c&&console.log("varDatabaseDbHandler:results:",d),d&&o)try{return await (0,a.A)({unparsedResults:d,tableSchema:o})}catch(e){return console.log("\x1b[31mvarDatabaseDbHandler ERROR\x1b[0m =>",t,e),(0,s.A)({component:"varDatabaseDbHandler/lines-52-53",message:e.message}),null}else if(d)return d;else return null}},95969:(e,r,t)=>{t.d(r,{A:()=>l});var a=t(55511),s=t(79428),n=t(32443);function l({encryptedString:e,encryptionKey:r,encryptionSalt:t}){if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let{key:l,salt:o,keyLen:i,algorithm:c,bufferAllocSize:u}=(0,n.A)({encryptionKey:r});if(!l?.match(/.{8,}/))return console.log("Decrption key is invalid"),e;if(!o?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let d=(0,a.scryptSync)(l,o,i),p=s.Buffer.alloc(u,0),_=(0,a.createDecipheriv)(c,d,p);try{let r=_.update(e,"hex","utf8");return r+=_.final("utf8")}catch(r){return console.log("Error in decrypting =>",r.message),e}}},48786:(e,r,t)=>{t.d(r,{A:()=>s});var a=t(7447);async function s(...e){let r=(0,a.A)();try{if(!r)throw Error("No Connection provided to DB_HANDLER function!");let t=await r.query(...e);return JSON.parse(JSON.stringify(t))}catch(e){return console.log("DB Error =>",e),{success:!1,error:e.message}}finally{await r?.end()}}},64292:(e,r,t)=>{async function a(e,r,t){try{if("string"==typeof r){let a=await e.query(s(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 n=r[a],l=await e.query(s(n.query),n.values);t.push(JSON.parse(JSON.stringify(l)))}catch(e){t.push(null)}return t}}catch(e){return null}finally{e.end()}}function s(e){return e.replace(/\n/gm,"").replace(/ {2,}/g,"").trim()}t.d(r,{A:()=>a})},7447:(e,r,t)=>{t.d(r,{A:()=>n});var a=t(9973),s=t.n(a);function n(e){return e?.ro?DSQL_READ_ONLY_DB_CONN||s()({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||s()({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||s()({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"}})}},32443:(e,r,t)=>{t.d(r,{A:()=>a});function a(e){return{key:e?.encryptionKey||process.env.DSQL_ENCRYPTION_PASSWORD,keyLen:process.env.DSQL_ENCRYPTION_KEY_LENGTH?Number(process.env.DSQL_ENCRYPTION_KEY_LENGTH):24,salt:e?.encryptionSalt||process.env.DSQL_ENCRYPTION_SALT,apiKey:e?.apiKey||process.env.DSQL_API_KEY,algorithm:e?.algorithm||process.env.DSQL_ENCRYPTION_ALGORITHM||"aes-192-cbc",bufferAllocSize:e?.bufferAllocSize||(process.env.DSQL_ENCRYPTION_BUFFER_ALLOCATION_SIZE?function(e,r){try{let r=Number(e);if("number"!=typeof r||isNaN(r))return 0;return Math.round(r)}catch(e){return console.log(`Numberfy ERROR: ${e.message}`),0}}(process.env.DSQL_ENCRYPTION_BUFFER_ALLOCATION_SIZE):void 0)||16}}},2706:(e,r)=>{Object.defineProperty(r,"A",{enumerable:!0,get:function(){return t}});var t=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,t)=>{e.exports=t(75600)}};var r=require("../../webpack-api-runtime.js");r.C(e);var t=r(r