dsql-admin/dsql-app/.local_dist/server/chunks/2224.js
Benjamin Toby d13ba5057b Updates
2024-11-26 10:31:39 +01:00

77 lines
1.9 KiB
JavaScript

"use strict";
exports.id = 2224;
exports.ids = [2224];
exports.modules = {
/***/ 2224:
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
// @ts-check
const mysql = __webpack_require__(2261);
const grabDbSSL = __webpack_require__(4824);
const MASTER = mysql({
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) : undefined,
charset: "utf8mb4",
ssl: grabDbSSL()
}
});
/**
* DSQL user read-only DB handler
* @param {object} params
* @param {string} params.paradigm
* @param {string} params.database
* @param {string} params.queryString
* @param {string[]} [params.queryValues]
*/ // @ts-ignore
async function DB_HANDLER(...args) {
try {
const results = await MASTER.query(...args);
/** ********************* Clean up */ await MASTER.end();
return JSON.parse(JSON.stringify(results));
} catch (/** @type {any} */ error) {
console.log("DB Error =>", error);
return {
success: false,
error: error.message
};
}
}
module.exports = DB_HANDLER;
/***/ }),
/***/ 4824:
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
// @ts-check
const fs = __webpack_require__(7147);
/**
* @returns {string | (import("tls").SecureContextOptions & { rejectUnauthorized?: boolean | undefined;}) | undefined}
*/ module.exports = function grabDbSSL() {
const SSL_DIR = process.env.DSQL_SSL_DIR;
if (!SSL_DIR?.match(/./)) {
return undefined;
}
const caFilePath = `${SSL_DIR}/ca-cert.pem`;
if (!fs.existsSync(caFilePath)) {
console.log(`${caFilePath} does not exist`);
return undefined;
}
return {
ca: fs.readFileSync(`${SSL_DIR}/ca-cert.pem`)
};
};
/***/ })
};
;