Bug Fixes
This commit is contained in:
@@ -34,7 +34,8 @@ const grabApiCred = ({ key, database, table }) => {
|
||||
.includes(String(table));
|
||||
if (isTableAllowed) return ApiObject;
|
||||
return null;
|
||||
} catch (error) {
|
||||
} catch (/** @type {any} */ error) {
|
||||
console.log(`api-cred ERROR: ${error.message}`);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -21,34 +21,6 @@ const connection = mysql({
|
||||
},
|
||||
});
|
||||
|
||||
// const connection = mysql.createConnection({
|
||||
// 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",
|
||||
// });
|
||||
|
||||
// connection.on("error", (err) => {
|
||||
// console.log("CONNECTION STATE: ", connection.state);
|
||||
// console.log(err.message);
|
||||
// });
|
||||
|
||||
// connection.on("connect", () => {
|
||||
// console.log("CONNECTION ACTIVE: ", connection.state);
|
||||
// });
|
||||
|
||||
// connection.on("end", () => {
|
||||
// console.log("CONNECTION DISCONNECTED: ", connection.state);
|
||||
// });
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Main DB Handler Function
|
||||
* ==============================================================================
|
||||
@@ -87,59 +59,9 @@ module.exports = async function dbHandler(...args) {
|
||||
resolve(result);
|
||||
}
|
||||
});
|
||||
|
||||
// connection.on("error", (err) => {
|
||||
// console.log("CONNECTION STATE: ", connection.state);
|
||||
// console.log(err.message);
|
||||
// });
|
||||
|
||||
// connection.on("connect", () => {
|
||||
// console.log("CONNECTION ACTIVE: ", connection.state);
|
||||
// });
|
||||
|
||||
// connection.on("end", () => {
|
||||
// console.log("CONNECTION DISCONNECTED: ", connection.state);
|
||||
// });
|
||||
|
||||
/** ********************* Clean up */
|
||||
});
|
||||
|
||||
await connection.end();
|
||||
|
||||
// connection.query(...args, (error, result, fields) => {
|
||||
// if (error) {
|
||||
// resolve({ error: error.message });
|
||||
// } else {
|
||||
// resolve(result);
|
||||
// }
|
||||
|
||||
// connection.end()
|
||||
// });
|
||||
// connectionPool.query(...args, (error, result, fields) => {
|
||||
// if (error) {
|
||||
// resolve({ error: error.message });
|
||||
// } else {
|
||||
// resolve(result);
|
||||
// }
|
||||
// });
|
||||
|
||||
// connectionPool.getConnection(function (err, connection) {
|
||||
// if (err) {
|
||||
// resolve({ error: err.message });
|
||||
// connection.release();
|
||||
// return;
|
||||
// }
|
||||
|
||||
// connection.query(...args, (error, result, fields) => {
|
||||
// if (error) {
|
||||
// resolve({ error: error.message });
|
||||
// } else {
|
||||
// resolve(result);
|
||||
// }
|
||||
|
||||
// connection.release();
|
||||
// });
|
||||
// });
|
||||
} catch (/** @type {any} */ error) {
|
||||
fs.appendFileSync(
|
||||
"./.tmp/dbErrorLogs.txt",
|
||||
@@ -153,12 +75,6 @@ module.exports = async function dbHandler(...args) {
|
||||
component: "dbHandler",
|
||||
message: error.message,
|
||||
});
|
||||
|
||||
// try {
|
||||
// connection.end();
|
||||
// } catch (error) {
|
||||
// console.log("ERROR in dbHandler Function =>", error.message);
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,35 +2,26 @@
|
||||
|
||||
const { scryptSync, createDecipheriv } = require("crypto");
|
||||
const { Buffer } = require("buffer");
|
||||
// const serverError = require("./serverError");
|
||||
|
||||
/**
|
||||
* @param {string} encryptedString
|
||||
* @returns {string | null}
|
||||
*/
|
||||
const decrypt = (encryptedString) => {
|
||||
// /** @type {import("crypto").CipherCCMTypes} */
|
||||
const algorithm = "aes-192-cbc";
|
||||
const password = process.env.DSQL_ENCRYPTION_PASSWORD || "";
|
||||
const salt = process.env.DSQL_ENCRYPTION_SALT || "";
|
||||
|
||||
// /** @type {import("crypto").CipherKey} */
|
||||
let key = scryptSync(password, salt, 24);
|
||||
let iv = Buffer.alloc(16, 0);
|
||||
// @ts-ignore
|
||||
const decipher = createDecipheriv(algorithm, key, iv);
|
||||
|
||||
/** ********************* Decrypt String */
|
||||
try {
|
||||
let decrypted = decipher.update(encryptedString, "hex", "utf8");
|
||||
decrypted += decipher.final("utf8");
|
||||
return decrypted;
|
||||
} catch (error) {
|
||||
// serverError({
|
||||
// component: "decrypt",
|
||||
// message: error.message,
|
||||
// user: {},
|
||||
// });
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
*
|
||||
* @param {string | null | number} string
|
||||
* @param {(this: any, key: string, value: any) => any} [reviver]
|
||||
* @returns {{ [key: string]: any } | { [key: string]: any }[] | undefined}
|
||||
*/
|
||||
function parse(string, reviver) {
|
||||
if (!string) return undefined;
|
||||
if (typeof string == "object") return string;
|
||||
if (typeof string !== "string") return undefined;
|
||||
try {
|
||||
return JSON.parse(string, reviver);
|
||||
} catch (error) {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {any} value
|
||||
* @param {(this: any, key: string, value: any) => any} [replacer]
|
||||
* @param { string | number } [space]
|
||||
* @returns {string | undefined}
|
||||
*/
|
||||
function stringify(value, replacer, space) {
|
||||
try {
|
||||
return JSON.stringify(value, replacer, space);
|
||||
} catch (error) {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
const EJSON = {
|
||||
parse,
|
||||
stringify,
|
||||
};
|
||||
|
||||
module.exports = EJSON;
|
||||
Reference in New Issue
Block a user