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

66 lines
3.6 KiB
JavaScript
Raw Normal View History

2024-11-05 11:12:42 +00:00
"use strict";
exports.id = 4194;
exports.ids = [4194];
exports.modules = {
/***/ 4194:
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
// @ts-check
const fs = __webpack_require__(7147);
const os = __webpack_require__(2037);
const { execSync } = __webpack_require__(2081);
const serverError = __webpack_require__(2163);
const { ServerResponse } = __webpack_require__(3685);
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
* ==============================================================================
* Main Function
* ==============================================================================
* @param {Object} params - Single object parameter
* @param {string} params.dbName - Database Full Name
* @param {import("@/package-shared/types").UserType} params.user - Database Full Name
* @param {ServerResponse} params.res - Http response object
*/ module.exports = async function exportDb({ dbName , user , res }) {
const mysqlDumpPath = os.platform().match(/win/i) ? "'" + "C:\\Program Files\\MySQL\\MySQL Server 8.0\\bin\\mysqldump.exe" + "'" : "mysqldump";
try {
/** @type {import("child_process").ExecSyncOptions} */ let execSyncOptions = {
cwd: process.cwd()
};
2024-11-05 14:18:40 +00:00
const filePath = `${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${user.id}/export.sql`;
2024-11-05 11:12:42 +00:00
if (os.platform().match(/win/i)) execSyncOptions.shell = "bash.exe";
const exe = `${mysqlDumpPath} -u ${process.env.DSQL_DB_USERNAME} -h ${process.env.DSQL_DB_HOST} -p${process.env.DSQL_DB_PASSWORD} ${dbName} > ${filePath}`;
console.log(`exportDb.js exe => ${exe}`);
const dumpDb = execSync(exe, execSyncOptions);
// const file = fs.createWriteStream(filePath);
res.setHeader("Content-Type", "application/zip");
res.setHeader("Content-Disposition", `attachment; filename=export.sql`);
const fileStream = fs.createReadStream(filePath);
/** ********************* Write response header */ fileStream.pipe(res);
// res.pipe(file);
// res.writeHead(200);
// await new Promise((resolve, reject) => {
// file.on("finish", () => {
// // res.pipe(file);
// resolve(true);
// });
// });
// return fs.readFileSync(filePath, "utf-8");
// return file;
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
} catch (/** @type {any} */ error) {
serverError({
component: "/functions/backend/exportDb/lines-30-46",
message: error.message,
user: user
});
}
}; /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */
/***/ })
};
;