"use strict"; (() => { var exports = {}; exports.id = 5911; exports.ids = [5911]; exports.modules = { /***/ 6517: /***/ ((module) => { module.exports = require("lodash"); /***/ }), /***/ 6109: /***/ ((module) => { module.exports = require("sanitize-html"); /***/ }), /***/ 2261: /***/ ((module) => { module.exports = require("serverless-mysql"); /***/ }), /***/ 4300: /***/ ((module) => { module.exports = require("buffer"); /***/ }), /***/ 6113: /***/ ((module) => { module.exports = require("crypto"); /***/ }), /***/ 7147: /***/ ((module) => { module.exports = require("fs"); /***/ }), /***/ 1017: /***/ ((module) => { module.exports = require("path"); /***/ }), /***/ 7082: /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "default": () => (/* binding */ handler) /* harmony export */ }); /* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(6517); /* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(lodash__WEBPACK_IMPORTED_MODULE_0__); /* harmony import */ var _package_shared_functions_backend_db_runQuery__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(8499); /* harmony import */ var _package_shared_functions_backend_db_runQuery__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_db_runQuery__WEBPACK_IMPORTED_MODULE_1__); /* harmony import */ var _package_shared_functions_backend_decrypt__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(5425); /* harmony import */ var _package_shared_functions_backend_decrypt__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_decrypt__WEBPACK_IMPORTED_MODULE_2__); /* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(2163); /* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_3__); /* harmony import */ var _package_shared_functions_backend_api_cred__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(1007); /* harmony import */ var _package_shared_functions_backend_api_cred__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_api_cred__WEBPACK_IMPORTED_MODULE_4__); // @ts-check /** * ============================================================================== * Imports * ============================================================================== */ const fs = __webpack_require__(7147); /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** @type {import("next").NextApiHandler} */ async function handler(req, res) { /** * Check method * * @description Check request method and return if invalid */ if (req.method !== "GET") return res.json({ msg: "Failed!" }); /** * Send Response * * @description Send a boolean response */ try { /** * User auth * * @description Authenticate user */ /** @type {import("@/package-shared/types").GetReqQueryObject} */ // @ts-ignore const reqQueryObject = req.query; const { query , db } = reqQueryObject; /** @type {string | undefined } */ const tableName = reqQueryObject?.tableName ? String(reqQueryObject.tableName) : undefined; const authorization = req.headers.authorization; if (!authorization) return res.json({ success: false, msg: "Unauthorized" }); const apiCred = _package_shared_functions_backend_api_cred__WEBPACK_IMPORTED_MODULE_4___default()({ key: authorization, database: db, table: tableName }); if (!apiCred?.user_id) { throw new Error("Api Credentials invalid!"); } const { user_id } = apiCred; /** @type {string[] | undefined } */ let queryValues; if (reqQueryObject?.queryValues && typeof reqQueryObject?.queryValues === "string") { try { queryValues = JSON.parse(reqQueryObject.queryValues); } catch (error) {} } const dbFullName = `datasquirel_user_${user_id}_${db}`; /** * Input Validation * * @description Input Validation */ if (typeof query == "string" && (query.match(/^alter|^delete|information_schema|databases|^create/i) || !query.match(/^select/i))) { return res.json({ success: false, msg: "Wrong Input" }); } /** * Create new user folder and file * * @description Create new user folder and file */ let results; /** @type {import("@/package-shared/types").DSQL_DatabaseSchemaType | undefined} */ let dbSchema; const targetDbSchemaPath = `${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${user_id.toString().replace(/\//g, "")}/main.json`; if (fs.existsSync(targetDbSchemaPath)) { try { dbSchema = JSON.parse(fs.readFileSync(targetDbSchemaPath, "utf8")).filter((/** @type {any} */ db)=>db.dbFullName === dbFullName)[0]; } catch (_err) {} } try { let { result , error: error1 } = await _package_shared_functions_backend_db_runQuery__WEBPACK_IMPORTED_MODULE_1___default()({ dbFullName: dbFullName, query: query, queryValuesArray: queryValues, readOnly: true, dbSchema, tableName }); /** @type {import("@/package-shared/types").DSQL_TableSchemaType | undefined} */ let tableSchema; if (dbSchema) { const targetTable = dbSchema.tables.find((table)=>table.tableName === tableName); if (targetTable) { const clonedTargetTable = lodash__WEBPACK_IMPORTED_MODULE_0___default().cloneDeep(targetTable); delete clonedTargetTable.childTable; delete clonedTargetTable.childTableDbFullName; delete clonedTargetTable.childTableName; delete clonedTargetTable.childrenTables; delete clonedTargetTable.updateData; delete clonedTargetTable.tableNameOld; delete clonedTargetTable.indexes; tableSchema = clonedTargetTable; } } if (error1) throw error1; if (result.error) throw new Error(result.error); results = result; /** @type {import("@/package-shared/types").GetReturn} */ const resObject = { success: true, payload: results, schema: tableName && tableSchema ? tableSchema : undefined }; res.json(resObject); //////////////////////////////////////// } catch (/** @type {any} */ error2) { //////////////////////////////////////// _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_3___default()({ component: "/api/query/get/lines-85-94", message: error2.message }); res.json({ success: false, payload: null, error: error2.message }); } //////////////////////////////////////// } catch (/** @type {any} */ error3) { //////////////////////////////////////// _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_3___default()({ component: "/api/query/get/main-catch-error", message: error3.message }); res.json({ success: false, msg: "Wrong Credentials" }); //////////////////////////////////////// } } /***/ }) }; ; // load runtime var __webpack_require__ = require("../../../webpack-api-runtime.js"); __webpack_require__.C(exports); var __webpack_exec__ = (moduleId) => (__webpack_require__(__webpack_require__.s = moduleId)) var __webpack_exports__ = __webpack_require__.X(0, [2224,2163,3017,3403,7547,5886,5338,8326,1007,6147,4733], () => (__webpack_exec__(7082))); module.exports = __webpack_exports__; })();