dsql-admin/dsql-app/.local_dist/server/chunks/2451.js

25 lines
14 KiB
JavaScript
Raw Normal View History

2024-12-06 13:24:26 +00:00
"use strict";exports.id=2451,exports.ids=[2451],exports.modules={48225:(e,a,t)=>{let l=t(29021),{IncomingMessage:r}=t(81630);e.exports=async function({user:e,message:a,component:t,noMail:r,req:i}){let n=new Date,d=(()=>{if(!i)return null;try{let e=i.headers["x-forwarded-for"],a=i.headers["x-real-ip"],t=i.headers["cf-connecting-ip"],l=Array.isArray(e)?e[0]:e?.split(",")[0],r=t||l||a||i.socket.remoteAddress;if(!r)return null;return String(r)}catch(e){return null}})();try{let r=`🚀 SERVER ERROR ===========================
Error Message: ${a}
Component: ${t}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(r+=`
User Id: ${e?.id}
User Name: ${e?.first_name} ${e?.last_name}
User Email: ${e?.email}`),i?.url&&(r+=`
URL: ${i.url}`),i?.body&&(r+=`
Request Body: ${JSON.stringify(i.body,null,4)}`),d&&(r+=`
IP: ${d}`),r+=`
Date: ${n.toDateString()}
========================================`,l.existsSync("./.tmp/error.log")||l.writeFileSync("./.tmp/error.log","","utf-8");let s=l.readFileSync("./.tmp/error.log","utf-8");l.writeFileSync("./.tmp/error.log",r),l.appendFileSync("./.tmp/error.log",`
${s}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},72835:(e,a,t)=>{let{scryptSync:l,createDecipheriv:r}=t(55511),{Buffer:i}=t(79428);e.exports=({encryptedString:e,encryptionKey:a,encryptionSalt:t})=>{if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let n=a||process.env.DSQL_ENCRYPTION_PASSWORD,d=t||process.env.DSQL_ENCRYPTION_SALT,s=process.env.DSQL_ENCRYPTION_KEY_LENGTH?Number(process.env.DSQL_ENCRYPTION_KEY_LENGTH):24;if(!n?.match(/.{8,}/))return console.log("Decrption key is invalid"),e;if(!d?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let o=r("aes-192-cbc",l(n,d,s),i.alloc(16,0));try{let a=o.update(e,"hex","utf8");return a+=o.final("utf8")}catch(a){return console.log("Error in decrypting =>",a.message),e}}},19261:(e,a,t)=>{let l=t(33873),r=t(29021);t(60818).config({path:"./../.env"});let i=t(3444),n=t(38864),d=t(12452),s=t(35031),o=t(16926),u=t(27836),E=process.argv.find(e=>"--exec"===e);async function c({userId:e,targetDatabase:a,dbSchemaData:t}){let E=e?l.join(String(process.env.DSQL_USER_DB_SCHEMA_PATH),`/user-${e}/main.json`):l.resolve(__dirname,"../../jsonData/dbSchemas/main.json"),N=t||u.parse(r.readFileSync(E,"utf8"));if(!N){console.log("Schema Not Found!");return}for(let t=0;t<N.length;t++){let l=N[t],{dbFullName:r,tables:u,dbName:E,dbSlug:f,childrenDatabases:T}=l;if(a&&r!=a)continue;let _=await i(`SELECT SCHEMA_NAME AS dbFullName FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '${r}'`);_&&_[0]?.dbFullName||await i(`CREATE DATABASE IF NOT EXISTS \`${r}\` CHARACTER SET utf8mb4 COLLATE utf8mb4_bin`);let b=await i(`SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='${r}'`);for(let a=0;a<b.length;a++){let{TABLE_NAME:t}=b[a];if(!u.filter(e=>e.tableName===t)[0]){let a=u.filter(e=>e.tableNameOld&&e.tableNameOld===t);a&&a[0]?(console.log("Renaming Table"),await n({queryString:`RENAME TABLE \`${a[0].tableNameOld}\` TO \`${a[0].tableName}\``,database:r})):(console.log(`Dropping Table from ${r}`),await n({queryString:`DROP TABLE \`${t}\``,database:r}),await o({query:"DELETE FROM user_database_tables WHERE user_id = ? AND db_slug = ? AND table_slug = ?",values:[e,f,t],database:"datasquirel"}))}}let m=e?await n({database:"datasquirel",queryString:"SELECT * FROM user_databases WHERE db_full_name = ?",queryValuesArray:[r]}):void 0,S=m?.[0];for(let a=0;a<u.length;a++){let t=u[a],{tableName:i,fields:o,indexes:E}=t,c=await n({queryString:`
SELECT EXISTS (
SELECT
TABLE_NAME
FROM
information_schema.TABLES
WHERE
TABLE_SCHEMA = ? AND
TABLE_NAME = ?
) AS tableExists`,queryValuesArray:[r,t.tableName],database:r});if(c&&c[0]?.tableExists>0){if(await s({dbFullName:r,tableName:i,tableNameFull:t.tableFullName,tableInfoArray:o,userId:e,dbSchema:N,tableIndexes:E,tableIndex:a,childDb:l.childDatabase||void 0,recordedDbEntry:S,tableSchema:t}),t.childrenTables&&t.childrenTables[0])for(let a=0;a<t.childrenTables.length;a++){let r=t.childrenTables[a];await s({dbFullName:r.dbNameFull,tableName:r.tableName,tableNameFull:r.tableNameFull,tableInfoArray:o,userId:e,dbSchema:N,tableIndexes:E,clone:!0,childDb:l.childDatabase||void 0,recordedDbEntry:S,tableSchema:t})}}else if(await d({tableName:i,tableInfoArray:o,dbFullName:r,dbSchema:N,tableSchema:t,recordedDbEntry:S}),E&&E[0]&&E&&E[0])for(let e=0;e<E.length;e++){let{indexType:a,indexName:t,indexTableFields:l,alias:d}=E[e];if(d?.match(/./))try{if(!(await n({queryString:`SHOW INDEXES FROM \`${i}\``,database:r})).filter(e=>e.Key_name===d)[0])throw Error("This Index Does not Exist")}catch(e){await n({queryString:`CREATE${a?.match(/fullText/i)?" FULLTEXT":""} INDEX \`${d}\` ON ${i}(${l?.map(e=>e.value).map(e=>`\`${e}\``).join(",")}) COMMENT 'schema_index'`,database:r})}}}if(T?.[0])for(let a=0;a<T.length;a++){let{dbFullName:t}=T[a];await c({userId:e,targetDatabase:t})}}}e.exports=c,E&&c({})},12452:(e,a,t)=>{let l=t(38864),r=t(74941),i=t(57897),n=t(16926);e.exports=async function({dbFullName:e,tableName:a,tableInfoArray:t,dbSchema:d,clone:s,tableSchema:o,recordedDbEntry:u}){let E=i({tableInfoArray:t}),c=[];c.push(`CREATE TABLE IF NOT EXISTS \`${a}\` (`);try{if(!u)throw Error("Recorded Db entry not found!");let e=await l({database:"datasquirel",queryString:"SELECT * FROM user_database_tables WHERE db_id = ? AND table_slug = ?",queryValuesArray:[u.id,o?.tableName]}),a=e?.[0];a?.id||await n({query:"INSERT INTO user_database_tables SET ?",values:{user_id:u.user_id,db_id:u.id,db_slug:u.db_slug,table_name:o?.tableFullName,table_slug:o?.tableName,child_table:o?.childTable?"1":null,child_table_parent_database:o?.childTableDbFullName||null,child_table_parent_table:o?.childTableName||null,date_created:Date(),date_created_code:Date.now(),date_updated:Date(),date_updated_code:Date.now()},database:"datasquirel"})}catch(e){}let N=!1,f=[];for(let e=0;e<E.length;e++){let a=E[e],{fieldName:t,dataType:l,nullValue:i,primaryKey:n,autoIncrement:d,defaultValue:s,defaultValueLiteral:o,foreignKey:u,updatedField:T,onUpdate:_,onUpdateLiteral:b,onDelete:m,onDeleteLiteral:S,defaultField:A,encrypted:p,json:R,newTempField:y,notNullValue:g,originName:h,plainText:D,pattern:O,patternFlags:$,richText:L}=a;u&&f.push({fieldName:t,...u});let{fieldEntryText:I,newPrimaryKeySet:C}=r({columnData:a,primaryKeySet:N});N=C;let M=f[0]?",":e===E.length-1?"":",";c.push(" "+I+M)}f[0]&&f.forEach((e,a,t)=>{let{fieldName:l,destinationTableName:r,destinationTableColumnName:i,cascadeDelete:n,cascadeUpdate:d,foreignKeyName:s}=e,o=a===f.length-1?"":",";c.push(` CONSTRAINT \`${s}\` FOREIGN KEY (\`${l}\`) REFERENCES \`${r}\`(${i})${n?" ON DELETE CASCADE":""}${d?" ON UPDATE CASCADE":""}${o}`)}),c.push(") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;");let T=c.join("\n");return await l({queryString:T,database:e})}},16926:(e,a,t)=>{let l=t(29021),r=t(33873),i=t(9973),n=t(21580),d=i({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,charset:"utf8mb4",ssl:n()}});e.exports=async function({query:e,values:a,database:t}){let s;t&&(d=i({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_USERNAME,password:process.env.DSQL_DB_PASSWORD,database:t,charset:"utf8mb4",ssl:n()}}));try{s=e&&a?await d.query(e,a):await d.query(e),await d.end()}catch(e){if(process.env.FIRST_RUN)return null;console.log("ERROR in dbHandler =>",e.message),console.log(e),console.log(d.config()),l.appendFileSync(r.resolve(__dirname,"../.tmp/dbErrorLogs.txt"),JSON.stringify(e,null,4)+"\n"+Date()+"\n\n\n","utf8"),s=null}return s?JSON.parse(JSON.stringify(s)):null}},74941:e=>{e.exp