28 lines
8.7 KiB
JavaScript
28 lines
8.7 KiB
JavaScript
"use strict";(()=>{var e={};e.id=5757,e.ids=[5757],e.modules={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")},81630:e=>{e.exports=require("http")},33873:e=>{e.exports=require("path")},96762:(e,t)=>{Object.defineProperty(t,"M",{enumerable:!0,get:function(){return function e(t,r){return r in t?t[r]:"then"in t&&"function"==typeof t.then?t.then(t=>e(t,r)):"function"==typeof t&&"default"===r?t:void 0}}})},77379:(e,t,r)=>{r.r(t),r.d(t,{config:()=>b,default:()=>D,routeModule:()=>E});var s={};r.r(s),r.d(s,{default:()=>S});var a=r(89947),n=r(2706),l=r(96762),i=r(57638),o=r.n(i),c=r(77538),u=r.n(c),d=r(6420),p=r.n(d),_=r(51348),f=r.n(_);let m=r(29021);async function S(e,t){if("POST"!==e.method)return t.json({msg:"Failed!"});let r=await p()(e,t,!0);if(!r)return t.json({success:!1,msg:"Unauthorized"});let s=e.body,{id:a,user_id:n,table_name:l,table_slug:i,table_description:c}=s.table,{db_full_name:d}=s.database;await o()({database:d,queryString:`DROP TABLE \`${i}\``});let _=a?[a]:[i,r.id,s.database.id];await f()(a?"DELETE FROM user_database_tables WHERE id=?":"DELETE FROM user_database_tables WHERE table_slug=? AND user_id=? AND db_id=?",_);try{let e;let s=`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${r.id}/main.json`,a=JSON.parse(m.readFileSync(s,"utf8")),n=a.filter((e,t)=>{if(e.dbFullName===d)return!0}),l=n[0].tables.filter((t,r)=>{if(t?.tableName===i)return e=r,!0});if(l[0].childTable){let e;let t=a.filter(e=>e.dbFullName===l[0].childTableDbFullName)[0].tables.filter(e=>{if(e.tableName===l[0].childTableName)return!0})[0];t.childrenTables?.filter((t,r)=>{t.tableName===i&&(e=r)}),"number"==typeof e&&t.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 t=n[0].childrenDatabases[e];try{let e=a.filter(e=>e.dbFullName===t.dbFullName)[0];e.tables=n[0].tables,await f()("DELETE FROM user_database_tables WHERE table_slug=? AND user_id=? AND db_slug=?",[i,r.id,e.dbSlug])}catch(e){u()({component:"/api/deleteUserTable/lines-125-128",message:e.message,user:r})}}m.writeFileSync(`${s}`,JSON.stringify(a),"utf8"),t.json({success:!0})}catch(e){u()({component:"/api/deleteUserTable/main-catch-error",message:e.message,user:r}),t.json({success:!1,msg:"File Updates Failed"})}}let D=(0,l.M)(s,"default"),b=(0,l.M)(s,"config"),E=new a.PagesAPIRouteModule({definition:{kind:n.A.PAGES_API,page:"/api/deleteUserTable",pathname:"/api/deleteUserTable",bundlePath:"",filename:""},userland:s})},77538:(e,t,r)=>{let s=r(29021),{IncomingMessage:a}=r(81630);e.exports=async function({user:e,message:t,component:r,noMail:a,req:n}){let l=new Date,i=(()=>{if(!n)return null;try{let e=n.headers["x-forwarded-for"],t=n.headers["x-real-ip"],r=n.headers["cf-connecting-ip"],s=Array.isArray(e)?e[0]:e?.split(",")[0],a=r||s||t||n.socket.remoteAddress;if(!a)return null;return String(a)}catch(e){return null}})();try{let a=`🚀 SERVER ERROR ===========================
|
|
Error Message: ${t}
|
|
Component: ${r}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(a+=`
|
|
User Id: ${e?.id}
|
|
User Name: ${e?.first_name} ${e?.last_name}
|
|
User Email: ${e?.email}`),n?.url&&(a+=`
|
|
URL: ${n.url}`),n?.body&&(a+=`
|
|
Request Body: ${JSON.stringify(n.body,null,4)}`),i&&(a+=`
|
|
IP: ${i}`),a+=`
|
|
Date: ${l.toDateString()}
|
|
========================================`,s.existsSync("./.tmp/error.log")||s.writeFileSync("./.tmp/error.log","","utf-8");let o=s.readFileSync("./.tmp/error.log","utf-8");s.writeFileSync("./.tmp/error.log",a),s.appendFileSync("./.tmp/error.log",`
|
|
|
|
|
|
|
|
|
|
${o}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},6420:(e,t,r)=>{r(81630);let s=r(51348),a=r(72907),n=r(29021);async function l(e,t,r,l){if(!e.cookies?.datasquirelAuthKey?.match(/./))return null;let i=a(e.cookies.datasquirelAuthKey);if(!i)return null;let o=JSON.parse(i);if(!o.csrf_k||r&&!e.headers["x-csrf-auth"]?.match(RegExp(`${o.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(r&&!n.existsSync(`${c}/${o.csrf_k}`))return null;if(0==o.verification_status&&!r){let e=await s(`SELECT verification_status FROM users WHERE id='${o.id}'`);e&&e[0]&&1==e[0].verification_status&&t.setHeader("Set-Cookie",["user_refresh=1"])}return o?.date&&Date.now()-o.date>6048e5?null:o}e.exports=l},72907:(e,t,r)=>{let{scryptSync:s,createDecipheriv:a}=r(55511),{Buffer:n}=r(79428);e.exports=e=>{let t=a("aes-192-cbc",s(process.env.DSQL_ENCRYPTION_PASSWORD||"",process.env.DSQL_ENCRYPTION_SALT||"",24),n.alloc(16,0));try{let r=t.update(e,"hex","utf8");return r+=t.final("utf8")}catch(e){return null}}},30003:e=>{e.exports=/^id$|^uuid$|^date_created$|^date_created_code$|^date_created_timestamp$|^date_updated$|^date_updated_code$|^date_updated_timestamp$/},6061:(e,t,r)=>{let s=r(72907),a=r(30003);e.exports=async function({unparsedResults:e,tableSchema:t}){let r=[];try{for(let n=0;n<e.length;n++){let l=e[n],i=Object.keys(l);for(let e=0;e<i.length;e++){let r=i[e],n=t?.fields[e];if(r?.match(a))continue;let o=l[r];("number"==typeof o||o)&&n?.encrypted&&o?.match(/./)&&(l[r]=s(o))}r.push(l)}return r}catch(t){return console.log("ERROR in parseDbResults Function =>",t.message),e}}},48225:(e,t,r)=>{let s=r(29021);e.exports=async function({user:e,message:t,component:r,noMail:a}){let n=`🚀 SERVER ERROR ===========================
|
|
User Id: ${e?.id}
|
|
User Name: ${e?.first_name} ${e?.last_name}
|
|
User Email: ${e?.email}
|
|
Error Message: ${t}
|
|
Component: ${r}
|
|
Date: ${Date()}
|
|
========================================`;s.existsSync("./.tmp/error.log")||s.writeFileSync("./.tmp/error.log","","utf-8");let l=s.readFileSync("./.tmp/error.log","utf-8");s.writeFileSync("./.tmp/error.log",n),s.appendFileSync("./.tmp/error.log",`
|
|
|
|
|
|
|
|
|
|
${l}`)}},57638:(e,t,r)=>{r(29021);let s=r(6061),a=r(48225),n=r(51348),l=r(21339);e.exports=async function({queryString:e,queryValuesArray:t,database:r,tableSchema:i}){let o;let c=!!r?.match(/^datasquirel$/),u=c?n:l;try{o=e&&t&&Array.isArray(t)&&t[0]?c?await u(e,t):await u({paradigm:"Full Access",database:r,queryString:e,queryValues:t}):c?await u(e):await u({paradigm:"Full Access",database:r,queryString:e})}catch(e){a({component:"varDatabaseDbHandler/lines-29-32",message:e.message})}if(o&&i)try{let e=o;return await s({unparsedResults:e,tableSchema:i})}catch(e){return console.log("\x1b[31mvarDatabaseDbHandler ERROR\x1b[0m =>",r,e),a({component:"varDatabaseDbHandler/lines-52-53",message:e.message}),null}else if(o)return o;else return null}},51348:(e,t,r)=>{let s=r(9973),a=r(21580),n=s({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_USERNAME,password:process.env.DSQL_DB_PASSWORD,database:process.env.DSQL_DB_NAME,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void 0,charset:"utf8mb4",ssl:a()}});async function l(...e){try{let t=await n.query(...e);return await n.end(),JSON.parse(JSON.stringify(t))}catch(e){return console.log("DB Error =>",e),{success:!1,error:e.message}}}e.exports=l},21339:(e,t,r)=>{let s=r(29021);r(33873);let a=r(9973),n=r(21580),l=a({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_READ_ONLY_USERNAME,password:process.env.DSQL_DB_READ_ONLY_PASSWORD,charset:"utf8mb4",ssl:n()}});e.exports=function({paradigm:e,database:t,queryString:r,queryValues:i}){try{return new Promise((o,c)=>{let u=!!e?.match(/full.access|^fa$/i);try{function d(e){l.end(),o(JSON.parse(JSON.stringify(e)))}function p(e){l.end(),o({error:e.message,queryStringGenerated:r,queryValuesGenerated:i,sql:e.sql})}l=u?a({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_FULL_ACCESS_USERNAME,password:process.env.DSQL_DB_FULL_ACCESS_PASSWORD,database:t,ssl:n()}}):a({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_READ_ONLY_USERNAME,password:process.env.DSQL_DB_READ_ONLY_PASSWORD,database:t,ssl:n()}}),i&&Array.isArray(i)&&i[0]?l.query(r,i).then(d).catch(p):l.query(r).then(d).catch(p)}catch(e){s.appendFileSync("./.tmp/dbErrorLogs.txt",e.message+"\n"+Date()+"\n\n\n","utf8"),o({error:e.message})}})}catch(e){return{success:!1,error:e.message}}}},21580:(e,t,r)=>{let s=r(29021);e.exports=function(){let e=process.env.DSQL_SSL_DIR;if(!e?.match(/./))return;let t=`${e}/ca-cert.pem`;if(!s.existsSync(t)){console.log(`${t} does not exist`);return}return{ca:s.readFileSync(`${e}/ca-cert.pem`)}}},2706:(e,t)=>{var r;Object.defineProperty(t,"A",{enumerable:!0,get:function(){return r}}),function(e){e.PAGES="PAGES",e.PAGES_API="PAGES_API",e.APP_PAGE="APP_PAGE",e.APP_ROUTE="APP_ROUTE",e.IMAGE="IMAGE"}(r||(r={}))},89947:(e,t,r)=>{e.exports=r(75600)}};var t=require("../../webpack-api-runtime.js");t.C(e);var r=t(t.s=77379);module.exports=r})(); |