First Commit
This commit is contained in:
@@ -0,0 +1,222 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 9361;
|
||||
exports.ids = [9361];
|
||||
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");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3685:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("http");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 1017:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("path");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 6765:
|
||||
/***/ ((__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 _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(6825);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_0__);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2163);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1__);
|
||||
/* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(6517);
|
||||
/* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(lodash__WEBPACK_IMPORTED_MODULE_2__);
|
||||
/* harmony import */ var _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(2224);
|
||||
/* harmony import */ var _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_3__);
|
||||
/* harmony import */ var _package_shared_functions_backend_db_addDbEntry__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(5338);
|
||||
/* harmony import */ var _package_shared_functions_backend_db_addDbEntry__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_db_addDbEntry__WEBPACK_IMPORTED_MODULE_4__);
|
||||
// @ts-check
|
||||
const fs = __webpack_require__(7147);
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* API handler
|
||||
* ==============================================================================
|
||||
* @type {import("next").NextApiHandler}
|
||||
*/ async function handler(req, res) {
|
||||
/**
|
||||
* Check method
|
||||
*
|
||||
* @description Check request method and return if invalid
|
||||
*/ if (req.method !== "POST") return res.json({
|
||||
user: null,
|
||||
msg: "Registration Failed!"
|
||||
});
|
||||
/**
|
||||
* User Auth
|
||||
*
|
||||
* @description User Auth
|
||||
*/ const user = await _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_0___default()(req, res, true);
|
||||
if (!user) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Unauthorized"
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Validate Form
|
||||
*
|
||||
* @description Check if request body is valid
|
||||
*/ // const { id, inviting_user_id, invited_user_email, invitation_status, database_access, priviledge } = req.body;
|
||||
const sanitizedReqBody = lodash__WEBPACK_IMPORTED_MODULE_2___default().cloneDeep(req.body);
|
||||
const inviting_user_id = sanitizedReqBody.inviting_user_id;
|
||||
const invited_user_email = sanitizedReqBody.invited_user_email;
|
||||
const database_access = sanitizedReqBody.database_access;
|
||||
const priviledge = sanitizedReqBody.priviledge;
|
||||
/**
|
||||
* Validate Form
|
||||
*
|
||||
* @description Check if request body is valid
|
||||
*/ try {
|
||||
const existingUserUser = await _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_3___default()(`SELECT email FROM user_users WHERE user_id=? AND invited_user_id=? AND user_type='admin' AND email=?`, [
|
||||
inviting_user_id,
|
||||
user.id,
|
||||
user.email
|
||||
]);
|
||||
if (existingUserUser && existingUserUser[0]) {
|
||||
return res.json({
|
||||
success: false
|
||||
});
|
||||
}
|
||||
/** @type {any} */ const newUserUser = await _package_shared_functions_backend_db_addDbEntry__WEBPACK_IMPORTED_MODULE_4___default()({
|
||||
dbFullName: "datasquirel",
|
||||
tableName: "user_users",
|
||||
data: {
|
||||
user_id: inviting_user_id,
|
||||
invited_user_id: user.id,
|
||||
database_access: database_access,
|
||||
user_priviledge: priviledge,
|
||||
user_type: "admin",
|
||||
first_name: user.first_name,
|
||||
last_name: user.last_name,
|
||||
email: user.email,
|
||||
username: user.first_name,
|
||||
image: user.image,
|
||||
image_thumbnail: user.image_thumbnail
|
||||
}
|
||||
});
|
||||
const inviteAccepted = await _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_3___default()(`UPDATE invitations SET invitation_status='Accepted' WHERE inviting_user_id=? AND invited_user_email=?`, [
|
||||
inviting_user_id,
|
||||
invited_user_email
|
||||
]);
|
||||
const dbTableData = await _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_3___default()(`SELECT db_tables_data FROM invitations WHERE inviting_user_id=?`, [
|
||||
inviting_user_id
|
||||
]);
|
||||
// const dbTableData = await DB_HANDLER(`SELECT db_tables_data FROM invitations WHERE inviting_user_id='${inviting_user_id}' AND invited_user_email='${invited_user_email}'`);
|
||||
const clearEntries = await _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_3___default()(`DELETE FROM delegated_user_tables WHERE root_user_id='${inviting_user_id}' AND delegated_user_id='${user.id}'`);
|
||||
if (dbTableData && dbTableData[0]) {
|
||||
const dbTableEntries = dbTableData[0].db_tables_data.split("|");
|
||||
for(let i = 0; i < dbTableEntries.length; i++){
|
||||
const dbTableEntry = dbTableEntries[i];
|
||||
const dbTableEntryArray = dbTableEntry.split("-");
|
||||
const [db_slug, table_slug] = dbTableEntryArray;
|
||||
const newEntry = await _package_shared_functions_backend_db_addDbEntry__WEBPACK_IMPORTED_MODULE_4___default()({
|
||||
dbFullName: "datasquirel",
|
||||
tableName: "delegated_user_tables",
|
||||
data: {
|
||||
delegated_user_id: user.id,
|
||||
root_user_id: inviting_user_id,
|
||||
database: db_slug,
|
||||
table: table_slug,
|
||||
priviledge: priviledge
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
res.json({
|
||||
success: newUserUser?.insertId ? true : false
|
||||
});
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
} catch (/** @type {any} */ error) {
|
||||
_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1___default()({
|
||||
component: "/api/acceptUserInvitation/catch-error",
|
||||
message: error.message,
|
||||
user: user
|
||||
});
|
||||
res.json({
|
||||
success: false
|
||||
});
|
||||
}
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// 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, [5425,2224,2163,6825,3017,3403,7547,5886,5338], () => (__webpack_exec__(6765)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,144 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 3488;
|
||||
exports.ids = [3488];
|
||||
exports.modules = {
|
||||
|
||||
/***/ 9538:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("datasquirel");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 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");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3685:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("http");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 1017:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("path");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3278:
|
||||
/***/ ((__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 _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(6825);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_0__);
|
||||
/* harmony import */ var _functions_backend_addAdminUserOnLogin__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(613);
|
||||
/* harmony import */ var _functions_backend_addAdminUserOnLogin__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_addAdminUserOnLogin__WEBPACK_IMPORTED_MODULE_1__);
|
||||
// @ts-check
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/
|
||||
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* API handler
|
||||
* ==============================================================================
|
||||
* @type {import("next").NextApiHandler}
|
||||
*/ async function handler(req, res) {
|
||||
/**
|
||||
* Check method
|
||||
*
|
||||
* @description Check request method and return if invalid
|
||||
*/ if (req.method !== "POST") return res.json({
|
||||
msg: "Failed!"
|
||||
});
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const user = await _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_0___default()(req, res, true);
|
||||
if (!user) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Unauthorized"
|
||||
});
|
||||
}
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ console.log("Invitation Received by current logged in user, Loggin in VIA API ...");
|
||||
const acceptInvitation = await _functions_backend_addAdminUserOnLogin__WEBPACK_IMPORTED_MODULE_1___default()({
|
||||
// @ts-ignore
|
||||
query: req.body.query,
|
||||
user
|
||||
});
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
res.json({
|
||||
success: true,
|
||||
result: acceptInvitation
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// 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, [5425,2224,2163,6825,3017,3403,7547,5886,5338,613], () => (__webpack_exec__(3278)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,239 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 1600;
|
||||
exports.ids = [1600];
|
||||
exports.modules = {
|
||||
|
||||
/***/ 3785:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("generate-password");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 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");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 2081:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("child_process");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 6113:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("crypto");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 7147:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("fs");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3685:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("http");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 1017:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("path");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 5241:
|
||||
/***/ ((__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 _package_shared_functions_backend_encrypt__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(7547);
|
||||
/* harmony import */ var _package_shared_functions_backend_encrypt__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_encrypt__WEBPACK_IMPORTED_MODULE_0__);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2163);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1__);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(6825);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2__);
|
||||
/* harmony import */ var _package_shared_functions_backend_db_addDbEntry__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(5338);
|
||||
/* harmony import */ var _package_shared_functions_backend_db_addDbEntry__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_db_addDbEntry__WEBPACK_IMPORTED_MODULE_3__);
|
||||
// @ts-check
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/ const fs = __webpack_require__(7147);
|
||||
const path = __webpack_require__(1017);
|
||||
const { execSync } = __webpack_require__(2081);
|
||||
const generator = __webpack_require__(3785);
|
||||
|
||||
|
||||
|
||||
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* API handler
|
||||
* ==============================================================================
|
||||
* @type {import("next").NextApiHandler}
|
||||
*/ async function handler(req, res) {
|
||||
/**
|
||||
* Check method
|
||||
*
|
||||
* @description Check request method and return if invalid
|
||||
*/ if (req.method !== "POST") return res.json({
|
||||
msg: "Failed!"
|
||||
});
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const user = await _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2___default()(req, res, true);
|
||||
if (!user) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Unauthorized"
|
||||
});
|
||||
}
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ /** @type {import("@/package-shared/types").AddApiKeyRequestBody} */ const reqBody = req.body;
|
||||
const { api_key_name , api_key_slug , api_key_scope , target_database , target_table , } = reqBody;
|
||||
/**
|
||||
* Input Validation
|
||||
*
|
||||
* @description Input Validation
|
||||
*/ if (!api_key_name?.match(/./) || !api_key_slug?.match(/./) || !api_key_scope?.match(/./)) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Wrong Input"
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Send Response
|
||||
*
|
||||
* @description Send a boolean response
|
||||
*/ try {
|
||||
const allowedKeysPath = process.env.DSQL_API_KEYS_PATH;
|
||||
if (!allowedKeysPath) throw new Error("process.env.DSQL_API_KEYS_PATH variable not found");
|
||||
if (!fs.existsSync(allowedKeysPath)) {
|
||||
fs.mkdirSync(allowedKeysPath, {
|
||||
recursive: true
|
||||
});
|
||||
}
|
||||
let sign = generator.generate({
|
||||
length: 24,
|
||||
numbers: true,
|
||||
uppercase: true,
|
||||
lowercase: true,
|
||||
symbols: "-"
|
||||
}) + "-" + Date.now();
|
||||
/** @type {import("@/package-shared/types").ApiKeyObject} */ let payload = {
|
||||
user_id: user.id,
|
||||
date_code: Date.now(),
|
||||
sign,
|
||||
target_database,
|
||||
target_table
|
||||
};
|
||||
if (api_key_scope == "fullAccess") {
|
||||
const extraPayload = {
|
||||
full_access: true
|
||||
};
|
||||
payload = {
|
||||
...payload,
|
||||
...extraPayload
|
||||
};
|
||||
}
|
||||
const apiKey = _package_shared_functions_backend_encrypt__WEBPACK_IMPORTED_MODULE_0___default()(JSON.stringify(payload));
|
||||
if (!apiKey) return res.json({
|
||||
success: false,
|
||||
msg: "Couldn't encrypt API key"
|
||||
});
|
||||
const encryptedApiKey = _package_shared_functions_backend_encrypt__WEBPACK_IMPORTED_MODULE_0___default()(apiKey);
|
||||
/**
|
||||
* Create new user folder and file
|
||||
*
|
||||
* @description Create new user folder and file
|
||||
*/ /** @type {any} */ let dbEntryObject = {
|
||||
dbFullName: "datasquirel",
|
||||
tableName: "api_keys",
|
||||
data: {
|
||||
user_id: user.id,
|
||||
name: api_key_name,
|
||||
slug: api_key_slug,
|
||||
key: encryptedApiKey,
|
||||
scope: api_key_scope
|
||||
}
|
||||
};
|
||||
if (sign) dbEntryObject.data.csrf = sign;
|
||||
let newApiKey = await _package_shared_functions_backend_db_addDbEntry__WEBPACK_IMPORTED_MODULE_3___default()(dbEntryObject);
|
||||
if (!newApiKey.insertId) {
|
||||
throw new Error("Api Key Couldn't be added");
|
||||
}
|
||||
fs.writeFileSync(`${allowedKeysPath}/${sign}`, JSON.stringify(payload), "utf-8");
|
||||
res.json({
|
||||
success: true
|
||||
});
|
||||
////////////////////////////////////////
|
||||
} catch (/** @type {any} */ error) {
|
||||
////////////////////////////////////////
|
||||
_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1___default()({
|
||||
component: "/api/addApiKey/catch-error",
|
||||
message: error.message,
|
||||
user: user
|
||||
});
|
||||
res.json({
|
||||
success: false,
|
||||
msg: "Database Files could not be written!"
|
||||
});
|
||||
////////////////////////////////////////
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// 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, [5425,2224,2163,6825,3017,3403,7547,5886,5338], () => (__webpack_exec__(5241)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,171 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 8066;
|
||||
exports.ids = [8066];
|
||||
exports.modules = {
|
||||
|
||||
/***/ 2029:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("datasquirel/functions/hashPassword");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 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");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3685:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("http");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 1017:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("path");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 5078:
|
||||
/***/ ((__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 datasquirel_functions_hashPassword__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2029);
|
||||
/* harmony import */ var datasquirel_functions_hashPassword__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(datasquirel_functions_hashPassword__WEBPACK_IMPORTED_MODULE_0__);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(6825);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_1__);
|
||||
/* harmony import */ var _package_shared_functions_backend_db_addDbEntry__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(5338);
|
||||
/* harmony import */ var _package_shared_functions_backend_db_addDbEntry__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_db_addDbEntry__WEBPACK_IMPORTED_MODULE_2__);
|
||||
// @ts-check
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/
|
||||
|
||||
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* API handler
|
||||
* ==============================================================================
|
||||
* @type {import("next").NextApiHandler}
|
||||
*/ async function handler(req, res) {
|
||||
/**
|
||||
* Check method
|
||||
*
|
||||
* @description Check request method and return if invalid
|
||||
*/ if (req.method !== "POST") return res.json({
|
||||
msg: "Failed!"
|
||||
});
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const user = await _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_1___default()(req, res, true);
|
||||
if (!user) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Unauthorized"
|
||||
});
|
||||
}
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const sanitizedReqBody = req.body;
|
||||
const { payload , dbFullName , dbId } = sanitizedReqBody;
|
||||
/**
|
||||
* Input Validation
|
||||
*
|
||||
* @description Input Validation
|
||||
*/ const newUser = await _package_shared_functions_backend_db_addDbEntry__WEBPACK_IMPORTED_MODULE_2___default()({
|
||||
dbContext: "Dsql User",
|
||||
paradigm: "Full Access",
|
||||
dbFullName: dbFullName,
|
||||
tableName: "users",
|
||||
data: (()=>{
|
||||
const reqBodyKeys = Object.keys(payload);
|
||||
/** @type {any} */ let finalData = {};
|
||||
reqBodyKeys.forEach((key)=>{
|
||||
if (key?.match(/paradigm|priviledge|database_access|databases|confirm/)) return;
|
||||
finalData[key] = payload[key];
|
||||
});
|
||||
finalData["password"] = datasquirel_functions_hashPassword__WEBPACK_IMPORTED_MODULE_0___default()({
|
||||
encryptionKey: process.env.DSQL_ENCRYPTION_PASSWORD || "",
|
||||
password: payload.password
|
||||
});
|
||||
finalData["email"] = payload.email_address;
|
||||
finalData["image"] = "/images/user_images/user-preset.png";
|
||||
finalData["image_thumbnail"] = "/images/user_images/user-preset-thumbnail.png";
|
||||
delete finalData["email_address"];
|
||||
return finalData;
|
||||
})()
|
||||
});
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
res.json({
|
||||
success: newUser?.insertId ? true : false,
|
||||
msg: "New User User Added",
|
||||
newUserId: newUser.insertId
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// 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, [5425,2224,6825,3017,3403,7547,5886,5338], () => (__webpack_exec__(5078)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,312 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 8336;
|
||||
exports.ids = [8336];
|
||||
exports.modules = {
|
||||
|
||||
/***/ 6517:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("lodash");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 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");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3685:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("http");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 1017:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("path");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 2250:
|
||||
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
||||
|
||||
// @ts-check
|
||||
|
||||
const _ = __webpack_require__(6517);
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Sanitize SQL function
|
||||
* ==============================================================================
|
||||
* @description this function takes in a text(or number) and returns a sanitized
|
||||
* text, usually without spaces
|
||||
*
|
||||
* @param {any} text - Text or number or object
|
||||
* @param {boolean} [spaces] - Allow spaces
|
||||
* @param {RegExp?} [regex] - Regular expression, removes any match
|
||||
*
|
||||
* @returns {any}
|
||||
*/ function sanitizeSql(text, spaces, regex) {
|
||||
/**
|
||||
* Initial Checks
|
||||
*
|
||||
* @description Initial Checks
|
||||
*/ if (!text) return "";
|
||||
if (typeof text == "number" || typeof text == "boolean") return text;
|
||||
if (typeof text == "string" && !text?.toString()?.match(/./)) return "";
|
||||
if (typeof text == "object" && !Array.isArray(text)) {
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
const newObject = sanitizeObjects(text, spaces);
|
||||
return newObject;
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
} else if (typeof text == "object" && Array.isArray(text)) {
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
const newArray = sanitizeArrays(text, spaces);
|
||||
return newArray;
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
}
|
||||
// if (text?.toString()?.match(/\'|\"/)) {
|
||||
// console.log("TEXT containing commas =>", text);
|
||||
// return "";
|
||||
// }
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
/**
|
||||
* Declare variables
|
||||
*
|
||||
* @description Declare "results" variable
|
||||
*/ let finalText = text;
|
||||
if (regex) {
|
||||
finalText = text.toString().replace(regex, "");
|
||||
}
|
||||
if (spaces) {} else {
|
||||
finalText = text.toString().replace(/\n|\r|\n\r|\r\n/g, "").replace(/ /g, "");
|
||||
}
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
const escapeRegex = /select |insert |drop |delete |alter |create |exec | union | or | like | concat|LOAD_FILE|ASCII| COLLATE | HAVING | information_schema|DECLARE |\#|WAITFOR |delay |BENCHMARK |\/\*.*\*\//gi;
|
||||
finalText = finalText.replace(/(?<!\\)\'/g, "\\'").replace(/(?<!\\)\`/g, "\\`")// .replace(/(?<!\\)\"/g, '\\"')
|
||||
.replace(/\/\*\*\//g, "").replace(escapeRegex, "\\$&");
|
||||
// const injectionRegexp = /select .* from|\*|delete from|drop database|drop table|update .* set/i;
|
||||
// if (text?.toString()?.match(injectionRegexp)) {
|
||||
// console.log("ATTEMPTED INJECTION =>", text);
|
||||
// return "";
|
||||
// }
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
return finalText;
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Sanitize Objects Function
|
||||
* ==============================================================================
|
||||
* @description Sanitize objects in the form { key: "value" }
|
||||
*
|
||||
* @param {any} object - Database Full Name
|
||||
* @param {boolean} [spaces] - Allow spaces
|
||||
*
|
||||
* @returns {object}
|
||||
*/ function sanitizeObjects(object, spaces) {
|
||||
/** @type {any} */ let objectUpdated = {
|
||||
...object
|
||||
};
|
||||
const keys = Object.keys(objectUpdated);
|
||||
keys.forEach((key)=>{
|
||||
const value = objectUpdated[key];
|
||||
if (!value) {
|
||||
delete objectUpdated[key];
|
||||
return;
|
||||
}
|
||||
if (typeof value == "string" || typeof value == "number") {
|
||||
objectUpdated[key] = sanitizeSql(value, spaces);
|
||||
} else if (typeof value == "object" && !Array.isArray(value)) {
|
||||
objectUpdated[key] = sanitizeObjects(value, spaces);
|
||||
} else if (typeof value == "object" && Array.isArray(value)) {
|
||||
objectUpdated[key] = sanitizeArrays(value, spaces);
|
||||
}
|
||||
});
|
||||
return objectUpdated;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Sanitize Objects Function
|
||||
* ==============================================================================
|
||||
* @description Sanitize objects in the form { key: "value" }
|
||||
*
|
||||
* @param {any[]} array - Database Full Name
|
||||
* @param {boolean} [spaces] - Allow spaces
|
||||
*
|
||||
* @returns {string[]|number[]|object[]}
|
||||
*/ function sanitizeArrays(array, spaces) {
|
||||
let arrayUpdated = _.cloneDeep(array);
|
||||
arrayUpdated.forEach((item, index)=>{
|
||||
const value = item;
|
||||
if (!value) {
|
||||
arrayUpdated.splice(index, 1);
|
||||
return;
|
||||
}
|
||||
if (typeof item == "string" || typeof item == "number") {
|
||||
arrayUpdated[index] = sanitizeSql(value, spaces);
|
||||
} else if (typeof item == "object" && !Array.isArray(value)) {
|
||||
arrayUpdated[index] = sanitizeObjects(value, spaces);
|
||||
} else if (typeof item == "object" && Array.isArray(value)) {
|
||||
arrayUpdated[index] = sanitizeArrays(item, spaces);
|
||||
}
|
||||
});
|
||||
return arrayUpdated;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
module.exports = sanitizeSql;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 4373:
|
||||
/***/ ((__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 path__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1017);
|
||||
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_0__);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(6825);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_1__);
|
||||
/* harmony import */ var _package_shared_functions_backend_db_sanitizeSql__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(2250);
|
||||
/* harmony import */ var _package_shared_functions_backend_db_sanitizeSql__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_db_sanitizeSql__WEBPACK_IMPORTED_MODULE_2__);
|
||||
// @ts-check
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/ const fs = __webpack_require__(7147);
|
||||
|
||||
|
||||
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* API handler
|
||||
* ==============================================================================
|
||||
* @type {import("next").NextApiHandler}
|
||||
*/ async function handler(req, res) {
|
||||
/**
|
||||
* Check method
|
||||
*
|
||||
* @description Check request method and return if invalid
|
||||
*/ if (req.method !== "POST") return res.json({
|
||||
msg: "Failed!"
|
||||
});
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const user = await _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_1___default()(req, res, true);
|
||||
if (!user) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Unauthorized"
|
||||
});
|
||||
}
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const sanitizedReqBody = _package_shared_functions_backend_db_sanitizeSql__WEBPACK_IMPORTED_MODULE_2___default()(req.body);
|
||||
const { name } = sanitizedReqBody;
|
||||
const STATIC_ROOT = process.env.DSQL_STATIC_SERVER_DIR;
|
||||
if (!STATIC_ROOT) {
|
||||
console.log("Static File ENV not Found!");
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "No Static File Path"
|
||||
});
|
||||
}
|
||||
const folderPath = path__WEBPACK_IMPORTED_MODULE_0___default().join(STATIC_ROOT, `images/user-images/user-${user.id}/`);
|
||||
const newFolderPath = folderPath + name;
|
||||
const doesFolderExist = fs.existsSync(newFolderPath);
|
||||
if (doesFolderExist) return res.json({
|
||||
success: false
|
||||
});
|
||||
fs.mkdirSync(newFolderPath);
|
||||
/**
|
||||
* Send Response
|
||||
*
|
||||
* @description Send a boolean response
|
||||
*/ res.json({
|
||||
success: true
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// 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, [5425,2224,6825], () => (__webpack_exec__(4373)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,225 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 5012;
|
||||
exports.ids = [5012];
|
||||
exports.modules = {
|
||||
|
||||
/***/ 2261:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("serverless-mysql");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 4300:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("buffer");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 2081:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("child_process");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 6113:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("crypto");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 7147:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("fs");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3685:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("http");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 1017:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("path");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 1541:
|
||||
/***/ ((__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 _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2163);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_0__);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(6825);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_1__);
|
||||
// @ts-check
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/ const fs = __webpack_require__(7147);
|
||||
const path = __webpack_require__(1017);
|
||||
const { execSync } = __webpack_require__(2081);
|
||||
|
||||
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ // import { get, set } from "lodash";
|
||||
// const rateLimit = 10; // Number of allowed requests per minute
|
||||
// const rateLimiter = {};
|
||||
// const rateLimiterMiddleware = (ip) => {
|
||||
// const now = Date.now();
|
||||
// const windowStart = now - 60 * 1000; // 1 minute ago
|
||||
// const requestTimestamps = get(rateLimiter, ip, []).filter((timestamp) => timestamp > windowStart);
|
||||
// requestTimestamps.push(now);
|
||||
// set(rateLimiter, ip, requestTimestamps);
|
||||
// return requestTimestamps.length <= rateLimit;
|
||||
// };
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* API handler
|
||||
* ==============================================================================
|
||||
* @type {import("next").NextApiHandler}
|
||||
*/ async function handler(req, res) {
|
||||
/**
|
||||
* Check method
|
||||
*
|
||||
* @description Check request method and return if invalid
|
||||
*/ if (req.method !== "POST") return res.json({
|
||||
msg: "Failed!"
|
||||
});
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ // const ip = req.headers["x-real-ip"] || req.connection.remoteAddress;
|
||||
// if (!rateLimiterMiddleware(ip)) {
|
||||
// // res.status(429).json({ message: "Too Many Requests" });
|
||||
// return res.status(429).json({ msg: "Too Many Requests" });
|
||||
// }
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const user = await _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_1___default()(req, res, true);
|
||||
if (!user) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Unauthorized"
|
||||
});
|
||||
}
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const sanitizedReqBody = req.body;
|
||||
const { dbFullName , dbSlug , paradigm , platforms } = sanitizedReqBody;
|
||||
/**
|
||||
* Send Response
|
||||
*
|
||||
* @description Send a boolean response
|
||||
*/ try {
|
||||
/**
|
||||
* Create new user folder and file
|
||||
*
|
||||
* @description Create new user folder and file
|
||||
*/ const userEnvFilePath = `./jsonData/dbSchemas/users/user-${user.id}/env.json`;
|
||||
if (!fs.existsSync(userEnvFilePath)) {
|
||||
fs.writeFileSync(userEnvFilePath, "{}", "utf8");
|
||||
}
|
||||
const envObject = JSON.parse(fs.readFileSync(userEnvFilePath, "utf8"));
|
||||
let databseObject = envObject[dbFullName];
|
||||
if (!databseObject) {
|
||||
databseObject = {
|
||||
social: []
|
||||
};
|
||||
envObject[dbFullName] = databseObject;
|
||||
}
|
||||
/** @type {object[]} */ let socialLogins = databseObject.social;
|
||||
socialLogins = [];
|
||||
for(let i = 0; i < platforms.length; i++){
|
||||
const platform = platforms[i];
|
||||
const { clientId , clientSecret , domain1 , domain2 , callbackUrl } = platform;
|
||||
if (paradigm?.match(/personal/) && !clientId?.match(/./)) {
|
||||
throw new Error("Client Id Must be present");
|
||||
}
|
||||
if (paradigm?.match(/personal/) && !clientSecret?.match(/./)) {
|
||||
throw new Error("Client Secret Must be present");
|
||||
}
|
||||
if (paradigm?.match(/datasquirel/) && !domain1?.match(/./)) {
|
||||
throw new Error("Atleast one Domain Must be present");
|
||||
}
|
||||
// const existingPlatformIndex = socialLogins.findIndex((scObj) => scObj.platform === platform.platform);
|
||||
// console.log(existingPlatformIndex);
|
||||
// if (existingPlatformIndex >= 0) {
|
||||
// if (paradigm?.match(/personal/)) {
|
||||
// socialLogins[existingPlatformIndex] = { ...platform, paradigm };
|
||||
// } else {
|
||||
// socialLogins[existingPlatformIndex] = { paradigm, platform: platform.platform };
|
||||
// }
|
||||
// } else {
|
||||
// socialLogins.push({ paradigm, ...platform });
|
||||
// }
|
||||
if (paradigm?.match(/personal/)) {
|
||||
socialLogins.push({
|
||||
platform: platform.platform,
|
||||
paradigm,
|
||||
clientId,
|
||||
clientSecret,
|
||||
callbackUrl
|
||||
});
|
||||
} else {
|
||||
socialLogins.push({
|
||||
platform: platform.platform,
|
||||
paradigm,
|
||||
domain1,
|
||||
domain2
|
||||
});
|
||||
}
|
||||
}
|
||||
databseObject.social = socialLogins;
|
||||
fs.writeFileSync(userEnvFilePath, JSON.stringify(envObject, null, 4), "utf-8");
|
||||
res.json({
|
||||
success: true
|
||||
});
|
||||
////////////////////////////////////////
|
||||
} catch (/** @type {any} */ error) {
|
||||
console.log(error.message);
|
||||
////////////////////////////////////////
|
||||
_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_0___default()({
|
||||
component: "/api/addSocialLogin/catch-error",
|
||||
message: error.message,
|
||||
user: user
|
||||
});
|
||||
res.json({
|
||||
success: false,
|
||||
msg: error.message
|
||||
});
|
||||
////////////////////////////////////////
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// 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, [5425,2224,2163,6825], () => (__webpack_exec__(1541)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,216 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 8325;
|
||||
exports.ids = [8325];
|
||||
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");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3685:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("http");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 1017:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("path");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 2771:
|
||||
/***/ ((__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 _functions_backend_handleTableEntryOrder__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(766);
|
||||
/* harmony import */ var _functions_backend_handleTableEntryOrder__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_handleTableEntryOrder__WEBPACK_IMPORTED_MODULE_0__);
|
||||
/* harmony import */ var _package_shared_functions_backend_db_addDbEntry__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(5338);
|
||||
/* harmony import */ var _package_shared_functions_backend_db_addDbEntry__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_db_addDbEntry__WEBPACK_IMPORTED_MODULE_1__);
|
||||
/* harmony import */ var _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(2224);
|
||||
/* harmony import */ var _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_2__);
|
||||
/* harmony import */ var _package_shared_utils_backend_global_db_DSQL_USER_DB_HANDLER__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(3403);
|
||||
/* harmony import */ var _package_shared_utils_backend_global_db_DSQL_USER_DB_HANDLER__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_package_shared_utils_backend_global_db_DSQL_USER_DB_HANDLER__WEBPACK_IMPORTED_MODULE_3__);
|
||||
// @ts-check
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/ const checkUserRights = __webpack_require__(8999);
|
||||
const grabDelegatedUserFromCookie = __webpack_require__(1352);
|
||||
const serverError = __webpack_require__(2163);
|
||||
const userAuth = __webpack_require__(6825);
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* @typedef {object} AddTableEntryRequestBody
|
||||
* @property {string} tableName
|
||||
* @property {any} payload
|
||||
* @property {import("@/package-shared/types").DSQL_TableSchemaType} tableSchema
|
||||
* @property {string} dbSlug
|
||||
* @property {number} dbId
|
||||
* @property {boolean} delegated
|
||||
*/ /**
|
||||
* API handler
|
||||
* ==============================================================================
|
||||
* @type {import("next").NextApiHandler}
|
||||
*/ async function handler(req, res) {
|
||||
/**
|
||||
* Check method
|
||||
*
|
||||
* @description Check request method and return if invalid
|
||||
*/ if (req.method !== "POST") return res.json({
|
||||
msg: "Failed!"
|
||||
});
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const user = await userAuth(req, res, true);
|
||||
if (!user) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "User Auth Failed"
|
||||
});
|
||||
}
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ /** @type {AddTableEntryRequestBody} */ const sanitizedReqBody = req.body;
|
||||
const { tableName , payload , tableSchema , dbSlug , dbId , delegated } = sanitizedReqBody;
|
||||
/**
|
||||
* Send Response
|
||||
*
|
||||
* @description Send a boolean response
|
||||
*/ try {
|
||||
/**
|
||||
* Check if user has rights to this table
|
||||
*
|
||||
* @description Check if user has rights to this table
|
||||
*/ const delegatedUser = await grabDelegatedUserFromCookie({
|
||||
databaseSlug: dbSlug,
|
||||
request: req,
|
||||
user: user,
|
||||
query: req.query
|
||||
});
|
||||
const checkUserRightsBoolean = await checkUserRights({
|
||||
user: user,
|
||||
confirmedDelegetedUser: delegatedUser,
|
||||
database: dbSlug,
|
||||
table: tableName,
|
||||
dbId: dbId,
|
||||
priviledgeRegex: /Update Entries/i
|
||||
});
|
||||
if (!checkUserRightsBoolean) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Unauthorized"
|
||||
});
|
||||
}
|
||||
const dbFullName = delegatedUser?.rootUserId ? `datasquirel_user_${delegatedUser.rootUserId}_${dbSlug}` : `datasquirel_user_${user.id}_${dbSlug}`;
|
||||
/**
|
||||
* Create new user folder and file
|
||||
*
|
||||
* @description Create new user folder and file
|
||||
*/ const newTableEntry = await _package_shared_functions_backend_db_addDbEntry__WEBPACK_IMPORTED_MODULE_1___default()({
|
||||
dbContext: "Dsql User",
|
||||
paradigm: "Full Access",
|
||||
dbFullName: dbFullName,
|
||||
tableName: tableName,
|
||||
data: payload,
|
||||
tableSchema: tableSchema
|
||||
});
|
||||
if (!newTableEntry.insertId) {
|
||||
console.log("Table Insertion Failed =>", newTableEntry);
|
||||
throw new Error("Table Insertion Failed");
|
||||
}
|
||||
const handleOrder = await _functions_backend_handleTableEntryOrder__WEBPACK_IMPORTED_MODULE_0___default()({
|
||||
dbName: dbFullName,
|
||||
entryId: newTableEntry.insertId,
|
||||
entryOrder: payload.order,
|
||||
tableName: tableName,
|
||||
tableSchema: tableSchema
|
||||
});
|
||||
////////////////////////////////////////
|
||||
res.json({
|
||||
success: true
|
||||
});
|
||||
////////////////////////////////////////
|
||||
} catch (/** @type {any} */ error) {
|
||||
////////////////////////////////////////
|
||||
serverError({
|
||||
component: "/api/addTableEntry/catch-error",
|
||||
message: error.message,
|
||||
user: user
|
||||
});
|
||||
res.json({
|
||||
success: false,
|
||||
msg: "Database Files could not be written!",
|
||||
err: error.message
|
||||
});
|
||||
////////////////////////////////////////
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// 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, [5425,2224,2163,6825,3017,3403,7547,5886,5338,1352,8999,766], () => (__webpack_exec__(2771)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,355 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 3909;
|
||||
exports.ids = [3909];
|
||||
exports.modules = {
|
||||
|
||||
/***/ 6517:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("lodash");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 6109:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("sanitize-html");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 2261:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("serverless-mysql");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 7441:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("sharp");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 4300:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("buffer");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 2081:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("child_process");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 6113:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("crypto");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 7147:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("fs");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3685:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("http");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 1017:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("path");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 9146:
|
||||
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
||||
|
||||
__webpack_require__.r(__webpack_exports__);
|
||||
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
||||
/* harmony export */ "config": () => (/* binding */ config),
|
||||
/* harmony export */ "default": () => (/* binding */ handler)
|
||||
/* harmony export */ });
|
||||
/* harmony import */ var _package_shared_functions_backend_db_addDbEntry__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(5338);
|
||||
/* harmony import */ var _package_shared_functions_backend_db_addDbEntry__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_db_addDbEntry__WEBPACK_IMPORTED_MODULE_0__);
|
||||
/* harmony import */ var _functions_backend_fsWriteImageToDiskFromBase64__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(5910);
|
||||
/* harmony import */ var _functions_backend_fsWriteImageToDiskFromBase64__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_fsWriteImageToDiskFromBase64__WEBPACK_IMPORTED_MODULE_1__);
|
||||
/* harmony import */ var _functions_backend_grabPaths__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(6715);
|
||||
/* harmony import */ var _functions_backend_grabPaths__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_grabPaths__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 _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(6825);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_4__);
|
||||
// @ts-check
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/ const fs = __webpack_require__(7147);
|
||||
const path = __webpack_require__(1017);
|
||||
const { execSync } = __webpack_require__(2081);
|
||||
const config = {
|
||||
api: {
|
||||
responseLimit: "1mb",
|
||||
bodyParser: {
|
||||
sizeLimit: "200mb"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* API handler
|
||||
* ==============================================================================
|
||||
* @type {import("next").NextApiHandler}
|
||||
*/ async function handler(req, res) {
|
||||
/**
|
||||
* Check method
|
||||
*
|
||||
* @description Check request method and return if invalid
|
||||
*/ if (req.method !== "POST") return res.json({
|
||||
msg: "Failed!"
|
||||
});
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const user = await _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_4___default()(req, res, true);
|
||||
if (!user) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Unauthorized"
|
||||
});
|
||||
}
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const sanitizedReqBody = req.body;
|
||||
const { media } = sanitizedReqBody;
|
||||
const folder = sanitizedReqBody.folder;
|
||||
const type = sanitizedReqBody.type;
|
||||
const newMediaArray = media;
|
||||
const isProduction = "production".match(/production/);
|
||||
const STATIC_ROOT = process.env.DSQL_STATIC_SERVER_DIR;
|
||||
if (!STATIC_ROOT) {
|
||||
console.log("Static File ENV not Found!");
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "No Static File Path"
|
||||
});
|
||||
}
|
||||
if (folder) {
|
||||
const folderPath = path.join(STATIC_ROOT, `images/user-images/user-${user.id}/${folder}`);
|
||||
const folderExists = fs.existsSync(folderPath);
|
||||
if (!folderExists) {
|
||||
fs.mkdirSync(folderPath, {
|
||||
recursive: true
|
||||
});
|
||||
}
|
||||
const privateFolderPath = `./jsonData/dbSchemas/users/user-${user.id}/media/${folder}`;
|
||||
const privateFolderExists = fs.existsSync(privateFolderPath);
|
||||
if (!privateFolderExists) {
|
||||
fs.mkdirSync(privateFolderPath, {
|
||||
recursive: true
|
||||
});
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Send Response
|
||||
*
|
||||
* @description Send a boolean response
|
||||
*/ try {
|
||||
/**
|
||||
* Create new user folder and file
|
||||
*
|
||||
* @description Create new user folder and file
|
||||
*/ const mediaData = [];
|
||||
for(let i = 0; i < newMediaArray.length; i++){
|
||||
const newMedia = newMediaArray[i];
|
||||
if (type?.match(/image/i)) {
|
||||
const { imageBase64 , imageName , imageSize , mimeType } = newMedia;
|
||||
const imageWrite = await _functions_backend_fsWriteImageToDiskFromBase64__WEBPACK_IMPORTED_MODULE_1___default()({
|
||||
imageName: imageName.replace(/ /g, "-"),
|
||||
imageSourceBase64: imageBase64,
|
||||
user: user,
|
||||
folder,
|
||||
mimeType,
|
||||
isPrivate: newMedia.private
|
||||
});
|
||||
if (!imageWrite) {
|
||||
console.log("Image Write Failed!");
|
||||
continue;
|
||||
}
|
||||
const { urlPath , urlThumbnailPath , urlRelativePath , urlThumbnailRelativePath , } = imageWrite;
|
||||
let newMediaEntry = await _package_shared_functions_backend_db_addDbEntry__WEBPACK_IMPORTED_MODULE_0___default()({
|
||||
dbFullName: "datasquirel",
|
||||
tableName: "user_media",
|
||||
data: {
|
||||
user_id: user.id,
|
||||
media_name: imageName.replace(/ /g, "-"),
|
||||
media_url: urlPath,
|
||||
media_type: "image",
|
||||
media_thumbnail_url: urlThumbnailPath,
|
||||
media_path: urlRelativePath,
|
||||
media_thumbnail_path: urlThumbnailRelativePath,
|
||||
folder: folder,
|
||||
private: newMedia.private ? 1 : 0
|
||||
},
|
||||
duplicateColumnName: "media_url",
|
||||
duplicateColumnValue: urlPath
|
||||
});
|
||||
// if (newMediaEntry?.insertId) {
|
||||
mediaData.push({
|
||||
media_name: imageName.replace(/ /g, "-"),
|
||||
media_url: urlPath,
|
||||
media_thumbnail_url: urlThumbnailPath
|
||||
});
|
||||
// }
|
||||
} else if (type?.match(/file/i)) {
|
||||
const { fileBase64 , fileSize , fileType } = newMedia;
|
||||
const fileName = newMedia.fileName.replace(/ /g, "-").replace(/\./g, "");
|
||||
/**
|
||||
* Grab URL Paths
|
||||
*/ const grabedPaths = _functions_backend_grabPaths__WEBPACK_IMPORTED_MODULE_2___default()({
|
||||
isPrivate: newMedia.private,
|
||||
user: user,
|
||||
folder: folder
|
||||
});
|
||||
if (!grabedPaths) {
|
||||
continue;
|
||||
}
|
||||
const { fileRootPath , urlRootPath , relativePath } = grabedPaths;
|
||||
const fileExt = (()=>{
|
||||
if (fileType?.match(/pdf/)) return ".pdf";
|
||||
if (fileType?.match(/xlsx/)) return ".xlsx";
|
||||
if (fileType?.match(/csv/)) return ".csv";
|
||||
if (fileType?.match(/json/)) return ".json";
|
||||
return null;
|
||||
})();
|
||||
if (!fileExt) continue;
|
||||
const writePath = fileRootPath + fileName + fileExt;
|
||||
const urlPath1 = urlRootPath + fileName + fileExt;
|
||||
const urlRelativePath1 = relativePath + fileName + fileExt;
|
||||
fs.writeFileSync(writePath, fileBase64, "base64");
|
||||
let newMediaEntry1 = await _package_shared_functions_backend_db_addDbEntry__WEBPACK_IMPORTED_MODULE_0___default()({
|
||||
dbFullName: "datasquirel",
|
||||
tableName: "user_media",
|
||||
data: {
|
||||
user_id: user.id,
|
||||
media_name: fileName,
|
||||
media_url: urlPath1,
|
||||
media_thumbnail_url: urlPath1,
|
||||
media_path: urlRelativePath1,
|
||||
media_thumbnail_path: urlRelativePath1,
|
||||
media_type: "file" + "/" + fileExt.replace(/\./, ""),
|
||||
folder: folder,
|
||||
private: newMedia.private ? 1 : 0
|
||||
},
|
||||
duplicateColumnName: "media_url",
|
||||
duplicateColumnValue: urlPath1
|
||||
});
|
||||
mediaData.push({
|
||||
media_name: fileName,
|
||||
media_url: urlPath1,
|
||||
media_thumbnail_url: urlPath1
|
||||
});
|
||||
} else if (type?.match(/video/i)) {
|
||||
const { fileBase64: fileBase641 , fileSize: fileSize1 , fileType: fileType1 } = newMedia;
|
||||
const fileName1 = newMedia.fileName.replace(/ /g, "-").replace(/\./g, "");
|
||||
/**
|
||||
* Grab URL Paths
|
||||
*/ const grabedPaths1 = _functions_backend_grabPaths__WEBPACK_IMPORTED_MODULE_2___default()({
|
||||
isPrivate: newMedia.private,
|
||||
user: user,
|
||||
folder: folder,
|
||||
video: true
|
||||
});
|
||||
if (!grabedPaths1) {
|
||||
continue;
|
||||
}
|
||||
const { fileRootPath: fileRootPath1 , urlRootPath: urlRootPath1 , relativePath: relativePath1 } = grabedPaths1;
|
||||
const fileExt1 = (()=>{
|
||||
if (fileType1?.match(/mp4/)) return ".mp4";
|
||||
return null;
|
||||
})();
|
||||
if (!fileExt1) continue;
|
||||
const writePath1 = fileRootPath1 + fileName1 + fileExt1;
|
||||
const urlPath2 = urlRootPath1 + fileName1 + fileExt1;
|
||||
const urlRelativePath2 = relativePath1 + fileName1 + fileExt1;
|
||||
fs.writeFileSync(writePath1, fileBase641, "base64");
|
||||
let newMediaEntry2 = await _package_shared_functions_backend_db_addDbEntry__WEBPACK_IMPORTED_MODULE_0___default()({
|
||||
dbFullName: "datasquirel",
|
||||
tableName: "user_media",
|
||||
data: {
|
||||
user_id: user.id,
|
||||
media_name: fileName1,
|
||||
media_url: urlPath2,
|
||||
media_thumbnail_url: urlPath2,
|
||||
media_path: urlRelativePath2,
|
||||
media_thumbnail_path: urlRelativePath2,
|
||||
media_type: "video" + "/" + fileExt1.replace(/\./, ""),
|
||||
folder: folder,
|
||||
private: newMedia.private ? 1 : 0
|
||||
},
|
||||
duplicateColumnName: "media_url",
|
||||
duplicateColumnValue: urlPath2
|
||||
});
|
||||
mediaData.push({
|
||||
media_name: fileName1,
|
||||
media_url: urlPath2,
|
||||
media_thumbnail_url: urlPath2
|
||||
});
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////
|
||||
res.json({
|
||||
success: true,
|
||||
mediaData: mediaData
|
||||
});
|
||||
////////////////////////////////////////
|
||||
} catch (/** @type {any} */ error) {
|
||||
console.log(`Add User Media Error: ${error.message}`);
|
||||
_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_3___default()({
|
||||
component: "/api/addUserMedia/catch-error",
|
||||
message: error.message,
|
||||
user: user
|
||||
});
|
||||
res.json({
|
||||
success: false,
|
||||
msg: "Database Files could not be written!"
|
||||
});
|
||||
////////////////////////////////////////
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// 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, [5425,2224,2163,6825,3017,3403,7547,5886,5338,6715,5910], () => (__webpack_exec__(9146)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,304 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 8448;
|
||||
exports.ids = [8448];
|
||||
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");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 2081:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("child_process");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 6113:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("crypto");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 7147:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("fs");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3685:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("http");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 1017:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("path");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 8583:
|
||||
/***/ ((__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 _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2163);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_0__);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(6825);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_1__);
|
||||
/* harmony import */ var _functions_backend_grabUserSchemaData__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(8164);
|
||||
/* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(6517);
|
||||
/* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(lodash__WEBPACK_IMPORTED_MODULE_3__);
|
||||
/* harmony import */ var _functions_backend_setUserSchemaData__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(7638);
|
||||
/* harmony import */ var _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(2224);
|
||||
/* harmony import */ var _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_5__);
|
||||
/* harmony import */ var _package_shared_functions_backend_db_addDbEntry__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(5338);
|
||||
/* harmony import */ var _package_shared_functions_backend_db_addDbEntry__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_db_addDbEntry__WEBPACK_IMPORTED_MODULE_6__);
|
||||
// @ts-check
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/ const fs = __webpack_require__(7147);
|
||||
const path = __webpack_require__(1017);
|
||||
const { execSync } = __webpack_require__(2081);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* API handler
|
||||
* ==============================================================================
|
||||
* @type {import("next").NextApiHandler}
|
||||
*/ async function handler(req, res) {
|
||||
/**
|
||||
* Check method
|
||||
*
|
||||
* @description Check request method and return if invalid
|
||||
*/ if (req.method !== "POST") return res.json({
|
||||
msg: "Failed!"
|
||||
});
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const user = await _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_1___default()(req, res, true);
|
||||
if (!user) {
|
||||
console.log("No User");
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Unauthorized"
|
||||
});
|
||||
}
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const { payload } = req.body;
|
||||
const dbFullName = req.body.dbFullName.replace(/[^a-z\_0-9]/g, "");
|
||||
const dbSlug = req.body.dbSlug;
|
||||
const dbId = req.body.dbId;
|
||||
const parentDatabase = req.body.parentDatabase;
|
||||
const parentTable = req.body.parentTable;
|
||||
/**
|
||||
* Send Response
|
||||
*
|
||||
* @description Send a boolean response
|
||||
*/ try {
|
||||
let userSchemaData = (0,_functions_backend_grabUserSchemaData__WEBPACK_IMPORTED_MODULE_2__["default"])({
|
||||
userId: user.id
|
||||
});
|
||||
if (!userSchemaData) {
|
||||
throw new Error("No User Schema found!");
|
||||
}
|
||||
let targetDatabaseIndex = userSchemaData.findIndex((db)=>db.dbFullName === dbFullName);
|
||||
/** @type {import("@/package-shared/types").DSQL_DatabaseSchemaType | undefined} */ let targetDatabase = userSchemaData[targetDatabaseIndex];
|
||||
if (!targetDatabase) {
|
||||
throw new Error("No Target Database Found!");
|
||||
}
|
||||
let existingTableIndex = targetDatabase.tables.findIndex((table)=>table.tableName === payload.tableName);
|
||||
if (existingTableIndex >= 0) {
|
||||
userSchemaData[targetDatabaseIndex].tables[existingTableIndex] = payload;
|
||||
} else {
|
||||
userSchemaData[targetDatabaseIndex].tables.push(payload);
|
||||
}
|
||||
if (payload?.childTable) {
|
||||
/** @type {import("@/package-shared/types").DSQL_DatabaseSchemaType | undefined} */ const parentDb = userSchemaData.find((db)=>db.dbFullName === parentDatabase);
|
||||
const parentTableObject = parentDb?.tables.find((table)=>{
|
||||
if (table.tableName === parentTable) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
if (!parentTableObject) {
|
||||
throw new Error("Child Table Parent Doesn't Exist!");
|
||||
}
|
||||
if (parentTableObject.childrenTables?.[0]) {
|
||||
parentTableObject.childrenTables.push({
|
||||
dbNameFull: dbFullName,
|
||||
tableName: payload.tableName,
|
||||
tableNameFull: payload.tableNameFull
|
||||
});
|
||||
} else {
|
||||
parentTableObject.childrenTables = [
|
||||
{
|
||||
dbNameFull: dbFullName,
|
||||
tableName: payload.tableName,
|
||||
tableNameFull: payload.tableFullName
|
||||
},
|
||||
];
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
/**
|
||||
* Check Children Databases
|
||||
*
|
||||
* @description Check Children Databases
|
||||
*/ if (targetDatabase.childrenDatabases) {
|
||||
for(let i = 0; i < targetDatabase.childrenDatabases.length; i++){
|
||||
const childDb = targetDatabase.childrenDatabases[i];
|
||||
try {
|
||||
const targetChildIndex = userSchemaData.findIndex((db)=>db.dbFullName === childDb.dbFullName);
|
||||
if (userSchemaData[targetChildIndex]) userSchemaData[targetChildIndex].tables = lodash__WEBPACK_IMPORTED_MODULE_3___default().cloneDeep(targetDatabase.tables);
|
||||
const targetDbRecord = await _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_5___default()(`SELECT * FROM user_databases WHERE user_id = ? AND db_full_name = ?`, [
|
||||
user.id,
|
||||
childDb.dbFullName
|
||||
]);
|
||||
const existingEntry = await _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_5___default()(`SELECT * FROM user_database_tables WHERE db_id=? AND user_id=? AND table_slug=?`, [
|
||||
targetDbRecord[0].id,
|
||||
user.id,
|
||||
payload.tableName
|
||||
]);
|
||||
if (existingEntry?.[0]) continue;
|
||||
const newChildTableEntry = await _package_shared_functions_backend_db_addDbEntry__WEBPACK_IMPORTED_MODULE_6___default()({
|
||||
dbFullName: "datasquirel",
|
||||
tableName: "user_database_tables",
|
||||
data: {
|
||||
user_id: user.id,
|
||||
db_id: targetDbRecord[0].id,
|
||||
db_slug: targetDbRecord[0].db_slug,
|
||||
table_name: payload.tableFullName,
|
||||
table_slug: payload.tableName
|
||||
}
|
||||
});
|
||||
} catch (/** @type {any} */ error) {
|
||||
_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_0___default()({
|
||||
component: "/api/addUserTable/lines-124-140",
|
||||
message: error.message,
|
||||
user: user
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
// console.log("Done ...");
|
||||
// fs.writeFileSync(
|
||||
// "./.tmp/newTableSchema.json",
|
||||
// JSON.stringify(userSchemaData, null, 4),
|
||||
// "utf8"
|
||||
// );
|
||||
// return res.json({
|
||||
// success: false,
|
||||
// msg: "Testing",
|
||||
// });
|
||||
(0,_functions_backend_setUserSchemaData__WEBPACK_IMPORTED_MODULE_4__["default"])({
|
||||
userId: user.id,
|
||||
schemaData: userSchemaData
|
||||
});
|
||||
////////////////////////////////////////
|
||||
/** @type {any} */ const newTableInsertObject = {
|
||||
user_id: user.id,
|
||||
db_id: dbId,
|
||||
db_slug: dbSlug,
|
||||
table_name: payload.tableFullName,
|
||||
table_slug: payload.tableName
|
||||
};
|
||||
if (payload?.childTable) {
|
||||
newTableInsertObject["child_table"] = "1";
|
||||
newTableInsertObject["child_table_parent_database"] = parentDatabase;
|
||||
newTableInsertObject["child_table_parent_table"] = parentTable;
|
||||
}
|
||||
const newTableEntry = await _package_shared_functions_backend_db_addDbEntry__WEBPACK_IMPORTED_MODULE_6___default()({
|
||||
dbFullName: "datasquirel",
|
||||
tableName: "user_database_tables",
|
||||
data: newTableInsertObject
|
||||
});
|
||||
////////////////////////////////////////
|
||||
const targetPath = path.join(process.cwd(), "/shell");
|
||||
const dbShellUpdate = execSync(`node createDbFromSchema.js --user ${user.id} --database ${dbFullName}${payload?.childTable ? " --clone" : ""}`, {
|
||||
cwd: targetPath
|
||||
});
|
||||
////////////////////////////////////////
|
||||
res.json({
|
||||
success: true
|
||||
});
|
||||
////////////////////////////////////////
|
||||
} catch (/** @type {any} */ error1) {
|
||||
////////////////////////////////////////
|
||||
console.log(error1.message);
|
||||
_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_0___default()({
|
||||
component: "/api/addUserTable/main-catch-error",
|
||||
message: error1.message,
|
||||
user: user
|
||||
});
|
||||
res.json({
|
||||
success: false,
|
||||
msg: "Database Files could not be written!"
|
||||
});
|
||||
////////////////////////////////////////
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// 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, [5425,2224,2163,6825,3017,3403,7547,5886,5338,8164,7638], () => (__webpack_exec__(8583)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,231 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 5402;
|
||||
exports.ids = [5402];
|
||||
exports.modules = {
|
||||
|
||||
/***/ 2029:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("datasquirel/functions/hashPassword");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 6517:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("lodash");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 5184:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("nodemailer");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 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");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3685:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("http");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 1017:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("path");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 9210:
|
||||
/***/ ((__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 _functions_backend_handleNodemailer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(6926);
|
||||
/* harmony import */ var _functions_backend_handleNodemailer__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_handleNodemailer__WEBPACK_IMPORTED_MODULE_0__);
|
||||
/* harmony import */ var datasquirel_functions_hashPassword__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2029);
|
||||
/* harmony import */ var datasquirel_functions_hashPassword__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(datasquirel_functions_hashPassword__WEBPACK_IMPORTED_MODULE_1__);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(6825);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2__);
|
||||
/* harmony import */ var _package_shared_functions_backend_db_addDbEntry__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(5338);
|
||||
/* harmony import */ var _package_shared_functions_backend_db_addDbEntry__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_db_addDbEntry__WEBPACK_IMPORTED_MODULE_3__);
|
||||
/* harmony import */ var _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(2224);
|
||||
/* harmony import */ var _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_4__);
|
||||
// @ts-check
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* API handler
|
||||
* ==============================================================================
|
||||
* @type {import("next").NextApiHandler}
|
||||
*/ async function handler(req, res) {
|
||||
/**
|
||||
* Check method
|
||||
*
|
||||
* @description Check request method and return if invalid
|
||||
*/ if (req.method !== "POST") return res.json({
|
||||
msg: "Failed!"
|
||||
});
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const user = await _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2___default()(req, res, true);
|
||||
if (!user) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Unauthorized"
|
||||
});
|
||||
}
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ // const sanitizedReqBody = sanitizeSql(req.body);
|
||||
const sanitizedReqBody = req.body;
|
||||
const paradigm = sanitizedReqBody.paradigm;
|
||||
/**
|
||||
* Input Validation
|
||||
*
|
||||
* @description Input Validation
|
||||
*/ if (paradigm?.match(/database/)) {
|
||||
const newUser = await _package_shared_functions_backend_db_addDbEntry__WEBPACK_IMPORTED_MODULE_3___default()({
|
||||
dbFullName: "datasquirel",
|
||||
tableName: "user_users",
|
||||
data: (()=>{
|
||||
const reqBodyKeys = Object.keys(sanitizedReqBody);
|
||||
/** @type {any} */ const finalData = {};
|
||||
reqBodyKeys.forEach((key)=>{
|
||||
if (key?.match(/paradigm|priviledge|database_access|databases|confirm/)) return;
|
||||
finalData[key] = sanitizedReqBody[key];
|
||||
});
|
||||
finalData["user_id"] = user.id;
|
||||
finalData["password"] = datasquirel_functions_hashPassword__WEBPACK_IMPORTED_MODULE_1___default()({
|
||||
encryptionKey: process.env.DSQL_ENCRYPTION_PASSWORD || "",
|
||||
password: sanitizedReqBody.password
|
||||
});
|
||||
finalData["user_type"] = "database";
|
||||
finalData["email"] = sanitizedReqBody.email_address;
|
||||
finalData["image"] = "/images/user_images/user-preset.png";
|
||||
finalData["image_thumbnail"] = "/images/user_images/user-preset-thumbnail.png";
|
||||
delete finalData["email_address"];
|
||||
return finalData;
|
||||
})()
|
||||
});
|
||||
res.json({
|
||||
success: newUser?.insertId ? true : false,
|
||||
msg: "New User User Added",
|
||||
newUserId: newUser.insertId
|
||||
});
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
} else {
|
||||
if (user?.email === sanitizedReqBody.email_address) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Can't Invite yourself"
|
||||
});
|
||||
}
|
||||
const existingInvitation = await _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_4___default()(`SELECT * FROM invitations WHERE invited_user_email=? AND inviting_user_id=?`, [
|
||||
sanitizedReqBody.email_address,
|
||||
user.id
|
||||
]);
|
||||
if (existingInvitation && existingInvitation[0]) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "User Already Invited"
|
||||
});
|
||||
}
|
||||
const newInvitation = await _package_shared_functions_backend_db_addDbEntry__WEBPACK_IMPORTED_MODULE_3___default()({
|
||||
dbFullName: "datasquirel",
|
||||
tableName: "invitations",
|
||||
data: {
|
||||
inviting_user_id: user.id,
|
||||
invited_user_email: sanitizedReqBody.email_address,
|
||||
database_access: sanitizedReqBody.database_access,
|
||||
priviledge: sanitizedReqBody.priviledge,
|
||||
db_tables_data: sanitizedReqBody.db_tables
|
||||
}
|
||||
});
|
||||
const sendInvitationMail = await _functions_backend_handleNodemailer__WEBPACK_IMPORTED_MODULE_0___default()({
|
||||
to: sanitizedReqBody.email_address,
|
||||
subject: `${user.first_name} ${user.last_name} Invited you`,
|
||||
text: `${user.first_name} ${user.last_name} has invited you to manage a datasquirel account`,
|
||||
html: `
|
||||
<h2>${user.first_name} ${user.last_name} has invited you to manage a datasquirel account.</h2>
|
||||
<a href="${process.env.DSQL_HOST}/create-account?invite=${user.id}&database_access=${sanitizedReqBody.database_access}&priviledge=${sanitizedReqBody.priviledge}&email=${sanitizedReqBody.email_address}">Accept Invitation</a>
|
||||
`
|
||||
});
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
res.json({
|
||||
success: sendInvitationMail?.accepted ? true : false,
|
||||
msg: "This is an invitation request"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// 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, [5425,2224,6825,3017,3403,7547,5886,5338,6926], () => (__webpack_exec__(9210)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,265 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 9372;
|
||||
exports.ids = [9372];
|
||||
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");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 2081:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("child_process");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 6113:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("crypto");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 7147:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("fs");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3685:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("http");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 1017:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("path");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 2066:
|
||||
/***/ ((__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 _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2224);
|
||||
/* harmony import */ var _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0__);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2163);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1__);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(6825);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2__);
|
||||
/* harmony import */ var _package_shared_functions_backend_db_addDbEntry__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(5338);
|
||||
/* harmony import */ var _package_shared_functions_backend_db_addDbEntry__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_db_addDbEntry__WEBPACK_IMPORTED_MODULE_3__);
|
||||
// @ts-check
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/ const fs = __webpack_require__(7147);
|
||||
const path = __webpack_require__(1017);
|
||||
const { execSync } = __webpack_require__(2081);
|
||||
|
||||
|
||||
|
||||
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* API handler
|
||||
* ==============================================================================
|
||||
* @type {import("next").NextApiHandler}
|
||||
*/ async function handler(req, res) {
|
||||
/**
|
||||
* Check method
|
||||
*
|
||||
* @description Check request method and return if invalid
|
||||
*/ if (req.method !== "POST") return res.json({
|
||||
msg: "Failed!"
|
||||
});
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const user = await _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2___default()(req, res, true);
|
||||
if (!user) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Unauthorized"
|
||||
});
|
||||
}
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const sanitizedReqBody = req.body;
|
||||
const { dbFullName , dbSlug , dbId } = sanitizedReqBody;
|
||||
const userPreset = __webpack_require__(9258);
|
||||
const defaultFields = __webpack_require__(2439);
|
||||
const finalFields = [
|
||||
...defaultFields.slice(0, 2),
|
||||
...userPreset.fields,
|
||||
...defaultFields.slice(2),
|
||||
];
|
||||
userPreset.fields = [
|
||||
...finalFields
|
||||
];
|
||||
/**
|
||||
* Send Response
|
||||
*
|
||||
* @description Send a boolean response
|
||||
*/ try {
|
||||
/**
|
||||
* Create new user folder and file
|
||||
*
|
||||
* @description Create new user folder and file
|
||||
*/ const userSchemaMainFilePath = `./jsonData/dbSchemas/users/user-${user.id}/main.json`;
|
||||
/** @type {import("@/package-shared/types").DSQL_DatabaseSchemaType[]} */ let userSchemaData = JSON.parse(fs.readFileSync(userSchemaMainFilePath, "utf8"));
|
||||
let targetDatabase = userSchemaData.filter((db)=>db.dbFullName === dbFullName)[0];
|
||||
/** @type {number | undefined} */ let existingTableIndex;
|
||||
let existingTable = targetDatabase.tables.filter((table, index)=>{
|
||||
if (table.tableName === "users") {
|
||||
existingTableIndex = index;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
// if (typeof existingTableIndex !== "number")
|
||||
// return res.json({ success: false });
|
||||
if (existingTable?.[0] && typeof existingTableIndex == "number") {
|
||||
targetDatabase.tables[existingTableIndex] = userPreset;
|
||||
} else {
|
||||
targetDatabase.tables.push(userPreset);
|
||||
}
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
/**
|
||||
* Check Children Databases
|
||||
*
|
||||
* @description Check Children Databases
|
||||
*/ if (targetDatabase.childrenDatabases) {
|
||||
for(let i = 0; i < targetDatabase.childrenDatabases.length; i++){
|
||||
const childDb = targetDatabase.childrenDatabases[i];
|
||||
try {
|
||||
const targetChild = userSchemaData.filter((db)=>db.dbFullName === childDb.dbFullName)[0];
|
||||
targetChild.tables = targetDatabase.tables;
|
||||
const targetDbRecord = await _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0___default()(`SELECT * FROM user_databases WHERE user_id = ? AND db_full_name = ?`, [
|
||||
user.id,
|
||||
childDb.dbFullName
|
||||
]);
|
||||
const newChildTableEntry = await _package_shared_functions_backend_db_addDbEntry__WEBPACK_IMPORTED_MODULE_3___default()({
|
||||
dbFullName: "datasquirel",
|
||||
tableName: "user_database_tables",
|
||||
data: {
|
||||
user_id: user.id,
|
||||
db_id: targetDbRecord[0].id,
|
||||
db_slug: targetDbRecord[0].db_slug,
|
||||
table_name: "Users",
|
||||
table_slug: "users"
|
||||
}
|
||||
});
|
||||
} catch (/** @type {any} */ error) {
|
||||
_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1___default()({
|
||||
component: "/api/addUsersTableToDatabase/lines-100-115",
|
||||
message: error.message,
|
||||
user: user
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
fs.writeFileSync(`${userSchemaMainFilePath}`, JSON.stringify(userSchemaData), "utf8");
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
const newTableEntry = await _package_shared_functions_backend_db_addDbEntry__WEBPACK_IMPORTED_MODULE_3___default()({
|
||||
dbFullName: "datasquirel",
|
||||
tableName: "user_database_tables",
|
||||
data: {
|
||||
user_id: user.id,
|
||||
db_id: dbId,
|
||||
db_slug: dbSlug,
|
||||
table_name: "Users",
|
||||
table_slug: "users"
|
||||
}
|
||||
});
|
||||
////////////////////////////////////////
|
||||
const targetPath = path.join(process.cwd(), "/shell");
|
||||
const sanitizedDbName = dbFullName.replace(/[^a-z\_0-9]/g, "");
|
||||
const dbShellUpdate = execSync(`node createDbFromSchema.js --user ${user.id} --database ${sanitizedDbName}`, {
|
||||
cwd: targetPath
|
||||
});
|
||||
console.log(dbShellUpdate.toString());
|
||||
////////////////////////////////////////
|
||||
res.json({
|
||||
success: true
|
||||
});
|
||||
////////////////////////////////////////
|
||||
} catch (/** @type {any} */ error1) {
|
||||
////////////////////////////////////////
|
||||
_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1___default()({
|
||||
component: "/api/addUsersTableToDatabase/main-catch-error",
|
||||
message: error1.message,
|
||||
user: user
|
||||
});
|
||||
res.json({
|
||||
success: false,
|
||||
msg: "Database Files could not be written!"
|
||||
});
|
||||
////////////////////////////////////////
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 2439:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = JSON.parse('[{"fieldName":"id","dataType":"BIGINT","notNullValue":true,"primaryKey":true,"autoIncrement":true},{"fieldName":"uuid","dataType":"UUID","defaultValueLiteral":"UUID()"},{"fieldName":"date_created","dataType":"VARCHAR(250)","nullValue":true},{"fieldName":"date_created_code","dataType":"BIGINT","nullValue":true},{"fieldName":"date_created_timestamp","dataType":"TIMESTAMP","defaultValueLiteral":"CURRENT_TIMESTAMP"},{"fieldName":"date_updated","dataType":"VARCHAR(250)","nullValue":true},{"fieldName":"date_updated_code","dataType":"BIGINT","nullValue":true},{"fieldName":"date_updated_timestamp","dataType":"TIMESTAMP","defaultValueLiteral":"CURRENT_TIMESTAMP","onUpdateLiteral":"CURRENT_TIMESTAMP"}]');
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// 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, [5425,2224,2163,6825,3017,3403,7547,5886,5338,9258], () => (__webpack_exec__(2066)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,184 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 2383;
|
||||
exports.ids = [2383];
|
||||
exports.modules = {
|
||||
|
||||
/***/ 2261:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("serverless-mysql");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 4300:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("buffer");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 2081:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("child_process");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 6113:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("crypto");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 7147:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("fs");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3685:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("http");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 2037:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("os");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 1017:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("path");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 5509:
|
||||
/***/ ((__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 _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2224);
|
||||
/* harmony import */ var _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0__);
|
||||
/* harmony import */ var _functions_backend_suAdminUserAuth__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(4432);
|
||||
/* harmony import */ var _functions_backend_suAdminUserAuth__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_suAdminUserAuth__WEBPACK_IMPORTED_MODULE_1__);
|
||||
// @ts-check
|
||||
const fs = __webpack_require__(7147);
|
||||
const os = __webpack_require__(2037);
|
||||
const { execSync , spawnSync } = __webpack_require__(2081);
|
||||
|
||||
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* API handler
|
||||
* ==============================================================================
|
||||
* @type {import("next").NextApiHandler}
|
||||
*/ async function handler(req, res) {
|
||||
/**
|
||||
* Check method
|
||||
*
|
||||
* @description Check request method and return if invalid
|
||||
*/ if (req.method !== "POST") return res.json({
|
||||
success: false,
|
||||
msg: "Wrong Method"
|
||||
});
|
||||
/**
|
||||
* Validate Form
|
||||
*
|
||||
* @description Check if request body is valid
|
||||
*/ const user = await _functions_backend_suAdminUserAuth__WEBPACK_IMPORTED_MODULE_1___default()(req);
|
||||
if (!user?.logged_in_status) {
|
||||
return res.json({
|
||||
success: false,
|
||||
log: "Unauthorized"
|
||||
});
|
||||
}
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
try {
|
||||
/**
|
||||
* Validate Form
|
||||
*
|
||||
* @description Check if request body is valid
|
||||
*/ const dsqlUser = req.body.user;
|
||||
const dsqlUserId = dsqlUser.id.toString().replace(/[^0-9]/g, "").replace(/\//g, "");
|
||||
const backupFolder = `./jsonData/dbSchemas/users/user-${dsqlUserId}/backups`;
|
||||
if (!fs.existsSync(backupFolder)) {
|
||||
fs.mkdirSync(backupFolder);
|
||||
}
|
||||
const newBackupFolderName = Date.now().toString();
|
||||
fs.mkdirSync(`${backupFolder}/${newBackupFolderName}`);
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
const userDatabases = await _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0___default()(`SHOW databases LIKE ?`, [
|
||||
`datasquirel_user_${dsqlUserId}_%`,
|
||||
]);
|
||||
for(let i = 0; i < userDatabases.length; i++){
|
||||
const dbObject = userDatabases[i];
|
||||
const dbName = Object.values(dbObject)[0].replace(/[^a-z0-9\_]/g, "");
|
||||
////////////////////////////////////////////////
|
||||
const mysqlDumpPath = os.platform().match(/win/i) ? "'" + "C:\\Program Files\\MySQL\\MySQL Server 8.0\\bin\\mysqldump.exe" + "'" : "mysqldump";
|
||||
/** @type {import("child_process").SpawnSyncOptions} */ let execSyncOptions = {
|
||||
cwd: process.cwd()
|
||||
};
|
||||
const filePath = `${backupFolder}/${newBackupFolderName}/${dbName}.sql`;
|
||||
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(`addUserBackup.js exe => ${exe}`);
|
||||
const dumpDb = spawnSync(mysqlDumpPath, [
|
||||
"-u",
|
||||
process.env.DSQL_DB_USERNAME,
|
||||
"-h",
|
||||
process.env.DSQL_DB_HOST,
|
||||
`-p${process.env.DSQL_DB_PASSWORD}`,
|
||||
dbName,
|
||||
">",
|
||||
filePath,
|
||||
], execSyncOptions);
|
||||
// const dumpDb = execSync(mysqlDumpPath, [], execSyncOptions);
|
||||
////////////////////////////////////////////////
|
||||
}
|
||||
////////////////////////////////////////////////
|
||||
fs.copyFileSync(`./jsonData/dbSchemas/users/user-${dsqlUserId}/main.json`, `${backupFolder}/${newBackupFolderName}/main.json`);
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
res.json({
|
||||
success: true
|
||||
});
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
} catch (/** @type {any} */ error) {
|
||||
console.log(error.message);
|
||||
res.json({
|
||||
success: false
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// 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, [5425,2224,4432], () => (__webpack_exec__(5509)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,112 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 7331;
|
||||
exports.ids = [7331];
|
||||
exports.modules = {
|
||||
|
||||
/***/ 4300:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("buffer");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 2081:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("child_process");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 6113:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("crypto");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 7147:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("fs");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3685:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("http");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 5313:
|
||||
/***/ ((__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 _functions_backend_suAdminUserAuth__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(4432);
|
||||
/* harmony import */ var _functions_backend_suAdminUserAuth__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_suAdminUserAuth__WEBPACK_IMPORTED_MODULE_0__);
|
||||
// @ts-check
|
||||
const { execSync } = __webpack_require__(2081);
|
||||
const fs = __webpack_require__(7147);
|
||||
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* API handler
|
||||
* ==============================================================================
|
||||
* @type {import("next").NextApiHandler}
|
||||
*/ async function handler(req, res) {
|
||||
/**
|
||||
* Check method
|
||||
*
|
||||
* @description Check request method and return if invalid
|
||||
*/ if (req.method !== "POST") return res.json({
|
||||
success: false,
|
||||
msg: "Wrong Method"
|
||||
});
|
||||
/**
|
||||
* Validate Form
|
||||
*
|
||||
* @description Check if request body is valid
|
||||
*/ const user = await _functions_backend_suAdminUserAuth__WEBPACK_IMPORTED_MODULE_0___default()(req);
|
||||
if (!user?.logged_in_status) {
|
||||
return res.json({
|
||||
success: false,
|
||||
log: "No Logs"
|
||||
});
|
||||
}
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
/**
|
||||
* Validate Form
|
||||
*
|
||||
* @description Check if request body is valid
|
||||
*/ fs.writeFileSync("./.tmp/error.log", "", "utf-8");
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
res.json({
|
||||
success: true
|
||||
});
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// 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, [5425,4432], () => (__webpack_exec__(5313)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
@@ -0,0 +1 @@
|
||||
{"version":1,"files":["../../../webpack-api-runtime.js","../../../chunks/5425.js","../../../chunks/4432.js","../../../../package.json","../../../../../package.json"]}
|
||||
@@ -0,0 +1,88 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 7194;
|
||||
exports.ids = [7194];
|
||||
exports.modules = {
|
||||
|
||||
/***/ 5184:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("nodemailer");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 7147:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("fs");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 4177:
|
||||
/***/ ((__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 _functions_backend_handleNodemailer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(6926);
|
||||
/* harmony import */ var _functions_backend_handleNodemailer__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_handleNodemailer__WEBPACK_IMPORTED_MODULE_0__);
|
||||
// @ts-check
|
||||
|
||||
const fs = __webpack_require__(7147);
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* API handler
|
||||
* ==============================================================================
|
||||
* @type {import("next").NextApiHandler}
|
||||
*/ async function handler(req, res) {
|
||||
/**
|
||||
* Check method
|
||||
*
|
||||
* @description Check request method and return if invalid
|
||||
*/ if (req.method !== "POST") return res.json({
|
||||
user: null,
|
||||
msg: "Failed"
|
||||
});
|
||||
/**
|
||||
* Validate Form
|
||||
*
|
||||
* @description Check if request body is valid
|
||||
*/ const { component , message , user } = req.body;
|
||||
const log = `💻 CLIENT ERROR ===========================\nUser Id: ${user?.id}\nUser Name: ${user?.first_name} ${user?.last_name}\nUser Email: ${user?.email}\nError Message: ${message}\nComponent: ${component}\nDate: ${Date()}\n========================================`;
|
||||
const initialText = fs.readFileSync(`./.tmp/error.log`, "utf-8");
|
||||
fs.writeFileSync(`./.tmp/error.log`, log);
|
||||
fs.appendFileSync(`./.tmp/error.log`, `\n\n\n\n\n${initialText}`);
|
||||
// if (process.env.NODE_ENV.match(/production/)) {
|
||||
// handleNodemailer({
|
||||
// to: "benoti.san@gmail.com",
|
||||
// subject: "CLIENT Error in Datasquirel Application",
|
||||
// text: "An Error occured in Datasquirel Application Client Side",
|
||||
// html: log,
|
||||
// });
|
||||
// }
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
res.json({
|
||||
success: true
|
||||
});
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// 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, [6926], () => (__webpack_exec__(4177)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
@@ -0,0 +1 @@
|
||||
{"version":1,"files":["../../../webpack-api-runtime.js","../../../chunks/6926.js","../../../../package.json","../../../../../node_modules/nodemailer/package.json","../../../../../node_modules/nodemailer/lib/nodemailer.js","../../../../../node_modules/nodemailer/lib/mailer/index.js","../../../../../node_modules/nodemailer/lib/shared/index.js","../../../../../node_modules/nodemailer/lib/smtp-pool/index.js","../../../../../node_modules/nodemailer/lib/sendmail-transport/index.js","../../../../../node_modules/nodemailer/lib/smtp-transport/index.js","../../../../../node_modules/nodemailer/lib/stream-transport/index.js","../../../../../node_modules/nodemailer/lib/ses-transport/index.js","../../../../../node_modules/nodemailer/lib/json-transport/index.js","../../../../../node_modules/nodemailer/lib/fetch/index.js","../../../../../node_modules/nodemailer/lib/mailer/mail-message.js","../../../../../node_modules/nodemailer/lib/smtp-connection/http-proxy-client.js","../../../../../node_modules/nodemailer/lib/smtp-pool/pool-resource.js","../../../../../node_modules/nodemailer/lib/fetch/cookies.js","../../../../../node_modules/nodemailer/lib/mime-funcs/mime-types.js","../../../../../node_modules/nodemailer/lib/mime-node/le-windows.js","../../../../../node_modules/nodemailer/lib/mail-composer/index.js","../../../../../node_modules/nodemailer/lib/dkim/index.js","../../../../../node_modules/nodemailer/lib/smtp-connection/index.js","../../../../../node_modules/nodemailer/lib/well-known/index.js","../../../../../node_modules/nodemailer/lib/xoauth2/index.js","../../../../../node_modules/nodemailer/lib/mime-funcs/index.js","../../../../../node_modules/nodemailer/lib/mime-node/index.js","../../../../../node_modules/nodemailer/lib/well-known/services.json","../../../../../node_modules/nodemailer/lib/smtp-connection/data-stream.js","../../../../../node_modules/nodemailer/lib/dkim/message-parser.js","../../../../../node_modules/nodemailer/lib/dkim/sign.js","../../../../../node_modules/nodemailer/lib/dkim/relaxed-body.js","../../../../../node_modules/nodemailer/lib/mime-node/last-newline.js","../../../../../node_modules/nodemailer/lib/mime-node/le-unix.js","../../../../../node_modules/nodemailer/lib/base64/index.js","../../../../../node_modules/nodemailer/lib/qp/index.js","../../../../../node_modules/nodemailer/lib/punycode/index.js","../../../../../node_modules/nodemailer/lib/addressparser/index.js","../../../../../package.json"]}
|
||||
@@ -0,0 +1,230 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 2845;
|
||||
exports.ids = [2845];
|
||||
exports.modules = {
|
||||
|
||||
/***/ 4300:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("buffer");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 2081:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("child_process");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 6113:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("crypto");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 7147:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("fs");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3685:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("http");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 2037:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("os");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 233:
|
||||
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
||||
|
||||
// @ts-check
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/
|
||||
const fs = __webpack_require__(7147);
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* ==============================================================================
|
||||
* Main Function
|
||||
* ==============================================================================
|
||||
* @param {{
|
||||
* rootFolderPath: string,
|
||||
* destinationFolderPath: string,
|
||||
* }} params - params
|
||||
*
|
||||
* @returns {boolean} operation successful or not
|
||||
*/ module.exports = function copyFolderRecursively({ rootFolderPath , destinationFolderPath , }) {
|
||||
try {
|
||||
/**
|
||||
* Start Operations
|
||||
*
|
||||
* @description Start Operations
|
||||
*/ fs.mkdirSync(destinationFolderPath);
|
||||
/**
|
||||
* Recursive Copy Function
|
||||
*
|
||||
* @description Recursive Copy Function
|
||||
* @param {string} srcPath - path string
|
||||
* @param {string} dstPath - path string
|
||||
*/ function copyFiles(srcPath, dstPath) {
|
||||
const files = fs.readdirSync(srcPath);
|
||||
for(let i = 0; i < files.length; i++){
|
||||
const file = files[i];
|
||||
if (file?.match(/\..{2,5}$/)) {
|
||||
fs.copyFileSync(`${srcPath}/${file}`, `${dstPath}/${file}`);
|
||||
} else {
|
||||
fs.mkdirSync(`${dstPath}/${file}`, {
|
||||
recursive: true
|
||||
});
|
||||
copyFiles(`${srcPath}/${file}`, `${dstPath}/${file}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
copyFiles(rootFolderPath, destinationFolderPath);
|
||||
return true;
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
} catch (/** @type {any} */ error) {
|
||||
console.log(error.message);
|
||||
return false;
|
||||
}
|
||||
}; ////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 9389:
|
||||
/***/ ((__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 _functions_backend_copyFolderRecursively__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(233);
|
||||
/* harmony import */ var _functions_backend_copyFolderRecursively__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_copyFolderRecursively__WEBPACK_IMPORTED_MODULE_0__);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2163);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1__);
|
||||
/* harmony import */ var _functions_backend_suAdminUserAuth__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(4432);
|
||||
/* harmony import */ var _functions_backend_suAdminUserAuth__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_suAdminUserAuth__WEBPACK_IMPORTED_MODULE_2__);
|
||||
// @ts-check
|
||||
const fs = __webpack_require__(7147);
|
||||
const os = __webpack_require__(2037);
|
||||
const { execSync } = __webpack_require__(2081);
|
||||
|
||||
|
||||
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* API handler
|
||||
* ==============================================================================
|
||||
* @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({
|
||||
success: false,
|
||||
msg: "Failed"
|
||||
});
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
/**
|
||||
* Validate Form
|
||||
*
|
||||
* @description Check if request body is valid
|
||||
*/ const user = await _functions_backend_suAdminUserAuth__WEBPACK_IMPORTED_MODULE_2___default()(req);
|
||||
if (!user?.logged_in_status) {
|
||||
return res.json({
|
||||
success: false,
|
||||
log: "No Logs"
|
||||
});
|
||||
}
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
/**
|
||||
* Validate Form
|
||||
*
|
||||
* @description Check if request body is valid
|
||||
*/ const backupFolder = "./.tmp/backups";
|
||||
if (!fs.existsSync(backupFolder)) {
|
||||
fs.mkdirSync("./.tmp/backups");
|
||||
}
|
||||
const newBackupFolderName = Date.now().toString();
|
||||
fs.mkdirSync(`${backupFolder}/${newBackupFolderName}`);
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
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()
|
||||
};
|
||||
const filePath = `${backupFolder}/${newBackupFolderName}/datasquirel.sql`;
|
||||
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} datasquirel > ${filePath}`;
|
||||
console.log(`createNewBackup.js exe => ${exe}`);
|
||||
const dumpDb = execSync(exe, execSyncOptions);
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
fs.copyFileSync(`./jsonData/dbSchemas/main.json`, `${backupFolder}/${newBackupFolderName}/datasquirelSchema.json`);
|
||||
const copyUserFiles = _functions_backend_copyFolderRecursively__WEBPACK_IMPORTED_MODULE_0___default()({
|
||||
rootFolderPath: `./jsonData/dbSchemas/users`,
|
||||
destinationFolderPath: `${backupFolder}/${newBackupFolderName}/userSchemas`
|
||||
});
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
res.json({
|
||||
success: true
|
||||
});
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
} catch (/** @type {any} */ error) {
|
||||
res.json({
|
||||
success: false
|
||||
});
|
||||
_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1___default()({
|
||||
component: "/api/admin/createNewBackup/lines-73-90",
|
||||
message: error.message
|
||||
});
|
||||
}
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// 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, [5425,2163,4432], () => (__webpack_exec__(9389)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
@@ -0,0 +1 @@
|
||||
{"version":1,"files":["../../../webpack-api-runtime.js","../../../chunks/5425.js","../../../chunks/2163.js","../../../chunks/4432.js","../../../../package.json","../../../../../package.json"]}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@@ -0,0 +1,149 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 9987;
|
||||
exports.ids = [9987];
|
||||
exports.modules = {
|
||||
|
||||
/***/ 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");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3685:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("http");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 1017:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("path");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 2372:
|
||||
/***/ ((__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 _package_shared_functions_backend_varDatabaseDbHandler__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1311);
|
||||
/* harmony import */ var _package_shared_functions_backend_varDatabaseDbHandler__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_varDatabaseDbHandler__WEBPACK_IMPORTED_MODULE_0__);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2163);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1__);
|
||||
/* harmony import */ var _functions_backend_suAdminUserAuth__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(4432);
|
||||
/* harmony import */ var _functions_backend_suAdminUserAuth__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_suAdminUserAuth__WEBPACK_IMPORTED_MODULE_2__);
|
||||
// @ts-check
|
||||
const fs = __webpack_require__(7147);
|
||||
|
||||
|
||||
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* API handler
|
||||
* ==============================================================================
|
||||
* @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({
|
||||
success: false,
|
||||
msg: "Wrong Method"
|
||||
});
|
||||
/**
|
||||
* Validate Form
|
||||
*
|
||||
* @description Check if request body is valid
|
||||
*/ const user = await _functions_backend_suAdminUserAuth__WEBPACK_IMPORTED_MODULE_2___default()(req);
|
||||
if (!user?.logged_in_status) {
|
||||
return res.json({
|
||||
success: false,
|
||||
log: "No Logs"
|
||||
});
|
||||
}
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
/**
|
||||
* Validate Form
|
||||
*
|
||||
* @description Check if request body is valid
|
||||
*/ const { database } = req.query;
|
||||
/**
|
||||
* Validate Form
|
||||
*
|
||||
* @description Check if request body is valid
|
||||
*/ try {
|
||||
const result = await _package_shared_functions_backend_varDatabaseDbHandler__WEBPACK_IMPORTED_MODULE_0___default()({
|
||||
database: typeof database === "string" ? database : "",
|
||||
queryString: `SHOW TABLES FROM ${database}`
|
||||
});
|
||||
if (!result) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Query Failed!"
|
||||
});
|
||||
}
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
res.json({
|
||||
success: true,
|
||||
tables: result.map((/** @type {any} */ table)=>Object.values(table)[0])
|
||||
});
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
} catch (/** @type {any} */ error) {
|
||||
console.log(error.message);
|
||||
res.json({
|
||||
success: false
|
||||
});
|
||||
}
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// 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, [5425,2224,2163,3017,3403,8326,1311,4432], () => (__webpack_exec__(2372)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,111 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 5485;
|
||||
exports.ids = [5485];
|
||||
exports.modules = {
|
||||
|
||||
/***/ 4300:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("buffer");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 6113:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("crypto");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 7147:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("fs");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3685:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("http");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 2235:
|
||||
/***/ ((__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 _functions_backend_suAdminUserAuth__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(4432);
|
||||
/* harmony import */ var _functions_backend_suAdminUserAuth__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_suAdminUserAuth__WEBPACK_IMPORTED_MODULE_0__);
|
||||
// @ts-check
|
||||
|
||||
const fs = __webpack_require__(7147);
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* API handler
|
||||
* ==============================================================================
|
||||
* @type {import("next").NextApiHandler}
|
||||
*/ async function handler(req, res) {
|
||||
/**
|
||||
* Check method
|
||||
*
|
||||
* @description Check request method and return if invalid
|
||||
*/ if (req.method !== "POST") return res.json({
|
||||
success: false,
|
||||
msg: "Wrong Method"
|
||||
});
|
||||
/**
|
||||
* Validate Form
|
||||
*
|
||||
* @description Check if request body is valid
|
||||
*/ const user = await _functions_backend_suAdminUserAuth__WEBPACK_IMPORTED_MODULE_0___default()(req);
|
||||
if (!user?.logged_in_status) {
|
||||
return res.json({
|
||||
success: false,
|
||||
log: "No Logs"
|
||||
});
|
||||
}
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
/**
|
||||
* Validate Form
|
||||
*
|
||||
* @description Check if request body is valid
|
||||
*/ const dsqlUser = req.body.user;
|
||||
const dsqlUserId = dsqlUser.id.toString().replace(/[^0-9]/g, "").replace(/\//g, "");
|
||||
const backupFolder = `./jsonData/dbSchemas/users/user-${dsqlUserId}/backups`;
|
||||
if (!fs.existsSync(backupFolder)) {
|
||||
fs.mkdirSync(backupFolder);
|
||||
}
|
||||
const backups = fs.readdirSync(backupFolder);
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
res.json({
|
||||
success: true,
|
||||
backups: backups
|
||||
});
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// 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, [5425,4432], () => (__webpack_exec__(2235)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
@@ -0,0 +1 @@
|
||||
{"version":1,"files":["../../../webpack-api-runtime.js","../../../chunks/5425.js","../../../chunks/4432.js","../../../../package.json","../../../../../package.json"]}
|
||||
@@ -0,0 +1,164 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 8141;
|
||||
exports.ids = [8141];
|
||||
exports.modules = {
|
||||
|
||||
/***/ 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");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3685:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("http");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 1017:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("path");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 6450:
|
||||
/***/ ((__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 _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2224);
|
||||
/* harmony import */ var _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0__);
|
||||
/* harmony import */ var _functions_backend_suAdminUserAuth__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(4432);
|
||||
/* harmony import */ var _functions_backend_suAdminUserAuth__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_suAdminUserAuth__WEBPACK_IMPORTED_MODULE_1__);
|
||||
// @ts-check
|
||||
|
||||
|
||||
const fs = __webpack_require__(7147);
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* API handler
|
||||
* ==============================================================================
|
||||
* @type {import("next").NextApiHandler}
|
||||
*/ async function handler(req, res) {
|
||||
/**
|
||||
* Check method
|
||||
*
|
||||
* @description Check request method and return if invalid
|
||||
*/ if (req.method !== "POST") return res.json({
|
||||
success: false,
|
||||
msg: "Wrong Method"
|
||||
});
|
||||
/**
|
||||
* Validate Form
|
||||
*
|
||||
* @description Check if request body is valid
|
||||
*/ const user = await _functions_backend_suAdminUserAuth__WEBPACK_IMPORTED_MODULE_1___default()(req);
|
||||
if (!user?.logged_in_status) {
|
||||
return res.json({
|
||||
success: false,
|
||||
log: "No Logs"
|
||||
});
|
||||
}
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
/**
|
||||
* Validate Form
|
||||
*
|
||||
* @description Check if request body is valid
|
||||
*/ const dsqlUser = req.body.user;
|
||||
const dsqlUserId = dsqlUser?.id.toString().replace(/[^0-9]/g, "").replace(/\//g, "");
|
||||
const userFolder = `./jsonData/dbSchemas/users/user-${dsqlUserId}`;
|
||||
/** @type {any[]} */ let userData = [];
|
||||
/**
|
||||
*
|
||||
* @param {object} params
|
||||
* @param {any[]} params.originArray
|
||||
* @param {string} params.rootPath
|
||||
*/ function grabFolderContent({ originArray , rootPath }) {
|
||||
const folderContent = fs.readdirSync(rootPath);
|
||||
for(let i = 0; i < folderContent.length; i++){
|
||||
const fileName = folderContent[i];
|
||||
if (fileName?.match(/\..{2,5}$/)) {
|
||||
originArray.push({
|
||||
name: fileName,
|
||||
type: "file",
|
||||
root: rootPath
|
||||
});
|
||||
} else {
|
||||
const newObject = {
|
||||
name: fileName,
|
||||
type: "folder",
|
||||
root: rootPath,
|
||||
content: []
|
||||
};
|
||||
grabFolderContent({
|
||||
originArray: newObject.content,
|
||||
rootPath: `${rootPath}/${fileName}`
|
||||
});
|
||||
originArray.push(newObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
grabFolderContent({
|
||||
originArray: userData,
|
||||
rootPath: userFolder
|
||||
});
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
/** @type {any[]} */ const userDatabases = await _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0___default()(`SHOW databases LIKE 'datasquirel_user_${dsqlUser.id}_%'`);
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
res.json({
|
||||
success: true,
|
||||
data: userData,
|
||||
databases: userDatabases.map((db)=>Object.values(db)[0])
|
||||
});
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// 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, [5425,2224,4432], () => (__webpack_exec__(6450)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,109 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 3649;
|
||||
exports.ids = [3649];
|
||||
exports.modules = {
|
||||
|
||||
/***/ 4300:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("buffer");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 6113:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("crypto");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 7147:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("fs");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3685:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("http");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 1183:
|
||||
/***/ ((__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 _functions_backend_suAdminUserAuth__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(4432);
|
||||
/* harmony import */ var _functions_backend_suAdminUserAuth__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_suAdminUserAuth__WEBPACK_IMPORTED_MODULE_0__);
|
||||
// @ts-check
|
||||
|
||||
const fs = __webpack_require__(7147);
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* API handler
|
||||
* ==============================================================================
|
||||
* @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({
|
||||
success: false,
|
||||
msg: "Failed"
|
||||
});
|
||||
/**
|
||||
* Validate Form
|
||||
*
|
||||
* @description Check if request body is valid
|
||||
*/ const user = await _functions_backend_suAdminUserAuth__WEBPACK_IMPORTED_MODULE_0___default()(req);
|
||||
if (!user?.logged_in_status) {
|
||||
return res.json({
|
||||
success: false,
|
||||
log: "No Logs"
|
||||
});
|
||||
}
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
/**
|
||||
* Validate Form
|
||||
*
|
||||
* @description Check if request body is valid
|
||||
*/ const backupFolder = "./.tmp/backups";
|
||||
if (!fs.existsSync(backupFolder)) {
|
||||
fs.mkdirSync(backupFolder);
|
||||
}
|
||||
const backups = fs.readdirSync(backupFolder);
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
res.json({
|
||||
success: true,
|
||||
backups: backups
|
||||
});
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// 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, [5425,4432], () => (__webpack_exec__(1183)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
@@ -0,0 +1 @@
|
||||
{"version":1,"files":["../../../webpack-api-runtime.js","../../../chunks/5425.js","../../../chunks/4432.js","../../../../package.json","../../../../../package.json"]}
|
||||
@@ -0,0 +1,111 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 5267;
|
||||
exports.ids = [5267];
|
||||
exports.modules = {
|
||||
|
||||
/***/ 4300:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("buffer");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 6113:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("crypto");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 7147:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("fs");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3685:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("http");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3360:
|
||||
/***/ ((__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 _functions_backend_suAdminUserAuth__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(4432);
|
||||
/* harmony import */ var _functions_backend_suAdminUserAuth__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_suAdminUserAuth__WEBPACK_IMPORTED_MODULE_0__);
|
||||
// @ts-check
|
||||
|
||||
const fs = __webpack_require__(7147);
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* API handler
|
||||
* ==============================================================================
|
||||
* @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({
|
||||
success: false,
|
||||
msg: "Failed"
|
||||
});
|
||||
/**
|
||||
* Validate Form
|
||||
*
|
||||
* @description Check if request body is valid
|
||||
*/ const user = await _functions_backend_suAdminUserAuth__WEBPACK_IMPORTED_MODULE_0___default()(req);
|
||||
if (!user?.logged_in_status) {
|
||||
return res.json({
|
||||
success: false,
|
||||
log: "No Logs"
|
||||
});
|
||||
}
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
/**
|
||||
* Validate Form
|
||||
*
|
||||
* @description Check if request body is valid
|
||||
*/ if (!fs.existsSync("./.tmp/error.log")) {
|
||||
return res.json({
|
||||
success: true,
|
||||
log: "No Logs Yet."
|
||||
});
|
||||
}
|
||||
const errorLogs = fs.readFileSync("./.tmp/error.log", "utf-8");
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
res.json({
|
||||
success: true,
|
||||
log: errorLogs
|
||||
});
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// 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, [5425,4432], () => (__webpack_exec__(3360)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
@@ -0,0 +1 @@
|
||||
{"version":1,"files":["../../../webpack-api-runtime.js","../../../chunks/5425.js","../../../chunks/4432.js","../../../../package.json","../../../../../package.json"]}
|
||||
@@ -0,0 +1,114 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 5736;
|
||||
exports.ids = [5736];
|
||||
exports.modules = {
|
||||
|
||||
/***/ 4300:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("buffer");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 6113:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("crypto");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 7147:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("fs");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3685:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("http");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 9411:
|
||||
/***/ ((__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 _functions_backend_suAdminUserAuth__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(4432);
|
||||
/* harmony import */ var _functions_backend_suAdminUserAuth__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_suAdminUserAuth__WEBPACK_IMPORTED_MODULE_0__);
|
||||
// @ts-check
|
||||
|
||||
const fs = __webpack_require__(7147);
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* API handler
|
||||
* ==============================================================================
|
||||
* @type {import("next").NextApiHandler}
|
||||
*/ async function handler(req, res) {
|
||||
/**
|
||||
* Check method
|
||||
*
|
||||
* @description Check request method and return if invalid
|
||||
*/ if (req.method !== "POST") return res.json({
|
||||
success: false,
|
||||
msg: "Wrong Method"
|
||||
});
|
||||
/**
|
||||
* Validate Form
|
||||
*
|
||||
* @description Check if request body is valid
|
||||
*/ const user = await _functions_backend_suAdminUserAuth__WEBPACK_IMPORTED_MODULE_0___default()(req);
|
||||
if (!user?.logged_in_status) {
|
||||
return res.json({
|
||||
success: false,
|
||||
log: "No Logs"
|
||||
});
|
||||
}
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
/**
|
||||
* Validate Form
|
||||
*
|
||||
* @description Check if request body is valid
|
||||
*/ const { type , path } = req.body;
|
||||
const dsqlUser = req.body.user;
|
||||
if (!path?.match(/^\.\/jsonData\/dbSchemas\/users/)) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Invalid Path"
|
||||
});
|
||||
}
|
||||
const sanitizedPath = path.replace(/\//g, "\\\\");
|
||||
let fileContent = fs.readFileSync(sanitizedPath, "utf-8");
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
res.json({
|
||||
success: true,
|
||||
data: fileContent
|
||||
});
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// 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, [5425,4432], () => (__webpack_exec__(9411)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
@@ -0,0 +1 @@
|
||||
{"version":1,"files":["../../../webpack-api-runtime.js","../../../chunks/5425.js","../../../chunks/4432.js","../../../../package.json","../../../../../package.json"]}
|
||||
@@ -0,0 +1,105 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 2094;
|
||||
exports.ids = [2094];
|
||||
exports.modules = {
|
||||
|
||||
/***/ 4300:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("buffer");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 6113:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("crypto");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 7147:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("fs");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 9393:
|
||||
/***/ ((__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 _package_shared_functions_backend_encrypt__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(7547);
|
||||
/* harmony import */ var _package_shared_functions_backend_encrypt__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_encrypt__WEBPACK_IMPORTED_MODULE_0__);
|
||||
// @ts-check
|
||||
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* API handler
|
||||
* ==============================================================================
|
||||
* @type {import("next").NextApiHandler}
|
||||
*/ async function handler(req, res) {
|
||||
/**
|
||||
* Check method
|
||||
*
|
||||
* @description Check request method and return if invalid
|
||||
*/ if (req.method !== "POST") return res.json({
|
||||
user: null,
|
||||
msg: "Failed"
|
||||
});
|
||||
/**
|
||||
* Validate Form
|
||||
*
|
||||
* @description Check if request body is valid
|
||||
*/ const { email , password , authKey } = req.body;
|
||||
if (false) {}
|
||||
if (false) {}
|
||||
if (password !== process.env.DSQL_USER_KEY) return res.json({
|
||||
success: false
|
||||
});
|
||||
if (authKey !== process.env.DSQL_SPECIAL_KEY) return res.json({
|
||||
success: false
|
||||
});
|
||||
////////////////////////////////////////
|
||||
/**
|
||||
* Validate Form
|
||||
*
|
||||
* @description Check if request body is valid
|
||||
*/ let encryptedPayload = _package_shared_functions_backend_encrypt__WEBPACK_IMPORTED_MODULE_0___default()(JSON.stringify({
|
||||
email: email,
|
||||
password: process.env.DSQL_USER_KEY,
|
||||
authKey: process.env.DSQL_SPECIAL_KEY,
|
||||
logged_in_status: true,
|
||||
date: Date.now()
|
||||
}));
|
||||
res.setHeader("Set-Cookie", [
|
||||
`datasquirelSuAdminUserAuthKey=${encryptedPayload};samesite=strict;path=/;HttpOnly=true;Secure=true`,
|
||||
]);
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
res.json({
|
||||
success: true
|
||||
});
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// 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, [3017,7547], () => (__webpack_exec__(9393)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
@@ -0,0 +1 @@
|
||||
{"version":1,"files":["../../../webpack-api-runtime.js","../../../chunks/3017.js","../../../chunks/7547.js","../../../../package.json","../../../../../package.json"]}
|
||||
@@ -0,0 +1,165 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 6750;
|
||||
exports.ids = [6750];
|
||||
exports.modules = {
|
||||
|
||||
/***/ 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");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3685:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("http");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 1017:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("path");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 4256:
|
||||
/***/ ((__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 _package_shared_functions_backend_varDatabaseDbHandler__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1311);
|
||||
/* harmony import */ var _package_shared_functions_backend_varDatabaseDbHandler__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_varDatabaseDbHandler__WEBPACK_IMPORTED_MODULE_0__);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2163);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1__);
|
||||
/* harmony import */ var _functions_backend_suAdminUserAuth__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(4432);
|
||||
/* harmony import */ var _functions_backend_suAdminUserAuth__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_suAdminUserAuth__WEBPACK_IMPORTED_MODULE_2__);
|
||||
// @ts-check
|
||||
const fs = __webpack_require__(7147);
|
||||
|
||||
|
||||
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* API handler
|
||||
* ==============================================================================
|
||||
* @type {import("next").NextApiHandler}
|
||||
*/ async function handler(req, res) {
|
||||
/**
|
||||
* Check method
|
||||
*
|
||||
* @description Check request method and return if invalid
|
||||
*/ if (req.method !== "POST") return res.json({
|
||||
success: false,
|
||||
msg: "Wrong Method"
|
||||
});
|
||||
/**
|
||||
* Validate Form
|
||||
*
|
||||
* @description Check if request body is valid
|
||||
*/ const user = await _functions_backend_suAdminUserAuth__WEBPACK_IMPORTED_MODULE_2___default()(req);
|
||||
if (!user?.logged_in_status) {
|
||||
return res.json({
|
||||
success: false,
|
||||
log: "No Logs"
|
||||
});
|
||||
}
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
/**
|
||||
* Validate Form
|
||||
*
|
||||
* @description Check if request body is valid
|
||||
*/ const { database , query } = req.body;
|
||||
const dsqlUser = req.body.user;
|
||||
/**
|
||||
* Validate Form
|
||||
*
|
||||
* @description Check if request body is valid
|
||||
*/ try {
|
||||
const allowedQueryRegex = /^select .* from .*|^show tables$|^show indexes from .*|show columns from .*|^update |^delete from /i;
|
||||
const disAllowedQueryRegex = /^create user|INFORMATION_SCHEMA/i;
|
||||
if (!query?.match(allowedQueryRegex) || query?.match(disAllowedQueryRegex)) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Disallowed query"
|
||||
});
|
||||
}
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
const result = await _package_shared_functions_backend_varDatabaseDbHandler__WEBPACK_IMPORTED_MODULE_0___default()({
|
||||
database: database,
|
||||
queryString: query
|
||||
});
|
||||
if (!result) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Query Failed!"
|
||||
});
|
||||
}
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
res.json({
|
||||
success: true,
|
||||
result
|
||||
});
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
} catch (/** @type {any} */ error) {
|
||||
console.log(error.message);
|
||||
_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1___default()({
|
||||
component: "/api/runUserDbQuery/main-catch-error",
|
||||
message: error.message
|
||||
});
|
||||
res.json({
|
||||
success: false
|
||||
});
|
||||
}
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// 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, [5425,2224,2163,3017,3403,8326,1311,4432], () => (__webpack_exec__(4256)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,148 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 1710;
|
||||
exports.ids = [1710];
|
||||
exports.modules = {
|
||||
|
||||
/***/ 6517:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("lodash");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 4300:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("buffer");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 2081:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("child_process");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 6113:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("crypto");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 7147:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("fs");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3685:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("http");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 1017:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("path");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 6520:
|
||||
/***/ ((__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 path__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1017);
|
||||
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_0__);
|
||||
/* harmony import */ var _functions_backend_suAdminUserAuth__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(4432);
|
||||
/* harmony import */ var _functions_backend_suAdminUserAuth__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_suAdminUserAuth__WEBPACK_IMPORTED_MODULE_1__);
|
||||
/* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(6517);
|
||||
/* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(lodash__WEBPACK_IMPORTED_MODULE_2__);
|
||||
// @ts-check
|
||||
const { execSync } = __webpack_require__(2081);
|
||||
const fs = __webpack_require__(7147);
|
||||
|
||||
|
||||
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* API handler
|
||||
* ==============================================================================
|
||||
* @type {import("next").NextApiHandler}
|
||||
*/ async function handler(req, res) {
|
||||
/**
|
||||
* Check method
|
||||
*
|
||||
* @description Check request method and return if invalid
|
||||
*/ if (req.method !== "POST") return res.json({
|
||||
success: false,
|
||||
msg: "Wrong Method"
|
||||
});
|
||||
/**
|
||||
* Validate Form
|
||||
*
|
||||
* @description Check if request body is valid
|
||||
*/ const user = await _functions_backend_suAdminUserAuth__WEBPACK_IMPORTED_MODULE_1___default()(req);
|
||||
if (!user?.logged_in_status) {
|
||||
return res.json({
|
||||
success: false,
|
||||
log: "No Logs"
|
||||
});
|
||||
}
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
/**
|
||||
* Validate Form
|
||||
*
|
||||
* @description Check if request body is valid
|
||||
*/ try {
|
||||
const envPath = path__WEBPACK_IMPORTED_MODULE_0___default().join(process.cwd(), ".env");
|
||||
const envContent = fs.readFileSync(envPath, "utf-8");
|
||||
const envRegex = new RegExp(`${lodash__WEBPACK_IMPORTED_MODULE_2___default().escapeRegExp(req.body.key)}=.*`);
|
||||
const envMatch = envContent.match(envRegex);
|
||||
const newEnv = envContent.replace(envRegex, `${req.body.key}=${req.body.value}`);
|
||||
fs.writeFileSync(envPath, newEnv, "utf-8");
|
||||
res.json({
|
||||
success: true
|
||||
});
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
} catch (/** @type {any} */ error) {
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
console.log("updating Env error =>", error.message);
|
||||
res.json({
|
||||
success: false,
|
||||
error: error.message
|
||||
});
|
||||
}
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// 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, [5425,4432], () => (__webpack_exec__(6520)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
@@ -0,0 +1 @@
|
||||
{"version":1,"files":["../../../webpack-api-runtime.js","../../../chunks/5425.js","../../../chunks/4432.js","../../../../package.json","../../../../../node_modules/lodash/package.json","../../../../../node_modules/lodash/lodash.js","../../../../../package.json","../../../../../.env"]}
|
||||
@@ -0,0 +1,160 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 5705;
|
||||
exports.ids = [5705];
|
||||
exports.modules = {
|
||||
|
||||
/***/ 2029:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("datasquirel/functions/hashPassword");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 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");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3685:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("http");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 1017:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("path");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3509:
|
||||
/***/ ((__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 _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2224);
|
||||
/* harmony import */ var _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0__);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(6825);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_1__);
|
||||
/* harmony import */ var datasquirel_functions_hashPassword__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(2029);
|
||||
/* harmony import */ var datasquirel_functions_hashPassword__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(datasquirel_functions_hashPassword__WEBPACK_IMPORTED_MODULE_2__);
|
||||
// @ts-check
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/
|
||||
|
||||
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* API handler
|
||||
* ==============================================================================
|
||||
* @type {import("next").NextApiHandler}
|
||||
*/ async function handler(req, res) {
|
||||
/**
|
||||
* Check method
|
||||
*
|
||||
* @description Check request method and return if invalid
|
||||
*/ if (req.method !== "POST") return res.json({
|
||||
msg: "Failed!"
|
||||
});
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const user = await _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_1___default()(req, res, true);
|
||||
if (!user) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Unauthorized"
|
||||
});
|
||||
}
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const { userId , password , dbId } = req.body;
|
||||
/**
|
||||
* Input Validation
|
||||
*
|
||||
* @description Input Validation
|
||||
*/ try {
|
||||
const validDbId = Boolean(String(dbId).match(/^\d+$/));
|
||||
const validUserId = Boolean(String(userId).match(/^\d+$/));
|
||||
const invalidPassword = Boolean(String(password).match(/ /));
|
||||
if (!validDbId || !validUserId) {
|
||||
throw new Error("Invalud Parameters!");
|
||||
}
|
||||
if (invalidPassword) {
|
||||
throw new Error("Invalid Password!");
|
||||
}
|
||||
const targetDb = await _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0___default()(`SELECT * FROM user_databases WHERE id = ?`, [
|
||||
dbId
|
||||
]);
|
||||
const dbFullName = targetDb?.[0]?.db_full_name;
|
||||
const newPasswordHashed = datasquirel_functions_hashPassword__WEBPACK_IMPORTED_MODULE_2___default()({
|
||||
encryptionKey: process.env.DSQL_ENCRYPTION_PASSWORD || "",
|
||||
password: password
|
||||
});
|
||||
const updatePassword = await _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0___default()(`UPDATE \`${dbFullName}\`.\`users\` SET password = ? WHERE id = ?`, [
|
||||
newPasswordHashed,
|
||||
userId
|
||||
]);
|
||||
res.json({
|
||||
success: true,
|
||||
msg: "DB user Password Changed!"
|
||||
});
|
||||
} catch (/** @type {any} */ error) {
|
||||
res.json({
|
||||
success: false,
|
||||
msg: error.message
|
||||
});
|
||||
}
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// 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, [5425,2224,6825], () => (__webpack_exec__(3509)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,129 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 9976;
|
||||
exports.ids = [9976];
|
||||
exports.modules = {
|
||||
|
||||
/***/ 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");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 2472:
|
||||
/***/ ((__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 _package_shared_functions_backend_varDatabaseDbHandler__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1311);
|
||||
/* harmony import */ var _package_shared_functions_backend_varDatabaseDbHandler__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_varDatabaseDbHandler__WEBPACK_IMPORTED_MODULE_0__);
|
||||
// @ts-check
|
||||
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* API handler
|
||||
* ==============================================================================
|
||||
* @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({
|
||||
success: false,
|
||||
msg: "Failed!"
|
||||
});
|
||||
/**
|
||||
* Validate Form
|
||||
*
|
||||
* @description Check if request body is valid
|
||||
*/ const sanitizedReqBody = req.query;
|
||||
const { type , value , tableName , dbFullName , userId , dbId , userType , database , } = sanitizedReqBody;
|
||||
// if (!email.match(/.*@.*\..*/)) return res.json({ success: false, msg: "Invalid Email" });
|
||||
/**
|
||||
* Add New Rating
|
||||
*
|
||||
* @description Check user verification status
|
||||
*/ let queryStr = `SELECT \`${type}\` FROM \`${tableName}\` WHERE \`${type}\`=?`;
|
||||
let queryArray = [
|
||||
value
|
||||
];
|
||||
if (userId) {
|
||||
queryStr += " AND user_id=?";
|
||||
queryArray.push(userId);
|
||||
}
|
||||
if (dbId) {
|
||||
queryStr += " AND db_id=?";
|
||||
queryArray.push(dbId);
|
||||
}
|
||||
if (userType) {
|
||||
queryStr += " AND user_type=?";
|
||||
queryArray.push(userType);
|
||||
}
|
||||
if (database) {
|
||||
queryStr += " AND `database`=?";
|
||||
queryArray.push(database);
|
||||
}
|
||||
const duplicate = await _package_shared_functions_backend_varDatabaseDbHandler__WEBPACK_IMPORTED_MODULE_0___default()({
|
||||
queryString: queryStr,
|
||||
queryValuesArray: queryArray,
|
||||
database: dbFullName && typeof dbFullName == "string" ? dbFullName.replace(/[^a-z0-9_]/g, "") : "datasquirel"
|
||||
});
|
||||
/**
|
||||
* Add New Rating
|
||||
*
|
||||
* @description Check user verification status
|
||||
*/ res.json({
|
||||
result: duplicate && duplicate[0] ? true : false
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// 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, [5425,2224,3017,3403,8326,1311], () => (__webpack_exec__(2472)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,130 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 2407;
|
||||
exports.ids = [2407];
|
||||
exports.modules = {
|
||||
|
||||
/***/ 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");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3685:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("http");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 1017:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("path");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 9668:
|
||||
/***/ ((__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 path__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1017);
|
||||
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_0__);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(6825);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_1__);
|
||||
// @ts-check
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/ const fs = __webpack_require__(7147);
|
||||
|
||||
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* API handler
|
||||
* ==============================================================================
|
||||
* @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!"
|
||||
});
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const user = await _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_1___default()(req, res);
|
||||
if (!user) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Unauthorized"
|
||||
});
|
||||
}
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const { name , folder } = req.query;
|
||||
const STATIC_ROOT = process.env.DSQL_STATIC_SERVER_DIR;
|
||||
if (!STATIC_ROOT) {
|
||||
console.log("Static File ENV not Found!");
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "No Static Path!"
|
||||
});
|
||||
}
|
||||
const folderPath = path__WEBPACK_IMPORTED_MODULE_0___default().join(STATIC_ROOT, `images/user-images/user-${user.id}/${folder ? folder + "/" : ""}`);
|
||||
const existingFolderPath = folderPath + name;
|
||||
const doesFolderExist = fs.existsSync(existingFolderPath);
|
||||
/**
|
||||
* Send Response
|
||||
*
|
||||
* @description Send a boolean response
|
||||
*/ res.json({
|
||||
success: doesFolderExist
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// 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, [5425,2224,6825], () => (__webpack_exec__(9668)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,104 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 225;
|
||||
exports.ids = [225];
|
||||
exports.modules = {
|
||||
|
||||
/***/ 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");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3685:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("http");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 1017:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("path");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 8848:
|
||||
/***/ ((__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 _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(6825);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_0__);
|
||||
// @ts-check
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* API handler
|
||||
* ==============================================================================
|
||||
* @type {import("next").NextApiHandler}
|
||||
*/ async function handler(req, res) {
|
||||
/**
|
||||
* Check method
|
||||
*
|
||||
* @description Check request method and return if invalid
|
||||
*/ if (req.method !== "POST") return res.json({
|
||||
msg: "Failed!"
|
||||
});
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const user = await _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_0___default()(req, res, true);
|
||||
/**
|
||||
* Send Response
|
||||
*
|
||||
* @description Send a boolean response
|
||||
*/ res.json({
|
||||
user
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// 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, [5425,2224,6825], () => (__webpack_exec__(8848)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,140 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 8607;
|
||||
exports.ids = [8607];
|
||||
exports.modules = {
|
||||
|
||||
/***/ 4300:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("buffer");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 6113:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("crypto");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 7147:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("fs");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 1017:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("path");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 8026:
|
||||
/***/ ((__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 _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2163);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_0__);
|
||||
/* harmony import */ var _package_shared_functions_backend_decrypt__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(5425);
|
||||
/* harmony import */ var _package_shared_functions_backend_decrypt__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_decrypt__WEBPACK_IMPORTED_MODULE_1__);
|
||||
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(1017);
|
||||
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_2__);
|
||||
// @ts-check
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/ const fs = __webpack_require__(7147);
|
||||
|
||||
|
||||
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* API handler
|
||||
* ==============================================================================
|
||||
* @type {import("next").NextApiHandler}
|
||||
*/ async function handler(req, res) {
|
||||
/**
|
||||
* Check method
|
||||
*
|
||||
* @description Check request method and return if invalid
|
||||
*/ if (req.method !== "POST") return res.json({
|
||||
msg: "Failed!"
|
||||
});
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const sanitizedReqBody = req.body;
|
||||
/** @type {{ url:string, key: string, database: import("@/package-shared/types").DSQL_MYSQL_user_databases_Type, dbSchema: import("@/package-shared/types").DSQL_DatabaseSchemaType, type: "pull" | "push" }} */ const { url , key , database , dbSchema , type } = sanitizedReqBody;
|
||||
/**
|
||||
* Send Response
|
||||
*
|
||||
* @description Send a boolean response
|
||||
*/ try {
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const deletedKeys = fs.readFileSync("./apiKeys/deleted.txt", "utf8");
|
||||
const authorization = key;
|
||||
if (!authorization) return res.json({
|
||||
success: false,
|
||||
msg: "Unauthorized"
|
||||
});
|
||||
if (deletedKeys.includes(authorization)) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Key Inactive!"
|
||||
});
|
||||
}
|
||||
const userJSON = _package_shared_functions_backend_decrypt__WEBPACK_IMPORTED_MODULE_1___default()(authorization);
|
||||
const remoteUser = userJSON ? JSON.parse(userJSON) : null;
|
||||
const { user_id , full_access , csrf } = remoteUser;
|
||||
if (!full_access || !csrf) return res.json({
|
||||
success: false,
|
||||
msg: "Unauthorized"
|
||||
});
|
||||
const userSchemaPath = path__WEBPACK_IMPORTED_MODULE_2___default().resolve(process.cwd(), "jsonData/dbSchemas/users", `user-${user_id}`, "main.json");
|
||||
if (!fs.existsSync(userSchemaPath)) throw new Error("User Shcema data file doesn't exist!");
|
||||
const dbSchema1 = JSON.parse(fs.readFileSync(userSchemaPath, "utf-8"));
|
||||
res.json({
|
||||
success: true,
|
||||
payload: dbSchema1
|
||||
});
|
||||
////////////////////////////////////////
|
||||
} catch (/** @type {any} */ error) {
|
||||
////////////////////////////////////////
|
||||
console.log("Connect Verification Error, =>", error.message);
|
||||
_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_0___default()({
|
||||
component: "/api/connect/main-catch-error",
|
||||
message: error.message
|
||||
});
|
||||
res.json({
|
||||
success: false,
|
||||
msg: "Connect Verification Operation Failed!"
|
||||
});
|
||||
////////////////////////////////////////
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// 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, [5425,2163], () => (__webpack_exec__(8026)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
@@ -0,0 +1 @@
|
||||
{"version":1,"files":["../../webpack-api-runtime.js","../../chunks/5425.js","../../chunks/2163.js","../../../package.json","../../../../package.json","../../../../jsonData/dbSchemas/users/user-1/main.json","../../../../jsonData/dbSchemas/users/user-10/main.json","../../../../jsonData/dbSchemas/users/user-11/main.json","../../../../jsonData/dbSchemas/users/user-13/main.json","../../../../jsonData/dbSchemas/users/user-14/main.json","../../../../jsonData/dbSchemas/users/user-18/main.json","../../../../jsonData/dbSchemas/users/user-12/main.json","../../../../jsonData/dbSchemas/users/user-19/main.json","../../../../jsonData/dbSchemas/users/user-20/main.json","../../../../jsonData/dbSchemas/users/user-3/main.json","../../../../jsonData/dbSchemas/users/user-21/main.json","../../../../jsonData/dbSchemas/users/user-22/main.json","../../../../jsonData/dbSchemas/users/user-4/main.json","../../../../jsonData/dbSchemas/users/user-6/main.json","../../../../jsonData/dbSchemas/users/user-9/main.json"]}
|
||||
@@ -0,0 +1,179 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 7160;
|
||||
exports.ids = [7160];
|
||||
exports.modules = {
|
||||
|
||||
/***/ 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");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3685:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("http");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 1017:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("path");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 7310:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("url");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3837:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("util");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 7131:
|
||||
/***/ ((__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 _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2163);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_0__);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(6825);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_1__);
|
||||
/* harmony import */ var _package_shared_functions_backend_db_updateDbEntry__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(5886);
|
||||
/* harmony import */ var _package_shared_functions_backend_db_updateDbEntry__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_db_updateDbEntry__WEBPACK_IMPORTED_MODULE_2__);
|
||||
// @ts-check
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/ const fs = __webpack_require__(7147);
|
||||
const utils = __webpack_require__(3837);
|
||||
const { URL } = __webpack_require__(7310);
|
||||
|
||||
|
||||
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* API handler
|
||||
* ==============================================================================
|
||||
* @type {import("next").NextApiHandler}
|
||||
*/ async function handler(req, res) {
|
||||
/**
|
||||
* Check method
|
||||
*
|
||||
* @description Check request method and return if invalid
|
||||
*/ if (req.method !== "POST") return res.json({
|
||||
msg: "Failed!"
|
||||
});
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const user = await _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_1___default()(req, res, true);
|
||||
if (!user) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Unauthorized"
|
||||
});
|
||||
}
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const sanitizedReqBody = req.body;
|
||||
const { dbId } = sanitizedReqBody;
|
||||
/**
|
||||
* Send Response
|
||||
*
|
||||
* @description Send a boolean response
|
||||
*/ try {
|
||||
if (!dbId) throw new Error("No Target Database ID provided");
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const updateDb = await _package_shared_functions_backend_db_updateDbEntry__WEBPACK_IMPORTED_MODULE_2___default()({
|
||||
tableName: "user_databases",
|
||||
data: {
|
||||
remote_connected: 0,
|
||||
remote_connection_host: "",
|
||||
remote_connection_key: "",
|
||||
remote_connection_type: "",
|
||||
remote_db_full_name: ""
|
||||
},
|
||||
identifierColumnName: "id",
|
||||
identifierValue: dbId
|
||||
});
|
||||
res.json({
|
||||
success: true
|
||||
});
|
||||
////////////////////////////////////////
|
||||
} catch (/** @type {any} */ error) {
|
||||
////////////////////////////////////////
|
||||
console.log("Disconnect Error, =>", error.message);
|
||||
_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_0___default()({
|
||||
component: "/api/connect/verify/main-catch-error",
|
||||
message: error.message,
|
||||
user: user
|
||||
});
|
||||
res.json({
|
||||
success: false,
|
||||
msg: "Operation Failed!"
|
||||
});
|
||||
////////////////////////////////////////
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// 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, [5425,2224,2163,6825,3017,3403,7547,5886], () => (__webpack_exec__(7131)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,291 @@
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 9569;
|
||||
exports.ids = [9569];
|
||||
exports.modules = {
|
||||
|
||||
/***/ 6109:
|
||||
/***/ ((module) => {
|
||||
|
||||
"use strict";
|
||||
module.exports = require("sanitize-html");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 2261:
|
||||
/***/ ((module) => {
|
||||
|
||||
"use strict";
|
||||
module.exports = require("serverless-mysql");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 4300:
|
||||
/***/ ((module) => {
|
||||
|
||||
"use strict";
|
||||
module.exports = require("buffer");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 2081:
|
||||
/***/ ((module) => {
|
||||
|
||||
"use strict";
|
||||
module.exports = require("child_process");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 6113:
|
||||
/***/ ((module) => {
|
||||
|
||||
"use strict";
|
||||
module.exports = require("crypto");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 7147:
|
||||
/***/ ((module) => {
|
||||
|
||||
"use strict";
|
||||
module.exports = require("fs");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3685:
|
||||
/***/ ((module) => {
|
||||
|
||||
"use strict";
|
||||
module.exports = require("http");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 1017:
|
||||
/***/ ((module) => {
|
||||
|
||||
"use strict";
|
||||
module.exports = require("path");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 7310:
|
||||
/***/ ((module) => {
|
||||
|
||||
"use strict";
|
||||
module.exports = require("url");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3837:
|
||||
/***/ ((module) => {
|
||||
|
||||
"use strict";
|
||||
module.exports = require("util");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 8518:
|
||||
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
||||
|
||||
var __webpack_unused_export__;
|
||||
// @ts-check
|
||||
const { execSync } = __webpack_require__(2081);
|
||||
const fs = __webpack_require__(7147);
|
||||
const path = __webpack_require__(1017);
|
||||
// const serverError = require("./serverError");
|
||||
/**
|
||||
* @async
|
||||
* @param {object} params
|
||||
* @param {number | string} params.userId
|
||||
* @param {DSQL_DatabaseSchemaType[]} params.dbSchema
|
||||
* @param {string} [params.targetDb] - Eg `datasquirel_user_7_db_name`
|
||||
* @returns {string}
|
||||
*/ const dbSchemaExec = ({ userId , dbSchema , targetDb })=>{
|
||||
const userSchemaPath = path.resolve(process.cwd(), "jsonData/dbSchemas/users", `user-${userId}`, "main.json");
|
||||
fs.writeFileSync(userSchemaPath, JSON.stringify(dbSchema), "utf-8");
|
||||
const targetPath = path.join(process.cwd(), "shell");
|
||||
const dbShellUpdate = execSync(`node createDbFromSchema.js --user ${userId}${targetDb ? " --database " + targetDb : ""}`, {
|
||||
cwd: targetPath
|
||||
});
|
||||
return `User ${userId} Db Schema Updated => ${dbShellUpdate.toString("utf-8")}`;
|
||||
};
|
||||
/**
|
||||
* @async
|
||||
* @param {object} params
|
||||
* @param {number | string} params.userId
|
||||
* @param {DSQL_DatabaseSchemaType} params.dbSchema - New Db Schema for `targetDbFullName` variable
|
||||
* @param {DSQL_MYSQL_user_databases_Type} params.database - Db entry
|
||||
* @returns {string}
|
||||
*/ const dbSchemaExecDbUpdate = ({ userId , dbSchema , database })=>{
|
||||
const userSchemaPath = path.resolve(process.cwd(), "jsonData/dbSchemas/users", `user-${userId}`, "main.json");
|
||||
/** @type {DSQL_DatabaseSchemaType[]} */ let userDbSchema = JSON.parse(fs.readFileSync(userSchemaPath, "utf-8"));
|
||||
const targetDbIndex = userDbSchema.findIndex((db)=>db.dbFullName == database.db_full_name);
|
||||
if (targetDbIndex < 0) {
|
||||
throw new Error("Target Database not found in user schema data");
|
||||
}
|
||||
const targetDb = {
|
||||
...userDbSchema[targetDbIndex]
|
||||
};
|
||||
userDbSchema[targetDbIndex] = dbSchema;
|
||||
userDbSchema[targetDbIndex].dbName = targetDb.dbName;
|
||||
userDbSchema[targetDbIndex].dbFullName = targetDb.dbFullName;
|
||||
userDbSchema[targetDbIndex].dbSlug = targetDb.dbSlug;
|
||||
userDbSchema[targetDbIndex].dbImage = targetDb.dbImage;
|
||||
return dbSchemaExec({
|
||||
dbSchema: userDbSchema,
|
||||
userId,
|
||||
targetDb: database.db_full_name
|
||||
});
|
||||
};
|
||||
__webpack_unused_export__ = dbSchemaExec;
|
||||
exports.H = dbSchemaExecDbUpdate;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 2917:
|
||||
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
||||
|
||||
"use strict";
|
||||
__webpack_require__.r(__webpack_exports__);
|
||||
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
||||
/* harmony export */ "default": () => (/* binding */ handler)
|
||||
/* harmony export */ });
|
||||
/* harmony import */ var _functions_backend_dbSchemaExec__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(8518);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2163);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1__);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(6825);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2__);
|
||||
/* harmony import */ var _package_shared_functions_backend_db_updateDbEntry__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(5886);
|
||||
/* harmony import */ var _package_shared_functions_backend_db_updateDbEntry__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_db_updateDbEntry__WEBPACK_IMPORTED_MODULE_3__);
|
||||
// @ts-check
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/ const fs = __webpack_require__(7147);
|
||||
const utils = __webpack_require__(3837);
|
||||
const { URL } = __webpack_require__(7310);
|
||||
|
||||
|
||||
|
||||
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* API handler
|
||||
* ==============================================================================
|
||||
* @type {import("next").NextApiHandler}
|
||||
*/ async function handler(req, res) {
|
||||
/**
|
||||
* Check method
|
||||
*
|
||||
* @description Check request method and return if invalid
|
||||
*/ if (req.method !== "POST") return res.json({
|
||||
msg: "Failed!"
|
||||
});
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const user = await _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2___default()(req, res, true);
|
||||
if (!user) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Unauthorized"
|
||||
});
|
||||
}
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const sanitizedReqBody = req.body;
|
||||
/** @type {import("@/package-shared/types").DbConnectType} */ const { url , key , database , dbSchema , type , remoteDbs , targetDb } = sanitizedReqBody;
|
||||
/**
|
||||
* Send Response
|
||||
*
|
||||
* @description Send a boolean response
|
||||
*/ try {
|
||||
if (!targetDb?.tables) throw new Error("No Target Database");
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const updateDb = await _package_shared_functions_backend_db_updateDbEntry__WEBPACK_IMPORTED_MODULE_3___default()({
|
||||
tableName: "user_databases",
|
||||
// /** @type {DSQL_MYSQL_user_databases_Type} */
|
||||
data: {
|
||||
remote_connected: 1,
|
||||
remote_connection_host: url,
|
||||
remote_connection_key: key,
|
||||
remote_connection_type: type,
|
||||
remote_db_full_name: targetDb.dbFullName
|
||||
},
|
||||
identifierColumnName: "db_full_name",
|
||||
identifierValue: database.db_full_name
|
||||
});
|
||||
const update = (0,_functions_backend_dbSchemaExec__WEBPACK_IMPORTED_MODULE_0__/* .dbSchemaExecDbUpdate */ .H)({
|
||||
dbSchema: targetDb,
|
||||
database: database,
|
||||
userId: user.id
|
||||
});
|
||||
res.json({
|
||||
success: true
|
||||
});
|
||||
////////////////////////////////////////
|
||||
} catch (/** @type {any} */ error) {
|
||||
////////////////////////////////////////
|
||||
console.log("Connect Handshake Error, =>", error.message);
|
||||
_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1___default()({
|
||||
component: "/api/connect/verify/main-catch-error",
|
||||
message: error.message,
|
||||
user: user
|
||||
});
|
||||
res.json({
|
||||
success: false,
|
||||
msg: "Operation Failed!"
|
||||
});
|
||||
////////////////////////////////////////
|
||||
}
|
||||
} // const userSchemaPath = path.resolve(
|
||||
// process.cwd(),
|
||||
// "jsonData/dbSchemas/users",
|
||||
// `user-${user.id}`,
|
||||
// "main.json"
|
||||
// );
|
||||
// if (!fs.existsSync(userSchemaPath))
|
||||
// throw new Error("User Shcema data file doesn't exist!");
|
||||
// /** @type {DSQL_DatabaseSchemaType[]} */
|
||||
// let userDbSchema = JSON.parse(fs.readFileSync(userSchemaPath, "utf-8"));
|
||||
// const targetDbIndex = userDbSchema.findIndex(
|
||||
// (db) => db.dbFullName == dbSchema?.dbFullName
|
||||
// );
|
||||
// if (targetDbIndex < 0)
|
||||
// throw new Error(
|
||||
// "Target Database for handshake not found in user schema data"
|
||||
// );
|
||||
// userDbSchema[targetDbIndex] = targetDb;
|
||||
// userDbSchema[targetDbIndex].dbName = dbSchema.dbName;
|
||||
// userDbSchema[targetDbIndex].dbFullName = dbSchema.dbFullName;
|
||||
// userDbSchema[targetDbIndex].dbSlug = dbSchema.dbSlug;
|
||||
// userDbSchema[targetDbIndex].dbDescription = dbSchema.dbDescription;
|
||||
// userDbSchema[targetDbIndex].dbImage = dbSchema.dbImage;
|
||||
// fs.writeFileSync(userSchemaPath, JSON.stringify(userDbSchema), "utf-8");
|
||||
// const targetPath = path.join(process.cwd(), "shell");
|
||||
// const dbShellUpdate = execSync(
|
||||
// `node createDbFromSchema.js --user ${user.id}`,
|
||||
// { cwd: targetPath }
|
||||
// );
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// 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, [5425,2224,2163,6825,3017,3403,7547,5886], () => (__webpack_exec__(2917)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,188 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 2519;
|
||||
exports.ids = [2519];
|
||||
exports.modules = {
|
||||
|
||||
/***/ 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");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3685:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("http");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 5687:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("https");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 1017:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("path");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 7310:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("url");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3837:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("util");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 7034:
|
||||
/***/ ((__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 _functions_backend_httpsRequest__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(722);
|
||||
/* harmony import */ var _functions_backend_httpsRequest__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_httpsRequest__WEBPACK_IMPORTED_MODULE_0__);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2163);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1__);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(6825);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2__);
|
||||
// @ts-check
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/ const fs = __webpack_require__(7147);
|
||||
const utils = __webpack_require__(3837);
|
||||
const { URL } = __webpack_require__(7310);
|
||||
|
||||
|
||||
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* API handler
|
||||
* ==============================================================================
|
||||
* @type {import("next").NextApiHandler}
|
||||
*/ async function handler(req, res) {
|
||||
/**
|
||||
* Check method
|
||||
*
|
||||
* @description Check request method and return if invalid
|
||||
*/ if (req.method !== "POST") return res.json({
|
||||
msg: "Failed!"
|
||||
});
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const user = await _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2___default()(req, res, true);
|
||||
if (!user) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Unauthorized"
|
||||
});
|
||||
}
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const sanitizedReqBody = req.body;
|
||||
/** @type {{ url:string, key: string, database: import("@/package-shared/types").DSQL_MYSQL_user_databases_Type, dbSchema: import("@/package-shared/types").DSQL_DatabaseSchemaType, type: "pull" | "push" }} */ const { url , key , database , dbSchema , type } = sanitizedReqBody;
|
||||
/**
|
||||
* Send Response
|
||||
*
|
||||
* @description Send a boolean response
|
||||
*/ try {
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const REMOTE_URL = new URL(url);
|
||||
const { hostname , port , protocol } = REMOTE_URL;
|
||||
const pingBody = {
|
||||
url,
|
||||
key
|
||||
};
|
||||
const pingRemote = await _functions_backend_httpsRequest__WEBPACK_IMPORTED_MODULE_0___default()({
|
||||
scheme: protocol,
|
||||
headers: {
|
||||
Authorization: key
|
||||
},
|
||||
hostname: hostname,
|
||||
port: port,
|
||||
path: "/api/connect",
|
||||
method: "POST",
|
||||
body: pingBody
|
||||
});
|
||||
const resultObject = JSON.parse(pingRemote);
|
||||
if (!resultObject?.success) {
|
||||
throw new Error(resultObject.msg || "Remote request failed");
|
||||
}
|
||||
res.json({
|
||||
success: true,
|
||||
payload: resultObject.payload
|
||||
});
|
||||
////////////////////////////////////////
|
||||
} catch (/** @type {any} */ error) {
|
||||
////////////////////////////////////////
|
||||
console.log("Connect Verification Initialtor Error, =>", error.message);
|
||||
_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1___default()({
|
||||
component: "/api/connect/verify/main-catch-error",
|
||||
message: error.message,
|
||||
user: user
|
||||
});
|
||||
res.json({
|
||||
success: false,
|
||||
msg: "Operation Failed!"
|
||||
});
|
||||
////////////////////////////////////////
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// 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, [5425,2224,2163,6825,722], () => (__webpack_exec__(7034)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,123 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 2091;
|
||||
exports.ids = [2091];
|
||||
exports.modules = {
|
||||
|
||||
/***/ 5184:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("nodemailer");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 7147:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("fs");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 7221:
|
||||
/***/ ((__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 _functions_backend_handleNodemailer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(6926);
|
||||
/* harmony import */ var _functions_backend_handleNodemailer__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_handleNodemailer__WEBPACK_IMPORTED_MODULE_0__);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2163);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1__);
|
||||
// @ts-check
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/
|
||||
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* API handler
|
||||
* ==============================================================================
|
||||
* @type {import("next").NextApiHandler}
|
||||
*/ async function handler(req, res) {
|
||||
/**
|
||||
* Check method
|
||||
*
|
||||
* @description Check request method and return if invalid
|
||||
*/ if (req.method !== "POST") return res.json({
|
||||
msg: "Failed!"
|
||||
});
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const sanitizedReqBody = req.body;
|
||||
const { name , email , message } = sanitizedReqBody;
|
||||
if (!email.match(/.*@.*\..*/)) return res.json({
|
||||
success: false,
|
||||
msg: "Invalid Email"
|
||||
});
|
||||
if (!name.match(/./) || !message.match(/./)) return res.json({
|
||||
success: false,
|
||||
msg: "Please Fill in all Fields"
|
||||
});
|
||||
/**
|
||||
* Send Response
|
||||
*
|
||||
* @description Send a boolean response
|
||||
*/ try {
|
||||
/**
|
||||
* Create new user folder and file
|
||||
*
|
||||
* @description Create new user folder and file
|
||||
*/ const mail = await _functions_backend_handleNodemailer__WEBPACK_IMPORTED_MODULE_0___default()({
|
||||
to: "benoti.san@gmail.com",
|
||||
html: `
|
||||
<h2>Message From ${name}, ${email}</h2>
|
||||
<p>${message}</p>
|
||||
`,
|
||||
subject: "Contact Form Submission",
|
||||
text: `Message from ${name}, ${email}`
|
||||
});
|
||||
////////////////////////////////////////
|
||||
if (mail.messageId) {
|
||||
res.json({
|
||||
success: true
|
||||
});
|
||||
} else {
|
||||
res.json({
|
||||
success: false,
|
||||
msg: "Message Sending Failed"
|
||||
});
|
||||
}
|
||||
////////////////////////////////////////
|
||||
} catch (/** @type {any} */ error) {
|
||||
////////////////////////////////////////
|
||||
_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1___default()({
|
||||
component: "/api/contact/main-catch-error",
|
||||
message: error.message
|
||||
});
|
||||
res.json({
|
||||
success: false,
|
||||
msg: "Database Files could not be written!"
|
||||
});
|
||||
////////////////////////////////////////
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// 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, [2163,6926], () => (__webpack_exec__(7221)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
@@ -0,0 +1 @@
|
||||
{"version":1,"files":["../../webpack-api-runtime.js","../../chunks/2163.js","../../chunks/6926.js","../../../package.json","../../../../node_modules/nodemailer/package.json","../../../../node_modules/nodemailer/lib/nodemailer.js","../../../../node_modules/nodemailer/lib/mailer/index.js","../../../../node_modules/nodemailer/lib/shared/index.js","../../../../node_modules/nodemailer/lib/smtp-pool/index.js","../../../../node_modules/nodemailer/lib/sendmail-transport/index.js","../../../../node_modules/nodemailer/lib/smtp-transport/index.js","../../../../node_modules/nodemailer/lib/stream-transport/index.js","../../../../node_modules/nodemailer/lib/ses-transport/index.js","../../../../node_modules/nodemailer/lib/json-transport/index.js","../../../../node_modules/nodemailer/lib/fetch/index.js","../../../../node_modules/nodemailer/lib/mailer/mail-message.js","../../../../node_modules/nodemailer/lib/smtp-connection/http-proxy-client.js","../../../../node_modules/nodemailer/lib/smtp-pool/pool-resource.js","../../../../node_modules/nodemailer/lib/fetch/cookies.js","../../../../node_modules/nodemailer/lib/mime-funcs/mime-types.js","../../../../node_modules/nodemailer/lib/mime-node/le-windows.js","../../../../node_modules/nodemailer/lib/mail-composer/index.js","../../../../node_modules/nodemailer/lib/dkim/index.js","../../../../node_modules/nodemailer/lib/smtp-connection/index.js","../../../../node_modules/nodemailer/lib/well-known/index.js","../../../../node_modules/nodemailer/lib/xoauth2/index.js","../../../../node_modules/nodemailer/lib/mime-funcs/index.js","../../../../node_modules/nodemailer/lib/mime-node/index.js","../../../../node_modules/nodemailer/lib/well-known/services.json","../../../../node_modules/nodemailer/lib/smtp-connection/data-stream.js","../../../../node_modules/nodemailer/lib/dkim/message-parser.js","../../../../node_modules/nodemailer/lib/dkim/sign.js","../../../../node_modules/nodemailer/lib/dkim/relaxed-body.js","../../../../node_modules/nodemailer/lib/mime-node/last-newline.js","../../../../node_modules/nodemailer/lib/mime-node/le-unix.js","../../../../node_modules/nodemailer/lib/base64/index.js","../../../../node_modules/nodemailer/lib/qp/index.js","../../../../node_modules/nodemailer/lib/punycode/index.js","../../../../node_modules/nodemailer/lib/addressparser/index.js","../../../../package.json"]}
|
||||
@@ -0,0 +1,301 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 2316;
|
||||
exports.ids = [2316];
|
||||
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");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 2081:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("child_process");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 6113:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("crypto");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 7147:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("fs");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3685:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("http");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 1017:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("path");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 4577:
|
||||
/***/ ((__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 _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2224);
|
||||
/* harmony import */ var _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0__);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2163);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1__);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(6825);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2__);
|
||||
/* harmony import */ var _package_shared_functions_backend_db_addDbEntry__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(5338);
|
||||
/* harmony import */ var _package_shared_functions_backend_db_addDbEntry__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_db_addDbEntry__WEBPACK_IMPORTED_MODULE_3__);
|
||||
/* harmony import */ var _package_shared_functions_backend_noDatabaseDbHandler__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(9132);
|
||||
/* harmony import */ var _package_shared_functions_backend_noDatabaseDbHandler__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_noDatabaseDbHandler__WEBPACK_IMPORTED_MODULE_4__);
|
||||
// @ts-check
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/ const fs = __webpack_require__(7147);
|
||||
const path = __webpack_require__(1017);
|
||||
const { execSync } = __webpack_require__(2081);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* API handler
|
||||
* ==============================================================================
|
||||
* @type {import("next").NextApiHandler}
|
||||
*/ async function handler(req, res) {
|
||||
/**
|
||||
* Check method
|
||||
*
|
||||
* @description Check request method and return if invalid
|
||||
*/ if (req.method !== "POST") return res.json({
|
||||
msg: "Failed!"
|
||||
});
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const user = await _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2___default()(req, res, true);
|
||||
if (!user) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Unauthorized"
|
||||
});
|
||||
}
|
||||
const fullUserArray = await _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0___default()(`SELECT * FROM users WHERE id = ?`, [
|
||||
user.id,
|
||||
]);
|
||||
const fullUser = fullUserArray?.[0];
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const sanitizedReqBody = req.body;
|
||||
const { db_name , db_slug , db_description , db_image , duplicate , keepUpdated , keepDataUpdated , } = sanitizedReqBody;
|
||||
if (db_slug.match(/[^a-zA-Z0-9-_]/)) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Input Error"
|
||||
});
|
||||
}
|
||||
const db_full_name = `datasquirel_user_${user.id}_${db_slug}`;
|
||||
const createDatabaseForUser = await _package_shared_functions_backend_noDatabaseDbHandler__WEBPACK_IMPORTED_MODULE_4___default()(`CREATE DATABASE IF NOT EXISTS \`${db_full_name}\` CHARACTER SET utf8mb4 COLLATE utf8mb4_bin`);
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ if (!createDatabaseForUser?.affectedRows) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Database Could Not be created!"
|
||||
});
|
||||
}
|
||||
/** @type {any} */ let newDbData = {
|
||||
user_id: user.id,
|
||||
db_name,
|
||||
db_slug,
|
||||
db_full_name,
|
||||
db_description,
|
||||
db_image
|
||||
};
|
||||
if (duplicate && keepUpdated) {
|
||||
newDbData["active_clone"] = "1";
|
||||
newDbData["active_clone_parent_db"] = duplicate;
|
||||
}
|
||||
if (duplicate && keepDataUpdated) {
|
||||
newDbData["active_data"] = "1";
|
||||
}
|
||||
const newDatabaseEntry = await _package_shared_functions_backend_db_addDbEntry__WEBPACK_IMPORTED_MODULE_3___default()({
|
||||
dbFullName: "datasquirel",
|
||||
tableName: "user_databases",
|
||||
data: newDbData
|
||||
});
|
||||
/**
|
||||
* Send Response
|
||||
*
|
||||
* @description Send a boolean response
|
||||
*/ if (newDatabaseEntry.insertId) {
|
||||
try {
|
||||
/**
|
||||
* Create new user folder and file
|
||||
*
|
||||
* @description Create new user folder and file
|
||||
*/ const userSchemaMainFilePath = `./jsonData/dbSchemas/users/user-${user.id}/main.json`;
|
||||
/** @type {import("@/package-shared/types").DSQL_DatabaseSchemaType[]} */ let userSchemaData = JSON.parse(fs.readFileSync(userSchemaMainFilePath, "utf8"));
|
||||
/** @type {any} */ let newDbSchemaObject = {
|
||||
dbName: db_name,
|
||||
dbSlug: db_slug,
|
||||
dbFullName: db_full_name,
|
||||
dbDescription: db_description,
|
||||
dbImage: db_image,
|
||||
tables: []
|
||||
};
|
||||
if (duplicate) {
|
||||
try {
|
||||
const parentDatabase = userSchemaData.filter((db)=>db.dbFullName === duplicate)[0];
|
||||
newDbSchemaObject.tables = parentDatabase.tables;
|
||||
if (keepUpdated) {
|
||||
newDbSchemaObject["childDatabase"] = true;
|
||||
newDbSchemaObject["childDatabaseDbFullName"] = duplicate;
|
||||
if (keepDataUpdated) newDbSchemaObject["updateData"] = true;
|
||||
if (parentDatabase.childrenDatabases) {
|
||||
parentDatabase.childrenDatabases.push({
|
||||
dbFullName: db_full_name
|
||||
});
|
||||
} else {
|
||||
parentDatabase.childrenDatabases = [
|
||||
{
|
||||
dbFullName: db_full_name
|
||||
},
|
||||
];
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
for(let i = 0; i < newDbSchemaObject.tables.length; i++){
|
||||
const newDbTable = newDbSchemaObject.tables[i];
|
||||
const newDbTableRecord = await _package_shared_functions_backend_db_addDbEntry__WEBPACK_IMPORTED_MODULE_3___default()({
|
||||
dbFullName: "datasquirel",
|
||||
tableName: "user_database_tables",
|
||||
data: {
|
||||
user_id: user.id,
|
||||
db_id: newDatabaseEntry.insertId,
|
||||
db_slug: db_slug,
|
||||
table_name: newDbTable.tableFullName,
|
||||
table_slug: newDbTable.tableName
|
||||
}
|
||||
});
|
||||
}
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
} catch (/** @type {any} */ error) {
|
||||
_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1___default()({
|
||||
component: "/api/createUserDatabase/lines-117-159",
|
||||
message: error.message,
|
||||
user: user
|
||||
});
|
||||
}
|
||||
}
|
||||
userSchemaData.push(newDbSchemaObject);
|
||||
fs.writeFileSync(`${userSchemaMainFilePath}`, JSON.stringify(userSchemaData), "utf8");
|
||||
////////////////////////////////////////
|
||||
if (duplicate) {
|
||||
const targetPath = path.join(process.cwd(), "/shell");
|
||||
const dbShellUpdate = execSync(`node createDbFromSchema.js --user ${user.id} --database ${db_full_name}`, {
|
||||
cwd: targetPath
|
||||
});
|
||||
}
|
||||
////////////////////////////////////////
|
||||
const grantDbPriviledges = await _package_shared_functions_backend_noDatabaseDbHandler__WEBPACK_IMPORTED_MODULE_4___default()(`GRANT ALL PRIVILEGES ON ${db_full_name}.* TO '${process.env.DSQL_DB_FULL_ACCESS_USERNAME}'@'${process.env.DSQL_DB_TARGET_IP_ADDRESS || "%"}' WITH GRANT OPTION`);
|
||||
if (grantDbPriviledges.error) {
|
||||
throw new Error(grantDbPriviledges.error);
|
||||
}
|
||||
const grantRead = await _package_shared_functions_backend_noDatabaseDbHandler__WEBPACK_IMPORTED_MODULE_4___default()(`GRANT SELECT ON ${db_full_name}.* TO '${process.env.DSQL_DB_READ_ONLY_USERNAME}'@'${process.env.DSQL_DB_TARGET_IP_ADDRESS || "%"}'`);
|
||||
if (grantRead.error) {
|
||||
throw new Error(grantRead.error);
|
||||
}
|
||||
if (fullUser?.mariadb_user && fullUser?.mariadb_pass) {
|
||||
const grantDbPriviledgesToSqlUser = await _package_shared_functions_backend_noDatabaseDbHandler__WEBPACK_IMPORTED_MODULE_4___default()(`GRANT ALL PRIVILEGES ON ${db_full_name}.* TO '${fullUser.mariadb_user}'@'${fullUser.mariadb_host}'`);
|
||||
}
|
||||
await _package_shared_functions_backend_noDatabaseDbHandler__WEBPACK_IMPORTED_MODULE_4___default()(`FLUSH PRIVILEGES`);
|
||||
////////////////////////////////////////
|
||||
res.json({
|
||||
success: true
|
||||
});
|
||||
////////////////////////////////////////
|
||||
} catch (/** @type {any} */ error1) {
|
||||
////////////////////////////////////////
|
||||
_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1___default()({
|
||||
component: "/api/createUserDatabase/main-catch-error",
|
||||
message: error1.message,
|
||||
user: user
|
||||
});
|
||||
res.json({
|
||||
success: false,
|
||||
msg: "Database Files could not be written!"
|
||||
});
|
||||
////////////////////////////////////////
|
||||
}
|
||||
} else {
|
||||
res.json({
|
||||
success: false,
|
||||
msg: "Database Could Not Be Recorded!"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// 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, [5425,2224,2163,6825,3017,3403,7547,5886,5338,7487,9132], () => (__webpack_exec__(4577)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,188 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 6209;
|
||||
exports.ids = [6209];
|
||||
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");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3685:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("http");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 1017:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("path");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 537:
|
||||
/***/ ((__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 _package_shared_functions_backend_decrypt__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(5425);
|
||||
/* harmony import */ var _package_shared_functions_backend_decrypt__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_decrypt__WEBPACK_IMPORTED_MODULE_0__);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2163);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1__);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(6825);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2__);
|
||||
/* harmony import */ var _package_shared_functions_backend_db_addDbEntry__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(5338);
|
||||
/* harmony import */ var _package_shared_functions_backend_db_addDbEntry__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_db_addDbEntry__WEBPACK_IMPORTED_MODULE_3__);
|
||||
/* harmony import */ var _package_shared_functions_backend_db_deleteDbEntry__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(6147);
|
||||
/* harmony import */ var _package_shared_functions_backend_db_deleteDbEntry__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_db_deleteDbEntry__WEBPACK_IMPORTED_MODULE_4__);
|
||||
/* harmony import */ var _package_shared_functions_backend_api_cred__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(1007);
|
||||
/* harmony import */ var _package_shared_functions_backend_api_cred__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_api_cred__WEBPACK_IMPORTED_MODULE_5__);
|
||||
// @ts-check
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/ const fs = __webpack_require__(7147);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* API handler
|
||||
* ==============================================================================
|
||||
* @type {import("next").NextApiHandler}
|
||||
*/ async function handler(req, res) {
|
||||
/**
|
||||
* Check method
|
||||
*
|
||||
* @description Check request method and return if invalid
|
||||
*/ if (req.method !== "POST") return res.json({
|
||||
msg: "Failed!"
|
||||
});
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const user = await _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2___default()(req, res, true);
|
||||
console.log("User", user);
|
||||
if (!user) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Unauthorized"
|
||||
});
|
||||
}
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const { id , key , user_id } = req.body;
|
||||
/**
|
||||
* Send Response
|
||||
*
|
||||
* @description Send a boolean response
|
||||
*/ try {
|
||||
const allowedKeysPath = process.env.DSQL_API_KEYS_PATH;
|
||||
if (!allowedKeysPath) throw new Error("process.env.DSQL_API_KEYS_PATH variable not found");
|
||||
const apiCred = _package_shared_functions_backend_api_cred__WEBPACK_IMPORTED_MODULE_5___default()({
|
||||
key: key
|
||||
});
|
||||
if (!apiCred?.sign) {
|
||||
await _package_shared_functions_backend_db_deleteDbEntry__WEBPACK_IMPORTED_MODULE_4___default()({
|
||||
dbFullName: "datasquirel",
|
||||
tableName: "api_keys",
|
||||
identifierColumnName: "id",
|
||||
identifierValue: id
|
||||
});
|
||||
throw new Error("API KEY is Invalid");
|
||||
}
|
||||
try {
|
||||
fs.unlinkSync(`${allowedKeysPath}/${apiCred?.sign}`);
|
||||
} catch (/** @type {any} */ error) {
|
||||
console.log("Error Deleting API key", error.message);
|
||||
}
|
||||
/**
|
||||
* Delete API key from database
|
||||
*/ await _package_shared_functions_backend_db_deleteDbEntry__WEBPACK_IMPORTED_MODULE_4___default()({
|
||||
dbFullName: "datasquirel",
|
||||
tableName: "api_keys",
|
||||
identifierColumnName: "id",
|
||||
identifierValue: id
|
||||
});
|
||||
res.json({
|
||||
success: true
|
||||
});
|
||||
////////////////////////////////////////
|
||||
} catch (/** @type {any} */ error1) {
|
||||
////////////////////////////////////////
|
||||
_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1___default()({
|
||||
component: "/api/deleteApiKey/main-catch-error",
|
||||
message: error1.message,
|
||||
user: user
|
||||
});
|
||||
res.json({
|
||||
success: false,
|
||||
msg: "Deletion Failed!"
|
||||
});
|
||||
////////////////////////////////////////
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// 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, [5425,2224,2163,6825,3017,3403,7547,5886,5338,1007,6147], () => (__webpack_exec__(537)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,127 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 5395;
|
||||
exports.ids = [5395];
|
||||
exports.modules = {
|
||||
|
||||
/***/ 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");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3685:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("http");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 1017:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("path");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 8511:
|
||||
/***/ ((__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 _package_shared_functions_backend_varDatabaseDbHandler__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1311);
|
||||
/* harmony import */ var _package_shared_functions_backend_varDatabaseDbHandler__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_varDatabaseDbHandler__WEBPACK_IMPORTED_MODULE_0__);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(6825);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_1__);
|
||||
// @ts-check
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/ const fs = __webpack_require__(7147);
|
||||
|
||||
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* API handler
|
||||
* ==============================================================================
|
||||
* @type {import("next").NextApiHandler}
|
||||
*/ async function handler(req, res) {
|
||||
/**
|
||||
* Check method
|
||||
*
|
||||
* @description Check request method and return if invalid
|
||||
*/ if (req.method !== "POST") return res.json({
|
||||
msg: "Failed!"
|
||||
});
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const user = await _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_1___default()(req, res, true);
|
||||
if (!user) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Unauthorized"
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Input Validation
|
||||
*
|
||||
* @description Input Validation
|
||||
*/ const sanitizedReqBody = req.body;
|
||||
const { dbFullName , userId } = sanitizedReqBody;
|
||||
const deleteUser = await _package_shared_functions_backend_varDatabaseDbHandler__WEBPACK_IMPORTED_MODULE_0___default()({
|
||||
database: dbFullName,
|
||||
queryString: `DELETE FROM users WHERE id = ?`,
|
||||
queryValuesArray: [
|
||||
userId
|
||||
]
|
||||
});
|
||||
res.json({
|
||||
success: true,
|
||||
msg: "User Deleted!"
|
||||
});
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// 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, [5425,2224,6825,3017,3403,8326,1311], () => (__webpack_exec__(8511)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,120 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 593;
|
||||
exports.ids = [593];
|
||||
exports.modules = {
|
||||
|
||||
/***/ 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");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3685:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("http");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 1017:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("path");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 9043:
|
||||
/***/ ((__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 _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2224);
|
||||
/* harmony import */ var _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0__);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(6825);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_1__);
|
||||
// @ts-check
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/
|
||||
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* API handler
|
||||
* ==============================================================================
|
||||
* @type {import("next").NextApiHandler}
|
||||
*/ async function handler(req, res) {
|
||||
/**
|
||||
* Check method
|
||||
*
|
||||
* @description Check request method and return if invalid
|
||||
*/ if (req.method !== "POST") return res.json({
|
||||
msg: "Failed!"
|
||||
});
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const user = await _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_1___default()(req, res, true);
|
||||
if (!user) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Unauthorized"
|
||||
});
|
||||
}
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const deletInvitation = await _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0___default()(`DELETE FROM invitations WHERE id = ? AND inviting_user_id = ?`, [
|
||||
req.body.id,
|
||||
user.id
|
||||
]);
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
res.json({
|
||||
success: true
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// 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, [5425,2224,6825], () => (__webpack_exec__(9043)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,193 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 820;
|
||||
exports.ids = [820];
|
||||
exports.modules = {
|
||||
|
||||
/***/ 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");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3685:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("http");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 1017:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("path");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 2562:
|
||||
/***/ ((__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 _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2224);
|
||||
/* harmony import */ var _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0__);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2163);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1__);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(6825);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2__);
|
||||
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(1017);
|
||||
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_3__);
|
||||
// @ts-check
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/ const fs = __webpack_require__(7147);
|
||||
|
||||
|
||||
|
||||
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* API handler
|
||||
* ==============================================================================
|
||||
* @type {import("next").NextApiHandler}
|
||||
*/ async function handler(req, res) {
|
||||
/**
|
||||
* Check method
|
||||
*
|
||||
* @description Check request method and return if invalid
|
||||
*/ if (req.method !== "POST") return res.json({
|
||||
msg: "Failed!"
|
||||
});
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const user = await _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2___default()(req, res, true);
|
||||
if (!user) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Unauthorized"
|
||||
});
|
||||
}
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const sanitizedReqBody = req.body;
|
||||
const { folder } = sanitizedReqBody;
|
||||
try {
|
||||
/**
|
||||
* ### Clean Target Folder
|
||||
* @param {object} params
|
||||
* @param {string} params.path
|
||||
*/ async function cleanFolder({ path }) {
|
||||
try {
|
||||
const folderFiles = fs.readdirSync(path);
|
||||
for(let i = 0; i < folderFiles.length; i++){
|
||||
const fileName = folderFiles[i];
|
||||
if (!fileName.match(/\..{3,4}$/)) {
|
||||
await cleanFolder({
|
||||
path: path + fileName + "/"
|
||||
});
|
||||
continue;
|
||||
}
|
||||
const targetFolder = path.replace(/.*user-images\/user-\d+\/|.*jsonData\/dbSchemas\/users\/user-\d+\/media\//, "").replace(/\/+$/, "");
|
||||
const targetMediaInDb = await _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0___default()(`SELECT * FROM user_media WHERE folder=? && media_url LIKE '%${fileName}'`, [
|
||||
targetFolder
|
||||
]);
|
||||
if (targetMediaInDb && targetMediaInDb[0]) {
|
||||
await _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0___default()(`DELETE FROM user_media WHERE id = ?`, [
|
||||
targetMediaInDb[0].id
|
||||
]);
|
||||
}
|
||||
try {
|
||||
fs.unlinkSync(path + fileName);
|
||||
} catch (error1) {
|
||||
try {
|
||||
fs.rmdirSync(path + fileName);
|
||||
} catch (error) {}
|
||||
}
|
||||
}
|
||||
fs.rmdirSync(path);
|
||||
} catch (/** @type {any} */ error2) {
|
||||
console.log("File cleaning error =>", error2.message);
|
||||
}
|
||||
}
|
||||
const STATIC_ROOT = process.env.DSQL_STATIC_SERVER_DIR;
|
||||
if (!STATIC_ROOT) {
|
||||
console.log("Static File ENV not Found!");
|
||||
throw new Error("No Static Path!");
|
||||
}
|
||||
const folderPath = path__WEBPACK_IMPORTED_MODULE_3___default().join(STATIC_ROOT, `images/user-images/user-${user.id}/`);
|
||||
const privateFolderPath = `./jsonData/dbSchemas/users/user-${user.id}/media/`;
|
||||
const fullFolderPath = folderPath + (folder ? folder.replace(/\.| /g, "") + "/" : "");
|
||||
const fullPrivateFolderPath = privateFolderPath + (folder ? folder.replace(/\.| /g, "") + "/" : "");
|
||||
await cleanFolder({
|
||||
path: fullFolderPath
|
||||
});
|
||||
await cleanFolder({
|
||||
path: fullPrivateFolderPath
|
||||
});
|
||||
/**
|
||||
* Send Response
|
||||
*
|
||||
* @description Send a boolean response
|
||||
*/ res.json({
|
||||
success: true
|
||||
});
|
||||
} catch (/** @type {any} */ error) {
|
||||
_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1___default()({
|
||||
component: "/api/deleteMediaFolder/main-catch-error",
|
||||
message: error.message,
|
||||
user: user
|
||||
});
|
||||
/**
|
||||
* Send Error Response
|
||||
*
|
||||
* @description Send a boolean response
|
||||
*/ res.json({
|
||||
success: false
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// 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, [5425,2224,2163,6825], () => (__webpack_exec__(2562)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,180 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 9745;
|
||||
exports.ids = [9745];
|
||||
exports.modules = {
|
||||
|
||||
/***/ 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");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3685:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("http");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 1017:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("path");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 6970:
|
||||
/***/ ((__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 _package_shared_functions_backend_db_deleteDbEntry__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(6147);
|
||||
/* harmony import */ var _package_shared_functions_backend_db_deleteDbEntry__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_db_deleteDbEntry__WEBPACK_IMPORTED_MODULE_0__);
|
||||
/* harmony import */ var _functions_backend_checkUserRights__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(8999);
|
||||
/* harmony import */ var _functions_backend_checkUserRights__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_checkUserRights__WEBPACK_IMPORTED_MODULE_1__);
|
||||
/* harmony import */ var _functions_backend_grabDelegatedUserFromCookie__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(1352);
|
||||
/* harmony import */ var _functions_backend_grabDelegatedUserFromCookie__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_grabDelegatedUserFromCookie__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 _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(6825);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_4__);
|
||||
// @ts-check
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* API handler
|
||||
* ==============================================================================
|
||||
* @type {import("next").NextApiHandler}
|
||||
*/ async function handler(req, res) {
|
||||
/**
|
||||
* Check method
|
||||
*
|
||||
* @description Check request method and return if invalid
|
||||
*/ if (req.method !== "POST") return res.json({
|
||||
msg: "Failed!"
|
||||
});
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const user = await _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_4___default()(req, res, true);
|
||||
if (!user) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Unauthorized"
|
||||
});
|
||||
}
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const sanitizedReqBody = req.body;
|
||||
const { dbFullName , tableName , entryId , dbSlug , dbId , delegated } = sanitizedReqBody;
|
||||
/**
|
||||
* Send Response
|
||||
*
|
||||
* @description Send a boolean response
|
||||
*/ try {
|
||||
/**
|
||||
* Check if user has rights to this table
|
||||
*
|
||||
* @description Check if user has rights to this table
|
||||
*/ const delegatedUser = await _functions_backend_grabDelegatedUserFromCookie__WEBPACK_IMPORTED_MODULE_2___default()({
|
||||
databaseSlug: dbSlug,
|
||||
request: req,
|
||||
user: user,
|
||||
query: req.query
|
||||
});
|
||||
const checkUserRightsBoolean = await _functions_backend_checkUserRights__WEBPACK_IMPORTED_MODULE_1___default()({
|
||||
user: user,
|
||||
confirmedDelegetedUser: delegatedUser,
|
||||
database: dbSlug,
|
||||
table: tableName,
|
||||
dbId: dbId,
|
||||
priviledgeRegex: /Delete Entries/i
|
||||
});
|
||||
if (!checkUserRightsBoolean) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Unauthorized"
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Create new user folder and file
|
||||
*
|
||||
* @description Create new user folder and file
|
||||
*/ const deleteTableEntry = await _package_shared_functions_backend_db_deleteDbEntry__WEBPACK_IMPORTED_MODULE_0___default()({
|
||||
dbContext: "Dsql User",
|
||||
paradigm: "Full Access",
|
||||
dbFullName: dbFullName,
|
||||
tableName: tableName,
|
||||
identifierColumnName: "id",
|
||||
identifierValue: entryId
|
||||
});
|
||||
////////////////////////////////////////
|
||||
res.json({
|
||||
success: true
|
||||
});
|
||||
////////////////////////////////////////
|
||||
} catch (/** @type {any} */ error) {
|
||||
////////////////////////////////////////
|
||||
_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_3___default()({
|
||||
component: "/api/deleteTableEntry/main-catch-error",
|
||||
message: error.message,
|
||||
user: user
|
||||
});
|
||||
res.json({
|
||||
success: false,
|
||||
msg: "Deletion Failed!"
|
||||
});
|
||||
////////////////////////////////////////
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// 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, [5425,2224,2163,6825,3403,1352,6147,8999], () => (__webpack_exec__(6970)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,265 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 4739;
|
||||
exports.ids = [4739];
|
||||
exports.modules = {
|
||||
|
||||
/***/ 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");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3685:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("http");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 1017:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("path");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 4512:
|
||||
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
||||
|
||||
// @ts-check
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/
|
||||
const fs = __webpack_require__(7147);
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* ==============================================================================
|
||||
* Main Function
|
||||
* ==============================================================================
|
||||
* @param {{
|
||||
* rootFolderPath: string,
|
||||
* }} params - params
|
||||
*
|
||||
* @returns {boolean} operation successful or not
|
||||
*/ module.exports = function deleteFolderRecursively({ rootFolderPath }) {
|
||||
try {
|
||||
/**
|
||||
* Recursive Copy Function
|
||||
*
|
||||
* @description Recursive Copy Function
|
||||
* @param {string} srcPath
|
||||
*/ function deleteFiles(srcPath) {
|
||||
try {
|
||||
const files = fs.readdirSync(srcPath);
|
||||
for(let i = 0; i < files.length; i++){
|
||||
const file = files[i];
|
||||
if (file?.match(/\..{2,5}$/)) {
|
||||
fs.unlinkSync(`${srcPath}/${file}`);
|
||||
} else {
|
||||
deleteFiles(`${srcPath}/${file}`);
|
||||
}
|
||||
}
|
||||
fs.rmdirSync(`${srcPath}`);
|
||||
} catch (error) {
|
||||
try {
|
||||
fs.unlinkSync(srcPath);
|
||||
} catch (err) {}
|
||||
}
|
||||
}
|
||||
deleteFiles(rootFolderPath);
|
||||
fs.rmSync(`${rootFolderPath}`, {
|
||||
recursive: true,
|
||||
force: true
|
||||
});
|
||||
return true;
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
} catch (/** @type {any} */ error) {
|
||||
console.log("ERROR in deleteFolderRecursively.js function =>", error.message);
|
||||
return false;
|
||||
}
|
||||
}; ////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3456:
|
||||
/***/ ((__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 _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2224);
|
||||
/* harmony import */ var _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0__);
|
||||
/* harmony import */ var _functions_backend_deleteFolderRecursively__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(4512);
|
||||
/* harmony import */ var _functions_backend_deleteFolderRecursively__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_deleteFolderRecursively__WEBPACK_IMPORTED_MODULE_1__);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(2163);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_2__);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(6825);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_3__);
|
||||
// @ts-check
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/ const fs = __webpack_require__(7147);
|
||||
const path = __webpack_require__(1017);
|
||||
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* API handler
|
||||
* ==============================================================================
|
||||
* @type {import("next").NextApiHandler}
|
||||
*/ async function handler(req, res) {
|
||||
/**
|
||||
* Check method
|
||||
*
|
||||
* @description Check request method and return if invalid
|
||||
*/ if (req.method !== "POST") return res.json({
|
||||
msg: "Failed!"
|
||||
});
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const user = await _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_3___default()(req, res, true);
|
||||
if (!user) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Unauthorized"
|
||||
});
|
||||
}
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
const isProduction = "production".match(/prod/i);
|
||||
/**
|
||||
* Send Response
|
||||
*
|
||||
* @description Send a boolean response
|
||||
*/ try {
|
||||
/**
|
||||
* Create new user folder and file
|
||||
*
|
||||
* @description Create new user folder and file
|
||||
*/ const deleteUser = await _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0___default()(`DELETE FROM users WHERE id='${user.id}'`);
|
||||
const deleteUserUser = await _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0___default()(`DELETE FROM user_users WHERE invited_user_id='${user.id}' OR user_id='${user.id}'`);
|
||||
const deleteDelegatedUserTables = await _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0___default()(`DELETE FROM delegated_user_tables WHERE delegated_user_id='${user.id}' OR root_user_id='${user.id}'`);
|
||||
const deleteUserDatabases = await _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0___default()(`DELETE FROM user_databases WHERE user_id='${user.id}'`);
|
||||
const deleteUserDatabaseTables = await _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0___default()(`DELETE FROM user_database_tables WHERE user_id='${user.id}'`);
|
||||
const deleteUserMedia = await _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0___default()(`DELETE FROM user_media WHERE user_id='${user.id}'`);
|
||||
const deleteDelegatedUsers = await _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0___default()(`DELETE FROM delegated_users WHERE user_id='${user.id}' OR delegated_user_id='${user.id}'`);
|
||||
const deleteUnsubscribes = await _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0___default()(`DELETE FROM unsubscribes WHERE user_id='${user.id}'`);
|
||||
const deleteNotifications = await _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0___default()(`DELETE FROM notifications WHERE user_id='${user.id}'`);
|
||||
const deleteApiKeys = await _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0___default()(`DELETE FROM api_keys WHERE user_id='${user.id}'`);
|
||||
const deleteInvitations = await _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0___default()(`DELETE FROM invitations WHERE inviting_user_id='${user.id}' OR invited_user_email='${user.email}'`);
|
||||
const mariadbUsersArray = await _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0___default()(`SELECT * FROM mariadb_users WHERE user_id = ?`, [
|
||||
user.id
|
||||
]);
|
||||
for(let i = 0; i < mariadbUsersArray.length; i++){
|
||||
const mariadbUser = mariadbUsersArray[i];
|
||||
const { username , host } = mariadbUser;
|
||||
const deleteMariadbUsers = await _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0___default()(`DROP USER IF EXISTS '${username}'@'${host}'`);
|
||||
}
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
const userDatabases = await _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0___default()(`SHOW databases LIKE 'datasquirel_user_${user.id}_%'`);
|
||||
for(let i1 = 0; i1 < userDatabases.length; i1++){
|
||||
const dbObj = userDatabases[i1];
|
||||
const dbName = Object.values(dbObj);
|
||||
await _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0___default()(`DROP database IF EXISTS ${dbName}`);
|
||||
}
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
const userSchemaPath = `./jsonData/dbSchemas/users/user-${user.id}/main.json`;
|
||||
if (fs.existsSync(userSchemaPath)) fs.unlinkSync(userSchemaPath);
|
||||
const STATIC_ROOT = process.env.DSQL_STATIC_SERVER_DIR;
|
||||
if (!STATIC_ROOT) {
|
||||
console.log("Static File ENV not Found!");
|
||||
throw new Error("No Static Path!");
|
||||
}
|
||||
const userMediaFolder = path.join(STATIC_ROOT, `images/user-images/user-${user.id}`);
|
||||
if (fs.existsSync(userMediaFolder)) _functions_backend_deleteFolderRecursively__WEBPACK_IMPORTED_MODULE_1___default()({
|
||||
rootFolderPath: userMediaFolder
|
||||
});
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
res.json({
|
||||
success: true
|
||||
});
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
} catch (/** @type {any} */ error) {
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_2___default()({
|
||||
component: "/api/addApiKey/catch-error",
|
||||
message: error.message,
|
||||
user: user
|
||||
});
|
||||
res.json({
|
||||
success: false,
|
||||
msg: "User could not be deleted!"
|
||||
});
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// 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, [5425,2224,2163,6825], () => (__webpack_exec__(3456)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,170 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 8937;
|
||||
exports.ids = [8937];
|
||||
exports.modules = {
|
||||
|
||||
/***/ 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");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3685:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("http");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 1017:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("path");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 2005:
|
||||
/***/ ((__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 _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2224);
|
||||
/* harmony import */ var _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0__);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2163);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1__);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(6825);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2__);
|
||||
/* harmony import */ var _package_shared_functions_backend_noDatabaseDbHandler__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(9132);
|
||||
/* harmony import */ var _package_shared_functions_backend_noDatabaseDbHandler__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_noDatabaseDbHandler__WEBPACK_IMPORTED_MODULE_3__);
|
||||
// @ts-check
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/ const fs = __webpack_require__(7147);
|
||||
|
||||
|
||||
|
||||
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* API handler
|
||||
* ==============================================================================
|
||||
* @type {import("next").NextApiHandler}
|
||||
*/ async function handler(req, res) {
|
||||
/**
|
||||
* Check method
|
||||
*
|
||||
* @description Check request method and return if invalid
|
||||
*/ if (req.method !== "POST") return res.json({
|
||||
msg: "Failed!"
|
||||
});
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const user = await _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2___default()(req, res, true);
|
||||
if (!user) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Unauthorized"
|
||||
});
|
||||
}
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const sanitizedReqBody = req.body;
|
||||
const { id , db_slug , db_full_name } = sanitizedReqBody;
|
||||
if (!db_full_name.match(`user_${user.id}_`)) {
|
||||
throw new Error("Database doesn't belong to user");
|
||||
}
|
||||
await _package_shared_functions_backend_noDatabaseDbHandler__WEBPACK_IMPORTED_MODULE_3___default()(`DROP DATABASE \`${db_full_name}\``);
|
||||
await _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0___default()(`DELETE FROM user_databases WHERE id = ?`, [
|
||||
id
|
||||
]);
|
||||
await _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0___default()(`DELETE FROM user_users WHERE user_id = ? AND \`database\` = ?`, [
|
||||
user.id,
|
||||
db_slug
|
||||
]);
|
||||
try {
|
||||
/**
|
||||
* Send Response
|
||||
*
|
||||
* @description Send a boolean response
|
||||
*/ const userSchemaMainFilePath = `./jsonData/dbSchemas/users/user-${user.id}/main.json`;
|
||||
/** @type {import("@/package-shared/types").DSQL_DatabaseSchemaType[]} */ let userSchemaData = JSON.parse(fs.readFileSync(userSchemaMainFilePath, "utf8"));
|
||||
/** @type {any} */ let targetDatabaseIndex;
|
||||
let targetDatabase = userSchemaData.filter((databaseObject, index)=>{
|
||||
if (databaseObject.dbFullName === db_full_name) {
|
||||
targetDatabaseIndex = index;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
if (targetDatabase[0].childDatabase) {
|
||||
const parentDb = userSchemaData.filter((db)=>db.dbFullName === targetDatabase[0].childDatabaseDbFullName)[0];
|
||||
const targetChildIndex = parentDb.childrenDatabases?.findIndex((val)=>val.dbFullName === targetDatabase[0].childDatabaseDbFullName);
|
||||
if (parentDb.childrenDatabases && typeof targetChildIndex == "number") {
|
||||
parentDb.childrenDatabases.splice(targetChildIndex, 1);
|
||||
}
|
||||
}
|
||||
userSchemaData.splice(targetDatabaseIndex, 1);
|
||||
fs.writeFileSync(`${userSchemaMainFilePath}`, JSON.stringify(userSchemaData), "utf8");
|
||||
////////////////////////////////////////
|
||||
res.json({
|
||||
success: true
|
||||
});
|
||||
////////////////////////////////////////
|
||||
} catch (/** @type {any} */ error) {
|
||||
////////////////////////////////////////
|
||||
_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1___default()({
|
||||
component: "/api/deleteUserDatabase/main-catch-error",
|
||||
message: error.message,
|
||||
user: user
|
||||
});
|
||||
res.json({
|
||||
success: false,
|
||||
msg: "File Updates Failed"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// 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, [5425,2224,2163,6825,3017,7487,9132], () => (__webpack_exec__(2005)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,185 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 551;
|
||||
exports.ids = [551];
|
||||
exports.modules = {
|
||||
|
||||
/***/ 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");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3685:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("http");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 1017:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("path");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 4316:
|
||||
/***/ ((__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 path__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1017);
|
||||
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_0__);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2163);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1__);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(6825);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2__);
|
||||
/* harmony import */ var _functions_backend_grabPaths__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(6715);
|
||||
/* harmony import */ var _functions_backend_grabPaths__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_grabPaths__WEBPACK_IMPORTED_MODULE_3__);
|
||||
/* harmony import */ var _package_shared_functions_backend_db_deleteDbEntry__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(6147);
|
||||
/* harmony import */ var _package_shared_functions_backend_db_deleteDbEntry__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_db_deleteDbEntry__WEBPACK_IMPORTED_MODULE_4__);
|
||||
// @ts-check
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/ const fs = __webpack_require__(7147);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* API handler
|
||||
* ==============================================================================
|
||||
* @type {import("next").NextApiHandler}
|
||||
*/ async function handler(req, res) {
|
||||
/**
|
||||
* Check method
|
||||
*
|
||||
* @description Check request method and return if invalid
|
||||
*/ if (req.method !== "POST") return res.json({
|
||||
msg: "Failed!"
|
||||
});
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const user = await _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2___default()(req, res, true);
|
||||
if (!user) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Unauthorized"
|
||||
});
|
||||
}
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const mediaObject = req.body;
|
||||
const { media_name , media_url , media_thumbnail_url , media_path , media_thumbnail_path , folder , } = mediaObject;
|
||||
const isProduction = "production".match(/production/);
|
||||
/**
|
||||
* Send Response
|
||||
*
|
||||
* @description Send a boolean response
|
||||
*/ try {
|
||||
/**
|
||||
* Create new user folder and file
|
||||
*
|
||||
* @description Create new user folder and file
|
||||
*/ const isPrivate = mediaObject?.private == 1 ? true : false;
|
||||
const STATIC_ROOT = process.env.DSQL_STATIC_SERVER_DIR;
|
||||
if (!STATIC_ROOT) {
|
||||
console.log("Static File ENV not Found!");
|
||||
throw new Error("No Static Path!");
|
||||
}
|
||||
const grabedPaths = _functions_backend_grabPaths__WEBPACK_IMPORTED_MODULE_3___default()({
|
||||
isPrivate: isPrivate,
|
||||
user: user,
|
||||
folder: mediaObject.folder ? mediaObject.folder + "/" : "",
|
||||
video: mediaObject.media_type?.match(/video/i) ? true : false
|
||||
});
|
||||
if (!grabedPaths) {
|
||||
throw new Error("Couldn't grab paths!");
|
||||
}
|
||||
const { fileRootPath , urlRootPath , relativePath } = grabedPaths;
|
||||
const rootFolder = fileRootPath;
|
||||
const mediaFolder = folder?.match(/./) ? "/" + folder + "/" : "/";
|
||||
const fileName = media_url.match(/[^\/]+$/)[0];
|
||||
const fileThumbnailName = media_thumbnail_url.match(/[^\/]+$/)[0];
|
||||
const filePath = path__WEBPACK_IMPORTED_MODULE_0___default().normalize(rootFolder + fileName);
|
||||
const fileThumbnailPath = path__WEBPACK_IMPORTED_MODULE_0___default().normalize(rootFolder + fileThumbnailName);
|
||||
fs.unlinkSync(filePath);
|
||||
try {
|
||||
fs.unlinkSync(fileThumbnailPath);
|
||||
} catch (error) {
|
||||
// console.log("ERROR in deleting user media =>", error.message);
|
||||
}
|
||||
await _package_shared_functions_backend_db_deleteDbEntry__WEBPACK_IMPORTED_MODULE_4___default()({
|
||||
dbFullName: "datasquirel",
|
||||
tableName: "user_media",
|
||||
identifierColumnName: "id",
|
||||
identifierValue: mediaObject.id
|
||||
});
|
||||
////////////////////////////////////////
|
||||
res.json({
|
||||
success: true
|
||||
});
|
||||
////////////////////////////////////////
|
||||
} catch (/** @type {any} */ error1) {
|
||||
////////////////////////////////////////
|
||||
console.log("ERROR in deleting user media =>", error1.message);
|
||||
_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1___default()({
|
||||
component: "/api/deleteUserMedia/main-catch-error",
|
||||
message: error1.message,
|
||||
user: user
|
||||
});
|
||||
res.json({
|
||||
success: false,
|
||||
msg: "Database Files could not be written!"
|
||||
});
|
||||
////////////////////////////////////////
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// 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, [5425,2224,2163,6825,3403,6147,6715], () => (__webpack_exec__(4316)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,218 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 590;
|
||||
exports.ids = [590];
|
||||
exports.modules = {
|
||||
|
||||
/***/ 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");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3685:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("http");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 1017:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("path");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 6772:
|
||||
/***/ ((__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 _package_shared_functions_backend_varDatabaseDbHandler__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1311);
|
||||
/* harmony import */ var _package_shared_functions_backend_varDatabaseDbHandler__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_varDatabaseDbHandler__WEBPACK_IMPORTED_MODULE_0__);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2163);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1__);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(6825);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2__);
|
||||
/* harmony import */ var _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(2224);
|
||||
/* harmony import */ var _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_3__);
|
||||
// @ts-check
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/ const fs = __webpack_require__(7147);
|
||||
|
||||
|
||||
|
||||
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* API handler
|
||||
* ==============================================================================
|
||||
* @type {import("next").NextApiHandler}
|
||||
*/ async function handler(req, res) {
|
||||
/**
|
||||
* Check method
|
||||
*
|
||||
* @description Check request method and return if invalid
|
||||
*/ if (req.method !== "POST") return res.json({
|
||||
msg: "Failed!"
|
||||
});
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const user = await _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2___default()(req, res, true);
|
||||
if (!user) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Unauthorized"
|
||||
});
|
||||
}
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const sanitizedReqBody = req.body;
|
||||
const { id , user_id , table_name , table_slug , table_description } = sanitizedReqBody.table;
|
||||
const { db_full_name } = sanitizedReqBody.database;
|
||||
await _package_shared_functions_backend_varDatabaseDbHandler__WEBPACK_IMPORTED_MODULE_0___default()({
|
||||
database: db_full_name,
|
||||
queryString: `DROP TABLE \`${table_slug}\``
|
||||
});
|
||||
const deleteTableQuery = id ? `DELETE FROM user_database_tables WHERE id=?` : `DELETE FROM user_database_tables WHERE table_slug=? AND user_id=? AND db_id=?`;
|
||||
const deleteTableQueryValues = id ? [
|
||||
id
|
||||
] : [
|
||||
table_slug,
|
||||
user.id,
|
||||
sanitizedReqBody.database.id
|
||||
];
|
||||
await _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_3___default()(deleteTableQuery, deleteTableQueryValues);
|
||||
try {
|
||||
/**
|
||||
* Send Response
|
||||
*
|
||||
* @description Send a boolean response
|
||||
*/ const userSchemaMainFilePath = `./jsonData/dbSchemas/users/user-${user.id}/main.json`;
|
||||
/** @type {import("@/package-shared/types").DSQL_DatabaseSchemaType[]} */ let userSchemaData = JSON.parse(fs.readFileSync(userSchemaMainFilePath, "utf8"));
|
||||
let targetDatabaseIndex;
|
||||
let targetDatabase = userSchemaData.filter((databaseObject, index)=>{
|
||||
if (databaseObject.dbFullName === db_full_name) {
|
||||
targetDatabaseIndex = index;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
/** @type {any} */ let targetTableIndex;
|
||||
let targetTable = targetDatabase[0].tables.filter((tableObject, index)=>{
|
||||
if (tableObject?.tableName === table_slug) {
|
||||
targetTableIndex = index;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
if (targetTable[0].childTable) {
|
||||
const parentDb = userSchemaData.filter((db)=>db.dbFullName === targetTable[0].childTableDbFullName)[0];
|
||||
const parentTableObject = parentDb.tables.filter((table)=>{
|
||||
if (table.tableName === targetTable[0].childTableName) {
|
||||
return true;
|
||||
}
|
||||
})[0];
|
||||
let targetChildIndex;
|
||||
const parentTableChildObject = parentTableObject.childrenTables?.filter((childTable, index)=>{
|
||||
if (childTable.tableName === table_slug) {
|
||||
targetChildIndex = index;
|
||||
}
|
||||
});
|
||||
if (typeof targetChildIndex === "number") parentTableObject.childrenTables?.splice(targetChildIndex, 1);
|
||||
}
|
||||
targetDatabase[0].tables.splice(targetTableIndex, 1);
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
/**
|
||||
* Check Children Databases
|
||||
*
|
||||
* @description Check Children Databases
|
||||
*/ if (targetDatabase[0].childrenDatabases) {
|
||||
for(let i = 0; i < targetDatabase[0].childrenDatabases.length; i++){
|
||||
const childDb = targetDatabase[0].childrenDatabases[i];
|
||||
try {
|
||||
const targetChild = userSchemaData.filter((db)=>db.dbFullName === childDb.dbFullName)[0];
|
||||
targetChild.tables = targetDatabase[0].tables;
|
||||
await _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_3___default()(`DELETE FROM user_database_tables WHERE table_slug=? AND user_id=? AND db_slug=?`, [
|
||||
table_slug,
|
||||
user.id,
|
||||
targetChild.dbSlug
|
||||
]);
|
||||
} catch (/** @type {any} */ error) {
|
||||
_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1___default()({
|
||||
component: "/api/deleteUserTable/lines-125-128",
|
||||
message: error.message,
|
||||
user: user
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
fs.writeFileSync(`${userSchemaMainFilePath}`, JSON.stringify(userSchemaData), "utf8");
|
||||
////////////////////////////////////////
|
||||
res.json({
|
||||
success: true
|
||||
});
|
||||
////////////////////////////////////////
|
||||
} catch (/** @type {any} */ error1) {
|
||||
////////////////////////////////////////
|
||||
_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1___default()({
|
||||
component: "/api/deleteUserTable/main-catch-error",
|
||||
message: error1.message,
|
||||
user: user
|
||||
});
|
||||
res.json({
|
||||
success: false,
|
||||
msg: "File Updates Failed"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// 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, [5425,2224,2163,6825,3017,3403,8326,1311], () => (__webpack_exec__(6772)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,134 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 3857;
|
||||
exports.ids = [3857];
|
||||
exports.modules = {
|
||||
|
||||
/***/ 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");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3685:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("http");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 1017:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("path");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 4229:
|
||||
/***/ ((__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 _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2224);
|
||||
/* harmony import */ var _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0__);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(6825);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_1__);
|
||||
// @ts-check
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/ const fs = __webpack_require__(7147);
|
||||
|
||||
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* API handler
|
||||
* ==============================================================================
|
||||
* @type {import("next").NextApiHandler}
|
||||
*/ async function handler(req, res) {
|
||||
/**
|
||||
* Check method
|
||||
*
|
||||
* @description Check request method and return if invalid
|
||||
*/ if (req.method !== "POST") return res.json({
|
||||
msg: "Failed!"
|
||||
});
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const user = await _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_1___default()(req, res, true);
|
||||
if (!user) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Unauthorized"
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Input Validation
|
||||
*
|
||||
* @description Input Validation
|
||||
*/ const sanitizedReqBody = req.body;
|
||||
const { user_type , user_id , email , invited_user_id } = sanitizedReqBody;
|
||||
const deleteUser = await _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0___default()(`DELETE FROM user_users WHERE id=?`, [
|
||||
sanitizedReqBody.id,
|
||||
]);
|
||||
if (user_type?.match(/admin/i)) {
|
||||
const deleteUserInvitation = await _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0___default()(`DELETE FROM invitations WHERE inviting_user_id=? AND invited_user_email=?`, [
|
||||
user.id,
|
||||
email
|
||||
]);
|
||||
const deleteUserDelegatedTables = await _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0___default()(`DELETE FROM delegated_user_tables WHERE delegated_user_id=? AND root_user_id=?`, [
|
||||
invited_user_id,
|
||||
user.id
|
||||
]);
|
||||
}
|
||||
// fs.unlinkSync()
|
||||
res.json({
|
||||
success: true,
|
||||
msg: "User Deleted!"
|
||||
});
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// 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, [5425,2224,6825], () => (__webpack_exec__(4229)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,151 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 7896;
|
||||
exports.ids = [7896];
|
||||
exports.modules = {
|
||||
|
||||
/***/ 2261:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("serverless-mysql");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 4300:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("buffer");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 2081:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("child_process");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 6113:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("crypto");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 7147:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("fs");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3685:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("http");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 2037:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("os");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 1017:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("path");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 711:
|
||||
/***/ ((__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 _functions_backend_exportDb__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(4194);
|
||||
/* harmony import */ var _functions_backend_exportDb__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_exportDb__WEBPACK_IMPORTED_MODULE_0__);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(6825);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_1__);
|
||||
// @ts-check
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/
|
||||
|
||||
const fs = __webpack_require__(7147);
|
||||
const path = __webpack_require__(1017);
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* API handler
|
||||
* ==============================================================================
|
||||
* @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!"
|
||||
});
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const user = await _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_1___default()(req, res, true);
|
||||
if (!user) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Unauthorized"
|
||||
});
|
||||
}
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const { dbName } = req.query;
|
||||
/**
|
||||
* Input Validation
|
||||
*
|
||||
* @description Input Validation
|
||||
*/ try {
|
||||
const schemaPath = path.resolve(process.cwd(), "jsonData/dbSchemas/users", `user-${user.id}/main.json`);
|
||||
if (!fs.existsSync(schemaPath)) {
|
||||
return res.end();
|
||||
}
|
||||
/** @type {import("@/package-shared/types").DSQL_DatabaseSchemaType[]} */ const schemaData = JSON.parse(fs.readFileSync(schemaPath, "utf-8"));
|
||||
const targetSchema = schemaData.find((schema)=>schema.dbFullName == dbName);
|
||||
if (!targetSchema) throw new Error("Database not found!");
|
||||
const targetWritePath = path.resolve(process.cwd(), "./.tmp/_tmp.json");
|
||||
fs.writeFileSync(targetWritePath, JSON.stringify(targetSchema), "utf-8");
|
||||
const fileStream = fs.createReadStream(targetWritePath);
|
||||
fileStream.pipe(res);
|
||||
fileStream.on("close", ()=>{
|
||||
fs.unlinkSync(targetWritePath);
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
return res.end();
|
||||
}
|
||||
////////////////////////////////////////
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// 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, [5425,2224,2163,6825,4194], () => (__webpack_exec__(711)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,136 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 9470;
|
||||
exports.ids = [9470];
|
||||
exports.modules = {
|
||||
|
||||
/***/ 2261:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("serverless-mysql");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 4300:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("buffer");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 2081:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("child_process");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 6113:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("crypto");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 7147:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("fs");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3685:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("http");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 2037:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("os");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 1017:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("path");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 8507:
|
||||
/***/ ((__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 _functions_backend_exportDb__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(4194);
|
||||
/* harmony import */ var _functions_backend_exportDb__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_exportDb__WEBPACK_IMPORTED_MODULE_0__);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(6825);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_1__);
|
||||
// @ts-check
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/
|
||||
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* API handler
|
||||
* ==============================================================================
|
||||
* @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!"
|
||||
});
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const user = await _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_1___default()(req, res, true);
|
||||
if (!user) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Unauthorized"
|
||||
});
|
||||
}
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const { dbName } = req.query;
|
||||
/**
|
||||
* Input Validation
|
||||
*
|
||||
* @description Input Validation
|
||||
*/ const file = await _functions_backend_exportDb__WEBPACK_IMPORTED_MODULE_0___default()({
|
||||
dbName: dbName?.toString() || "",
|
||||
res: res,
|
||||
user: user
|
||||
});
|
||||
// res.json({ success: true, text: file });
|
||||
////////////////////////////////////////
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// 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, [5425,2224,2163,6825,4194], () => (__webpack_exec__(8507)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,162 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 3368;
|
||||
exports.ids = [3368];
|
||||
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");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3685:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("http");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 1017:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("path");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 5856:
|
||||
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
||||
|
||||
__webpack_require__.r(__webpack_exports__);
|
||||
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
||||
/* harmony export */ "config": () => (/* binding */ config),
|
||||
/* harmony export */ "default": () => (/* binding */ handler)
|
||||
/* harmony export */ });
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(6825);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_0__);
|
||||
/* harmony import */ var _functions_backend_importExportTableDataFn__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2630);
|
||||
// @ts-check
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/
|
||||
|
||||
const config = {
|
||||
api: {
|
||||
responseLimit: "1mb",
|
||||
bodyParser: {
|
||||
sizeLimit: "200mb"
|
||||
}
|
||||
}
|
||||
};
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* API handler
|
||||
* ==============================================================================
|
||||
* @type {import("next").NextApiHandler}
|
||||
*/ async function handler(req, res) {
|
||||
/**
|
||||
* Check method
|
||||
*
|
||||
* @description Check request method and return if invalid
|
||||
*/ if (req.method !== "POST") return res.json({
|
||||
msg: "Failed!"
|
||||
});
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const user = await _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_0___default()(req, res, true);
|
||||
if (!user) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Unauthorized"
|
||||
});
|
||||
}
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const { paradigm , dbName , tableName , payload } = req.body;
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
try {
|
||||
const exportData = await (0,_functions_backend_importExportTableDataFn__WEBPACK_IMPORTED_MODULE_1__/* ["default"] */ .Z)({
|
||||
dbName,
|
||||
paradigm,
|
||||
payload,
|
||||
tableName,
|
||||
userId: user.id,
|
||||
payloadType: "base64"
|
||||
});
|
||||
if (!exportData) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Operation Failed!"
|
||||
});
|
||||
}
|
||||
res.json({
|
||||
success: true,
|
||||
msg: "Success!",
|
||||
data: exportData?.tableData
|
||||
});
|
||||
} catch (/** @type {any} */ error) {
|
||||
res.json({
|
||||
success: false,
|
||||
msg: error.message
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// 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, [5425,2224,2163,6825,3017,3403,7547,5886,5338,2630], () => (__webpack_exec__(5856)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,180 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 8362;
|
||||
exports.ids = [8362];
|
||||
exports.modules = {
|
||||
|
||||
/***/ 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");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3685:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("http");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 1017:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("path");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 1118:
|
||||
/***/ ((__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 _package_shared_functions_backend_varDatabaseDbHandler__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1311);
|
||||
/* harmony import */ var _package_shared_functions_backend_varDatabaseDbHandler__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_varDatabaseDbHandler__WEBPACK_IMPORTED_MODULE_0__);
|
||||
// @ts-check
|
||||
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/ const checkUserRights = __webpack_require__(8999);
|
||||
const grabDelegatedUserFromCookie = __webpack_require__(1352);
|
||||
const serverError = __webpack_require__(2163);
|
||||
const userAuth = __webpack_require__(6825);
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* @typedef {object} FetchEntriesBasicBody
|
||||
* @property {string} tableName
|
||||
* @property {string} dbSlug
|
||||
* @property {number} dbId
|
||||
* @property {boolean} [isTitle]
|
||||
* @property {boolean} [isSlug]
|
||||
* @property {boolean} [isFullName]
|
||||
* @property {string} [defaultField]
|
||||
*/ /**
|
||||
* API handler
|
||||
* ==============================================================================
|
||||
* @type {import("next").NextApiHandler}
|
||||
*/ async function handler(req, res) {
|
||||
/**
|
||||
* Check method
|
||||
*
|
||||
* @description Check request method and return if invalid
|
||||
*/ if (req.method !== "POST") return res.json({
|
||||
msg: "Failed!"
|
||||
});
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const user = await userAuth(req, res, true);
|
||||
if (!user) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "User Auth Failed"
|
||||
});
|
||||
}
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ /** @type {FetchEntriesBasicBody} */ const { tableName , dbSlug , dbId , isTitle , isSlug , isFullName , defaultField , } = req.body;
|
||||
/**
|
||||
* Send Response
|
||||
*
|
||||
* @description Send a boolean response
|
||||
*/ try {
|
||||
/**
|
||||
* Check if user has rights to this table
|
||||
*
|
||||
* @description Check if user has rights to this table
|
||||
*/ const delegatedUser = await grabDelegatedUserFromCookie({
|
||||
databaseSlug: dbSlug,
|
||||
request: req,
|
||||
user: user,
|
||||
query: req.query
|
||||
});
|
||||
const checkUserRightsBoolean = await checkUserRights({
|
||||
user: user,
|
||||
confirmedDelegetedUser: delegatedUser,
|
||||
database: dbSlug,
|
||||
table: tableName,
|
||||
dbId: dbId,
|
||||
priviledgeRegex: /Update Entries/i
|
||||
});
|
||||
if (!checkUserRightsBoolean) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Unauthorized"
|
||||
});
|
||||
}
|
||||
const dbFullName = delegatedUser?.rootUserId ? `datasquirel_user_${delegatedUser.rootUserId}_${dbSlug}` : `datasquirel_user_${user.id}_${dbSlug}`;
|
||||
const queryString = `SELECT id${isTitle ? ",title" : isSlug ? ",slug" : isFullName ? ",CONCAT(first_name, ' ', last_name) AS full_name" : defaultField ? "," + defaultField : ""} FROM ${tableName}`;
|
||||
const entries = await _package_shared_functions_backend_varDatabaseDbHandler__WEBPACK_IMPORTED_MODULE_0___default()({
|
||||
database: dbFullName,
|
||||
queryString: queryString
|
||||
});
|
||||
/**
|
||||
* Create new user folder and file
|
||||
*
|
||||
* @description Create new user folder and file
|
||||
*/ ////////////////////////////////////////
|
||||
res.json({
|
||||
success: true,
|
||||
entries
|
||||
});
|
||||
////////////////////////////////////////
|
||||
} catch (/** @type {any} */ error) {
|
||||
////////////////////////////////////////
|
||||
serverError({
|
||||
component: "/api/addTableEntry/catch-error",
|
||||
message: error.message,
|
||||
user: user
|
||||
});
|
||||
res.json({
|
||||
success: false,
|
||||
msg: "Database Files could not be written!",
|
||||
err: error.message
|
||||
});
|
||||
////////////////////////////////////////
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// 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, [5425,2224,2163,6825,3017,3403,8326,1311,1352,8999], () => (__webpack_exec__(1118)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,209 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 7072;
|
||||
exports.ids = [7072];
|
||||
exports.modules = {
|
||||
|
||||
/***/ 6517:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("lodash");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 2261:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("serverless-mysql");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 4300:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("buffer");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 2081:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("child_process");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 6113:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("crypto");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 7147:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("fs");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3685:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("http");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 1017:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("path");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 7840:
|
||||
/***/ ((__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 _functions_backend_grabUserSchemaData__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(8164);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2163);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1__);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(6825);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2__);
|
||||
/* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(6517);
|
||||
/* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(lodash__WEBPACK_IMPORTED_MODULE_3__);
|
||||
/* harmony import */ var _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(2224);
|
||||
/* harmony import */ var _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_4__);
|
||||
// @ts-check
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/ const fs = __webpack_require__(7147);
|
||||
const path = __webpack_require__(1017);
|
||||
const { execSync } = __webpack_require__(2081);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* @typedef {object} SyncTableBodySrcDstObject
|
||||
* @property {string} db
|
||||
* @property {string} table
|
||||
*/ /**
|
||||
* @typedef {object} SyncTableBody
|
||||
* @property {"Pull" | "Push"} paradigm
|
||||
* @property {SyncTableBodySrcDstObject} src
|
||||
* @property {SyncTableBodySrcDstObject} dst
|
||||
* @property {any} [delegated]
|
||||
*/ /**
|
||||
* API handler
|
||||
* ==============================================================================
|
||||
* @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!"
|
||||
});
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const user = await _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2___default()(req, res);
|
||||
if (!user) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Unauthorized"
|
||||
});
|
||||
}
|
||||
const dbUserId = req.query.dbUserId;
|
||||
const delegated = req.query.delegated;
|
||||
/**
|
||||
* Send Response
|
||||
*
|
||||
* @description Send a boolean response
|
||||
*/ try {
|
||||
if (!dbUserId) {
|
||||
throw new Error("No Root user Id Found!");
|
||||
}
|
||||
/** @type {import("@/package-shared/types").MYSQL_delegated_user_tables_table_def[]} */ const delegatedTables = await _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_4___default()(`SELECT * FROM datasquirel.delegated_user_tables WHERE delegated_user_id=? AND root_user_id=?`, [
|
||||
String(user.id),
|
||||
String(dbUserId)
|
||||
]);
|
||||
const rootUserDbSchema = (0,_functions_backend_grabUserSchemaData__WEBPACK_IMPORTED_MODULE_0__["default"])({
|
||||
userId: String(dbUserId)
|
||||
});
|
||||
if (!rootUserDbSchema) {
|
||||
throw new Error("Root user schema not found!");
|
||||
}
|
||||
/** @type {import("@/package-shared/types").DSQL_DatabaseSchemaType[]} */ const filteredDbSchema = [];
|
||||
delegatedTables.forEach((tblObj)=>{
|
||||
const existingDbIndex = filteredDbSchema.findIndex((db)=>db.dbSlug === tblObj.database);
|
||||
/** @type {import("@/package-shared/types").DSQL_DatabaseSchemaType | undefined} */ const targetDb = rootUserDbSchema.find((db)=>db.dbSlug === tblObj.database);
|
||||
if (targetDb) {
|
||||
/** @type {import("@/package-shared/types").DSQL_DatabaseSchemaType} */ const finalDb = filteredDbSchema[existingDbIndex] ? filteredDbSchema[existingDbIndex] : {
|
||||
...targetDb,
|
||||
tables: []
|
||||
};
|
||||
const targetDbTbls = lodash__WEBPACK_IMPORTED_MODULE_3___default().cloneDeep(targetDb.tables);
|
||||
const targetTable = targetDbTbls.find((tbl)=>tbl.tableName === tblObj.table);
|
||||
if (targetTable && filteredDbSchema[existingDbIndex]) {
|
||||
filteredDbSchema[existingDbIndex] = {
|
||||
...finalDb,
|
||||
tables: [
|
||||
...filteredDbSchema[existingDbIndex].tables,
|
||||
targetTable,
|
||||
]
|
||||
};
|
||||
} else if (targetTable && !filteredDbSchema[existingDbIndex]) {
|
||||
filteredDbSchema.push({
|
||||
...targetDb,
|
||||
tables: [
|
||||
targetTable
|
||||
]
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
////////////////////////////////////////
|
||||
res.json({
|
||||
success: true,
|
||||
payload: filteredDbSchema
|
||||
});
|
||||
} catch (/** @type {any} */ error) {
|
||||
console.log("ERROR:", error.message);
|
||||
////////////////////////////////////////
|
||||
_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1___default()({
|
||||
component: "/api/get-authorized-databases",
|
||||
message: error.message,
|
||||
user: user
|
||||
});
|
||||
res.json({
|
||||
success: false,
|
||||
msg: error.message
|
||||
});
|
||||
////////////////////////////////////////
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// 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, [5425,2224,2163,6825,8164], () => (__webpack_exec__(7840)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
File diff suppressed because one or more lines are too long
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user