Updates
This commit is contained in:
@@ -0,0 +1,281 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 7503;
|
||||
exports.ids = [7503];
|
||||
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");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 6113:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("crypto");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 7147:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("fs");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 1017:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("path");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 5425:
|
||||
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
||||
|
||||
// @ts-check
|
||||
|
||||
const { scryptSync , createDecipheriv } = __webpack_require__(6113);
|
||||
const { Buffer } = __webpack_require__(4300);
|
||||
/**
|
||||
* @param {string} encryptedString
|
||||
* @returns {string | null}
|
||||
*/ const decrypt = (encryptedString)=>{
|
||||
const algorithm = "aes-192-cbc";
|
||||
const password = process.env.DSQL_ENCRYPTION_PASSWORD || "";
|
||||
const salt = process.env.DSQL_ENCRYPTION_SALT || "";
|
||||
let key = scryptSync(password, salt, 24);
|
||||
let iv = Buffer.alloc(16, 0);
|
||||
// @ts-ignore
|
||||
const decipher = createDecipheriv(algorithm, key, iv);
|
||||
try {
|
||||
let decrypted = decipher.update(encryptedString, "hex", "utf8");
|
||||
decrypted += decipher.final("utf8");
|
||||
return decrypted;
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
module.exports = decrypt;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 7674:
|
||||
/***/ ((__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 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 _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_functions_backend_db_deleteDbEntry__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(6147);
|
||||
/* harmony import */ var _package_shared_functions_backend_db_deleteDbEntry__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_db_deleteDbEntry__WEBPACK_IMPORTED_MODULE_2__);
|
||||
/* harmony import */ var _package_shared_functions_backend_decrypt__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(5425);
|
||||
/* harmony import */ var _package_shared_functions_backend_decrypt__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_decrypt__WEBPACK_IMPORTED_MODULE_3__);
|
||||
/* harmony import */ var _functions_backend_fsWriteImageToDiskFromBase64__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(5910);
|
||||
/* harmony import */ var _functions_backend_fsWriteImageToDiskFromBase64__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_fsWriteImageToDiskFromBase64__WEBPACK_IMPORTED_MODULE_4__);
|
||||
/* harmony import */ var _functions_backend_grabPaths__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(6715);
|
||||
/* harmony import */ var _functions_backend_grabPaths__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_grabPaths__WEBPACK_IMPORTED_MODULE_5__);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(2163);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_6__);
|
||||
/* harmony import */ var _package_shared_functions_backend_api_cred__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(1007);
|
||||
/* harmony import */ var _package_shared_functions_backend_api_cred__WEBPACK_IMPORTED_MODULE_7___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_api_cred__WEBPACK_IMPORTED_MODULE_7__);
|
||||
// @ts-check
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/ const fs = __webpack_require__(7147);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/** ****************************************************************************** */ const config = {
|
||||
api: {
|
||||
bodyParser: {
|
||||
sizeLimit: "50mb"
|
||||
}
|
||||
}
|
||||
};
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** @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!"
|
||||
});
|
||||
/**
|
||||
* Send Response
|
||||
*
|
||||
* @description Send a boolean response
|
||||
*/ let results;
|
||||
try {
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const authorization = req.headers.authorization;
|
||||
if (!authorization) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Unauthorized"
|
||||
});
|
||||
}
|
||||
const apiCred = _package_shared_functions_backend_api_cred__WEBPACK_IMPORTED_MODULE_7___default()({
|
||||
key: authorization,
|
||||
user_id: String(req.query.user_id)
|
||||
});
|
||||
if (!apiCred?.user_id) {
|
||||
throw new Error("Api Credentials invalid!");
|
||||
}
|
||||
const { user_id , full_access } = apiCred;
|
||||
if (!full_access) return res.json({
|
||||
success: false,
|
||||
msg: "Unauthorized"
|
||||
});
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ let { fileData , fileName , mimeType , folder , isPrivate } = req.body;
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
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!");
|
||||
}
|
||||
if (folder) {
|
||||
const folderPath = path__WEBPACK_IMPORTED_MODULE_0___default().join(STATIC_ROOT, `images/user-images/user-${user_id}/${folder?.toString().replace(/\.\./g, "")}`);
|
||||
const folderExists = fs.existsSync(folderPath);
|
||||
if (!folderExists) {
|
||||
fs.mkdirSync(folderPath, {
|
||||
recursive: true
|
||||
});
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Input Validation
|
||||
*
|
||||
* @description Input Validation
|
||||
*/ const grabedPaths = _functions_backend_grabPaths__WEBPACK_IMPORTED_MODULE_5___default()({
|
||||
folder: folder,
|
||||
isPrivate: isPrivate,
|
||||
user: apiCred
|
||||
});
|
||||
if (!grabedPaths) {
|
||||
throw new Error("Couldn't Grab Image URLs");
|
||||
}
|
||||
const { fileRootPath , urlRootPath } = grabedPaths;
|
||||
const extension = (()=>{
|
||||
if (mimeType?.match(/csv/i)) return ".csv";
|
||||
if (mimeType?.match(/pdf/i)) return ".pdf";
|
||||
if (mimeType?.match(/xlsx/)) return ".xlsx";
|
||||
if (mimeType?.match(/json/i)) return ".json";
|
||||
return ".txt";
|
||||
})();
|
||||
const urlPath = urlRootPath + fileName + extension;
|
||||
const writePath = fileRootPath + fileName + extension;
|
||||
fs.writeFileSync(writePath, fileData, "base64");
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
const removeDuplicateMedia = await _package_shared_functions_backend_db_deleteDbEntry__WEBPACK_IMPORTED_MODULE_2___default()({
|
||||
dbFullName: "datasquirel",
|
||||
tableName: "user_media",
|
||||
identifierColumnName: "media_url",
|
||||
identifierValue: urlPath
|
||||
});
|
||||
let newMediaEntry = await _package_shared_functions_backend_db_addDbEntry__WEBPACK_IMPORTED_MODULE_1___default()({
|
||||
dbFullName: "datasquirel",
|
||||
tableName: "user_media",
|
||||
data: {
|
||||
user_id: user_id,
|
||||
media_name: fileName,
|
||||
media_url: urlPath,
|
||||
media_thumbnail_url: urlPath,
|
||||
folder: folder ? folder : "",
|
||||
media_type: "file",
|
||||
private: isPrivate ? "1" : null
|
||||
}
|
||||
});
|
||||
////////////////////////////////////////
|
||||
res.json({
|
||||
success: true,
|
||||
payload: {
|
||||
urlPath
|
||||
}
|
||||
});
|
||||
////////////////////////////////////////
|
||||
} catch (/** @type {any} */ error) {
|
||||
////////////////////////////////////////
|
||||
console.log("File write error:", error);
|
||||
_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_6___default()({
|
||||
component: "/api/query/add-file/main-catch-error",
|
||||
message: error.message
|
||||
});
|
||||
res.json({
|
||||
success: false,
|
||||
msg: "Add File Error!",
|
||||
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, [2224,2163,3017,3403,7547,5886,5338,1007,6147,6715,5910], () => (__webpack_exec__(7674)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,269 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 8494;
|
||||
exports.ids = [8494];
|
||||
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");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 6113:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("crypto");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 7147:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("fs");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 1017:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("path");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 5425:
|
||||
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
||||
|
||||
// @ts-check
|
||||
|
||||
const { scryptSync , createDecipheriv } = __webpack_require__(6113);
|
||||
const { Buffer } = __webpack_require__(4300);
|
||||
/**
|
||||
* @param {string} encryptedString
|
||||
* @returns {string | null}
|
||||
*/ const decrypt = (encryptedString)=>{
|
||||
const algorithm = "aes-192-cbc";
|
||||
const password = process.env.DSQL_ENCRYPTION_PASSWORD || "";
|
||||
const salt = process.env.DSQL_ENCRYPTION_SALT || "";
|
||||
let key = scryptSync(password, salt, 24);
|
||||
let iv = Buffer.alloc(16, 0);
|
||||
// @ts-ignore
|
||||
const decipher = createDecipheriv(algorithm, key, iv);
|
||||
try {
|
||||
let decrypted = decipher.update(encryptedString, "hex", "utf8");
|
||||
decrypted += decipher.final("utf8");
|
||||
return decrypted;
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
module.exports = decrypt;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 441:
|
||||
/***/ ((__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 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 _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_functions_backend_db_deleteDbEntry__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(6147);
|
||||
/* harmony import */ var _package_shared_functions_backend_db_deleteDbEntry__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_db_deleteDbEntry__WEBPACK_IMPORTED_MODULE_2__);
|
||||
/* harmony import */ var _package_shared_functions_backend_decrypt__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(5425);
|
||||
/* harmony import */ var _package_shared_functions_backend_decrypt__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_decrypt__WEBPACK_IMPORTED_MODULE_3__);
|
||||
/* harmony import */ var _functions_backend_fsWriteImageToDiskFromBase64__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(5910);
|
||||
/* harmony import */ var _functions_backend_fsWriteImageToDiskFromBase64__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_fsWriteImageToDiskFromBase64__WEBPACK_IMPORTED_MODULE_4__);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(2163);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_5__);
|
||||
/* harmony import */ var _package_shared_functions_backend_api_cred__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(1007);
|
||||
/* harmony import */ var _package_shared_functions_backend_api_cred__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_api_cred__WEBPACK_IMPORTED_MODULE_6__);
|
||||
// @ts-check
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/ const fs = __webpack_require__(7147);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/** ****************************************************************************** */ const config = {
|
||||
api: {
|
||||
bodyParser: {
|
||||
sizeLimit: "50mb"
|
||||
}
|
||||
}
|
||||
};
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** @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!"
|
||||
});
|
||||
/**
|
||||
* Send Response
|
||||
*
|
||||
* @description Send a boolean response
|
||||
*/ let results;
|
||||
try {
|
||||
const authorization = req.headers.authorization;
|
||||
if (!authorization) throw new Error("No Authorization Found!");
|
||||
const apiCred = _package_shared_functions_backend_api_cred__WEBPACK_IMPORTED_MODULE_6___default()({
|
||||
key: authorization,
|
||||
user_id: String(req.query.user_id)
|
||||
});
|
||||
if (!apiCred?.user_id) {
|
||||
throw new Error("Api Credentials invalid!");
|
||||
}
|
||||
const { user_id , full_access } = apiCred;
|
||||
if (!full_access) return res.json({
|
||||
success: false,
|
||||
msg: "Unauthorized"
|
||||
});
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ let { imageData , imageName , mimeType , thumbnailSize , folder , isPrivate , } = req.body;
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
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!");
|
||||
}
|
||||
if (folder) {
|
||||
const folderPath = path__WEBPACK_IMPORTED_MODULE_0___default().join(STATIC_ROOT, `images/user-images/user-${user_id}/${folder}`);
|
||||
const folderExists = fs.existsSync(folderPath);
|
||||
if (!folderExists) {
|
||||
fs.mkdirSync(folderPath, {
|
||||
recursive: true
|
||||
});
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Input Validation
|
||||
*
|
||||
* @description Input Validation
|
||||
*/ const imageType = (()=>{
|
||||
if (mimeType?.match(/jpeg/i)) return "jpeg";
|
||||
if (mimeType?.match(/png/i)) return "png";
|
||||
if (mimeType?.match(/webp/i)) return "webp";
|
||||
if (mimeType?.match(/svg/i)) return "svg";
|
||||
return "jpg";
|
||||
})();
|
||||
const writeImage = await _functions_backend_fsWriteImageToDiskFromBase64__WEBPACK_IMPORTED_MODULE_4___default()({
|
||||
imageName: imageName,
|
||||
imageSourceBase64: imageData,
|
||||
user: {
|
||||
id: user_id
|
||||
},
|
||||
mimeType: imageType,
|
||||
thumbnailSize: thumbnailSize,
|
||||
folder,
|
||||
isPrivate
|
||||
});
|
||||
if (!writeImage) throw new Error("Write Image Failed in add-media API route");
|
||||
const { urlPath , urlThumbnailPath } = writeImage;
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
const removeDuplicateMedia = await _package_shared_functions_backend_db_deleteDbEntry__WEBPACK_IMPORTED_MODULE_2___default()({
|
||||
dbFullName: "datasquirel",
|
||||
tableName: "user_media",
|
||||
identifierColumnName: "media_url",
|
||||
identifierValue: urlPath
|
||||
});
|
||||
let newMediaEntry = await _package_shared_functions_backend_db_addDbEntry__WEBPACK_IMPORTED_MODULE_1___default()({
|
||||
dbFullName: "datasquirel",
|
||||
tableName: "user_media",
|
||||
data: {
|
||||
user_id: user_id,
|
||||
media_name: imageName,
|
||||
media_url: urlPath,
|
||||
media_thumbnail_url: urlThumbnailPath,
|
||||
folder: folder ? folder : ""
|
||||
}
|
||||
});
|
||||
////////////////////////////////////////
|
||||
res.json({
|
||||
success: true,
|
||||
payload: {
|
||||
urlPath,
|
||||
urlThumbnailPath
|
||||
}
|
||||
});
|
||||
////////////////////////////////////////
|
||||
} catch (/** @type {any} */ error) {
|
||||
////////////////////////////////////////
|
||||
_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_5___default()({
|
||||
component: "/api/query/add-image/main-catch-error",
|
||||
message: error.message,
|
||||
user: {}
|
||||
});
|
||||
res.json({
|
||||
success: false,
|
||||
msg: "Add Image Error!",
|
||||
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, [2224,2163,3017,3403,7547,5886,5338,1007,6147,6715,5910], () => (__webpack_exec__(441)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,246 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 9244;
|
||||
exports.ids = [9244];
|
||||
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");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 5425:
|
||||
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
||||
|
||||
// @ts-check
|
||||
|
||||
const { scryptSync , createDecipheriv } = __webpack_require__(6113);
|
||||
const { Buffer } = __webpack_require__(4300);
|
||||
/**
|
||||
* @param {string} encryptedString
|
||||
* @returns {string | null}
|
||||
*/ const decrypt = (encryptedString)=>{
|
||||
const algorithm = "aes-192-cbc";
|
||||
const password = process.env.DSQL_ENCRYPTION_PASSWORD || "";
|
||||
const salt = process.env.DSQL_ENCRYPTION_SALT || "";
|
||||
let key = scryptSync(password, salt, 24);
|
||||
let iv = Buffer.alloc(16, 0);
|
||||
// @ts-ignore
|
||||
const decipher = createDecipheriv(algorithm, key, iv);
|
||||
try {
|
||||
let decrypted = decipher.update(encryptedString, "hex", "utf8");
|
||||
decrypted += decipher.final("utf8");
|
||||
return decrypted;
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
module.exports = decrypt;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 2169:
|
||||
/***/ ((__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_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 _package_shared_functions_backend_db_deleteDbEntry__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(6147);
|
||||
/* harmony import */ var _package_shared_functions_backend_db_deleteDbEntry__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_db_deleteDbEntry__WEBPACK_IMPORTED_MODULE_1__);
|
||||
/* harmony import */ var _package_shared_functions_backend_decrypt__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(5425);
|
||||
/* harmony import */ var _package_shared_functions_backend_decrypt__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_decrypt__WEBPACK_IMPORTED_MODULE_2__);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(2163);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_3__);
|
||||
/* harmony import */ var _package_shared_functions_backend_api_cred__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(1007);
|
||||
/* harmony import */ var _package_shared_functions_backend_api_cred__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_api_cred__WEBPACK_IMPORTED_MODULE_4__);
|
||||
// @ts-check
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/ const fs = __webpack_require__(7147);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/** ****************************************************************************** */ const config = {
|
||||
api: {
|
||||
bodyParser: {
|
||||
sizeLimit: "50mb"
|
||||
}
|
||||
}
|
||||
};
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** @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!"
|
||||
});
|
||||
/**
|
||||
* Send Response
|
||||
*
|
||||
* @description Send a boolean response
|
||||
*/ let results;
|
||||
try {
|
||||
const authorization = req.headers.authorization;
|
||||
if (!authorization) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Unauthorized"
|
||||
});
|
||||
}
|
||||
const apiCred = _package_shared_functions_backend_api_cred__WEBPACK_IMPORTED_MODULE_4___default()({
|
||||
key: authorization,
|
||||
user_id: String(req.query.user_id)
|
||||
});
|
||||
if (!apiCred?.user_id) {
|
||||
throw new Error("Api Credentials invalid!");
|
||||
}
|
||||
const { user_id , full_access } = apiCred;
|
||||
if (!full_access) return res.json({
|
||||
success: false,
|
||||
msg: "Unauthorized"
|
||||
});
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ let { url } = req.body;
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
const existingMedia = await _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0___default()(`SELECT * FROM user_media WHERE media_url = ?`, [
|
||||
url
|
||||
]);
|
||||
if (!existingMedia?.length) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Media not found!"
|
||||
});
|
||||
}
|
||||
const { id , folder , media_url , media_thumbnail_url , media_type } = existingMedia[0];
|
||||
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!");
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param {string | null | undefined} path
|
||||
* @returns {string}
|
||||
*/ const formPath = (path)=>{
|
||||
if (!path) return "";
|
||||
if (path?.match(/\.\./)) return "";
|
||||
if (path?.match(/^\@/)) {
|
||||
return path.replace(/@\/media\//, `${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${user_id}/media/`);
|
||||
}
|
||||
return path.replace(process.env.DSQL_STATIC_HOST || "", STATIC_ROOT);
|
||||
};
|
||||
const deletePath = formPath(media_url);
|
||||
const deleteThumbnailPath = formPath(media_thumbnail_url);
|
||||
if (!deletePath?.match(/./)) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Invalid path!"
|
||||
});
|
||||
}
|
||||
try {
|
||||
fs.unlinkSync(deletePath);
|
||||
fs.unlinkSync(deleteThumbnailPath);
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
const removeDuplicateMedia = await _package_shared_functions_backend_db_deleteDbEntry__WEBPACK_IMPORTED_MODULE_1___default()({
|
||||
dbFullName: "datasquirel",
|
||||
tableName: "user_media",
|
||||
identifierColumnName: "id",
|
||||
identifierValue: id
|
||||
});
|
||||
////////////////////////////////////////
|
||||
res.json({
|
||||
success: true,
|
||||
payload: {
|
||||
url
|
||||
}
|
||||
});
|
||||
} catch (/** @type {any} */ error) {
|
||||
console.log("File delete error:", error.message);
|
||||
////////////////////////////////////////
|
||||
res.json({
|
||||
success: false,
|
||||
payload: {
|
||||
url
|
||||
},
|
||||
error: error.message
|
||||
});
|
||||
}
|
||||
////////////////////////////////////////
|
||||
} catch (/** @type {any} */ error1) {
|
||||
////////////////////////////////////////
|
||||
console.log("File write error:", error1);
|
||||
_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_3___default()({
|
||||
component: "/api/query/delete-file/main-catch-error",
|
||||
message: error1.message
|
||||
});
|
||||
res.json({
|
||||
success: false,
|
||||
msg: "Delete File Error!",
|
||||
error: error1.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, [2224,2163,3403,1007,6147], () => (__webpack_exec__(2169)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,204 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 7554;
|
||||
exports.ids = [7554];
|
||||
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");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 5425:
|
||||
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
||||
|
||||
// @ts-check
|
||||
|
||||
const { scryptSync , createDecipheriv } = __webpack_require__(6113);
|
||||
const { Buffer } = __webpack_require__(4300);
|
||||
/**
|
||||
* @param {string} encryptedString
|
||||
* @returns {string | null}
|
||||
*/ const decrypt = (encryptedString)=>{
|
||||
const algorithm = "aes-192-cbc";
|
||||
const password = process.env.DSQL_ENCRYPTION_PASSWORD || "";
|
||||
const salt = process.env.DSQL_ENCRYPTION_SALT || "";
|
||||
let key = scryptSync(password, salt, 24);
|
||||
let iv = Buffer.alloc(16, 0);
|
||||
// @ts-ignore
|
||||
const decipher = createDecipheriv(algorithm, key, iv);
|
||||
try {
|
||||
let decrypted = decipher.update(encryptedString, "hex", "utf8");
|
||||
decrypted += decipher.final("utf8");
|
||||
return decrypted;
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
module.exports = decrypt;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 4985:
|
||||
/***/ ((__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 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 _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 _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 _package_shared_functions_backend_api_cred__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(1007);
|
||||
/* harmony import */ var _package_shared_functions_backend_api_cred__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_api_cred__WEBPACK_IMPORTED_MODULE_4__);
|
||||
// @ts-check
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/ const fs = __webpack_require__(7147);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/** ****************************************************************************** */ const config = {
|
||||
api: {
|
||||
bodyParser: {
|
||||
sizeLimit: "100mb"
|
||||
}
|
||||
}
|
||||
};
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** @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!"
|
||||
});
|
||||
/**
|
||||
* Send Response
|
||||
*
|
||||
* @description Send a boolean response
|
||||
*/ let results;
|
||||
try {
|
||||
const authorization = req.headers.authorization;
|
||||
if (!authorization) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Unauthorized"
|
||||
});
|
||||
}
|
||||
const apiCred = _package_shared_functions_backend_api_cred__WEBPACK_IMPORTED_MODULE_4___default()({
|
||||
key: authorization,
|
||||
user_id: String(req.query.user_id)
|
||||
});
|
||||
if (!apiCred?.user_id) {
|
||||
throw new Error("Api Credentials invalid!");
|
||||
}
|
||||
const { user_id , full_access } = apiCred;
|
||||
if (!full_access) return res.json({
|
||||
success: false,
|
||||
msg: "Unauthorized"
|
||||
});
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ let { folder , fileName , downloadType } = req.body;
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
/**
|
||||
* Input Validation
|
||||
*
|
||||
* @description Input Validation
|
||||
*/ const grabedPaths = _functions_backend_grabPaths__WEBPACK_IMPORTED_MODULE_2___default()({
|
||||
folder: folder,
|
||||
isPrivate: true,
|
||||
user: apiCred
|
||||
});
|
||||
if (!grabedPaths) {
|
||||
throw new Error("Couldn't Grab Image URLs");
|
||||
}
|
||||
const { fileRootPath } = grabedPaths;
|
||||
const filePath = path__WEBPACK_IMPORTED_MODULE_0___default().join(fileRootPath, fileName);
|
||||
if (downloadType?.match(/raw/i)) {
|
||||
const fileData = fs.readFileSync(filePath, "utf-8");
|
||||
return res.json({
|
||||
success: true,
|
||||
data: fileData
|
||||
});
|
||||
} else if (downloadType?.match(/base64/i)) {
|
||||
const fileData1 = fs.readFileSync(filePath, "base64");
|
||||
return res.json({
|
||||
success: true,
|
||||
data: fileData1
|
||||
});
|
||||
} else {
|
||||
const fileStream = fs.createReadStream(filePath);
|
||||
fileStream.pipe(res);
|
||||
}
|
||||
////////////////////////////////////////
|
||||
} catch (/** @type {any} */ error) {
|
||||
////////////////////////////////////////
|
||||
console.log("Get Private File Error:", error);
|
||||
_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_3___default()({
|
||||
component: "/api/query/get-private-file/main-catch-error",
|
||||
message: error.message
|
||||
});
|
||||
res.json({
|
||||
success: false,
|
||||
msg: "Get Private File Error!",
|
||||
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, [2163,1007,6715], () => (__webpack_exec__(4985)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
@@ -0,0 +1 @@
|
||||
{"version":1,"files":["../../../../webpack-api-runtime.js","../../../../chunks/2163.js","../../../../chunks/1007.js","../../../../chunks/6715.js","../../../../../package.json","../../../../../../package.json"]}
|
||||
@@ -0,0 +1,207 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 750;
|
||||
exports.ids = [750];
|
||||
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");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 5425:
|
||||
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
||||
|
||||
// @ts-check
|
||||
|
||||
const { scryptSync , createDecipheriv } = __webpack_require__(6113);
|
||||
const { Buffer } = __webpack_require__(4300);
|
||||
/**
|
||||
* @param {string} encryptedString
|
||||
* @returns {string | null}
|
||||
*/ const decrypt = (encryptedString)=>{
|
||||
const algorithm = "aes-192-cbc";
|
||||
const password = process.env.DSQL_ENCRYPTION_PASSWORD || "";
|
||||
const salt = process.env.DSQL_ENCRYPTION_SALT || "";
|
||||
let key = scryptSync(password, salt, 24);
|
||||
let iv = Buffer.alloc(16, 0);
|
||||
// @ts-ignore
|
||||
const decipher = createDecipheriv(algorithm, key, iv);
|
||||
try {
|
||||
let decrypted = decipher.update(encryptedString, "hex", "utf8");
|
||||
decrypted += decipher.final("utf8");
|
||||
return decrypted;
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
module.exports = decrypt;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 7982:
|
||||
/***/ ((__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 _package_shared_functions_backend_api_cred__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(1007);
|
||||
/* harmony import */ var _package_shared_functions_backend_api_cred__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_api_cred__WEBPACK_IMPORTED_MODULE_2__);
|
||||
// @ts-check
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/ const fs = __webpack_require__(7147);
|
||||
const path = __webpack_require__(1017);
|
||||
|
||||
|
||||
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** @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!"
|
||||
});
|
||||
console.log("Getting DB schema");
|
||||
/**
|
||||
* Send Response
|
||||
*
|
||||
* @description Send a boolean response
|
||||
*/ let results;
|
||||
try {
|
||||
/** @type {import("@/package-shared/types").GetSchemaRequestQuery} */ // @ts-ignore
|
||||
const reqQuery = req.query;
|
||||
let { database , table , field } = reqQuery;
|
||||
const authorization = req.headers.authorization;
|
||||
if (!authorization) return res.json({
|
||||
success: false,
|
||||
msg: "Unauthorized"
|
||||
});
|
||||
const apiCred = _package_shared_functions_backend_api_cred__WEBPACK_IMPORTED_MODULE_2___default()({
|
||||
key: authorization,
|
||||
database: database,
|
||||
table: table,
|
||||
user_id: String(req.query.user_id)
|
||||
});
|
||||
if (!apiCred?.user_id) {
|
||||
throw new Error("Api Credentials invalid!");
|
||||
}
|
||||
const { user_id , full_access } = apiCred;
|
||||
if (!full_access) return res.json({
|
||||
success: false,
|
||||
msg: "Unauthorized"
|
||||
});
|
||||
/**
|
||||
* Create new user folder and file
|
||||
*
|
||||
* @description Create new user folder and file
|
||||
*/ try {
|
||||
const dbFullName = database && typeof database == "string" ? `datasquirel_user_${user_id}_${database?.toLowerCase().replace(/[^a-z0-9\_]/g, "")}` : null;
|
||||
/** @type {string} */ const dbSchemaPath = path.join(String(process.env.DSQL_USER_DB_SCHEMA_PATH), `user-${user_id.toString().replace(/\//g, "")}`, "main.json");
|
||||
/** @type {import("@/package-shared/types").DSQL_DatabaseSchemaType[]} */ const dbSchema = JSON.parse(fs.readFileSync(dbSchemaPath, "utf8"));
|
||||
const targetDbSchema = dbFullName ? dbSchema.find((db)=>db.dbFullName == dbFullName) : null;
|
||||
if (table && database && targetDbSchema?.tables?.[0]) {
|
||||
const targetTable = targetDbSchema.tables.find((tbl)=>tbl.tableName == table);
|
||||
if (field && targetTable?.fields?.[0]) {
|
||||
const targetField = targetTable.fields.find((fld)=>fld.fieldName === field);
|
||||
return res.json({
|
||||
success: Boolean(targetField),
|
||||
payload: targetField
|
||||
});
|
||||
} else if (field && !targetTable?.fields?.[0]) {
|
||||
throw new Error("Target Table Not Found!");
|
||||
}
|
||||
return res.json({
|
||||
success: Boolean(targetTable),
|
||||
payload: targetTable
|
||||
});
|
||||
} else if (table && !targetDbSchema?.tables?.[0]) {
|
||||
throw new Error("Target Database Not Found!");
|
||||
}
|
||||
if (database) {
|
||||
res.json({
|
||||
success: Boolean(targetDbSchema),
|
||||
payload: targetDbSchema
|
||||
});
|
||||
} else {
|
||||
res.json({
|
||||
success: true,
|
||||
payload: dbSchema
|
||||
});
|
||||
}
|
||||
////////////////////////////////////////
|
||||
} catch (/** @type {any} */ error) {
|
||||
_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1___default()({
|
||||
component: "/api/query/get-schema/lines-132-142",
|
||||
message: error.message
|
||||
});
|
||||
////////////////////////////////////////
|
||||
res.json({
|
||||
success: false,
|
||||
payload: null,
|
||||
error: error.message
|
||||
});
|
||||
}
|
||||
////////////////////////////////////////
|
||||
} catch (/** @type {any} */ error1) {
|
||||
////////////////////////////////////////
|
||||
_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1___default()({
|
||||
component: "/api/query/get-schema/main-catch-error",
|
||||
message: error1.message
|
||||
});
|
||||
res.json({
|
||||
success: false,
|
||||
payload: null,
|
||||
msg: "Wrong Credentials"
|
||||
});
|
||||
////////////////////////////////////////
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// load runtime
|
||||
var __webpack_require__ = require("../../../../webpack-api-runtime.js");
|
||||
__webpack_require__.C(exports);
|
||||
var __webpack_exec__ = (moduleId) => (__webpack_require__(__webpack_require__.s = moduleId))
|
||||
var __webpack_exports__ = __webpack_require__.X(0, [2163,1007], () => (__webpack_exec__(7982)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
@@ -0,0 +1 @@
|
||||
{"version":1,"files":["../../../../webpack-api-runtime.js","../../../../chunks/2163.js","../../../../chunks/1007.js","../../../../../package.json","../../../../../../package.json"]}
|
||||
@@ -0,0 +1,238 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 6456;
|
||||
exports.ids = [6456];
|
||||
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");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 5687:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("https");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 1017:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("path");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 5830:
|
||||
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
||||
|
||||
__webpack_require__.r(__webpack_exports__);
|
||||
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
||||
/* harmony export */ "default": () => (/* binding */ handler)
|
||||
/* harmony export */ });
|
||||
/* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(6517);
|
||||
/* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(lodash__WEBPACK_IMPORTED_MODULE_0__);
|
||||
/* harmony import */ var _package_shared_functions_backend_db_runQuery__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(8499);
|
||||
/* harmony import */ var _package_shared_functions_backend_db_runQuery__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_db_runQuery__WEBPACK_IMPORTED_MODULE_1__);
|
||||
/* harmony import */ var _package_shared_functions_backend_decrypt__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(5425);
|
||||
/* harmony import */ var _package_shared_functions_backend_decrypt__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_decrypt__WEBPACK_IMPORTED_MODULE_2__);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(2163);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_3__);
|
||||
/* harmony import */ var _package_shared_functions_backend_api_cred__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(1007);
|
||||
/* harmony import */ var _package_shared_functions_backend_api_cred__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_api_cred__WEBPACK_IMPORTED_MODULE_4__);
|
||||
// @ts-check
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/ const fs = __webpack_require__(7147);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** @type {import("next").NextApiHandler} */ async function handler(req, res) {
|
||||
/**
|
||||
* Check method
|
||||
*
|
||||
* @description Check request method and return if invalid
|
||||
*/ if (req.method !== "GET") return res.json({
|
||||
msg: "Failed!"
|
||||
});
|
||||
/**
|
||||
* Send Response
|
||||
*
|
||||
* @description Send a boolean response
|
||||
*/ try {
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ /** @type {import("@/package-shared/types").GetReqQueryObject} */ // @ts-ignore
|
||||
const reqQueryObject = req.query;
|
||||
const { query , db } = reqQueryObject;
|
||||
/** @type {string | undefined } */ const tableName = reqQueryObject?.tableName ? String(reqQueryObject.tableName) : undefined;
|
||||
const authorization = req.headers.authorization;
|
||||
if (!authorization) return res.json({
|
||||
success: false,
|
||||
msg: "Unauthorized"
|
||||
});
|
||||
const apiCred = _package_shared_functions_backend_api_cred__WEBPACK_IMPORTED_MODULE_4___default()({
|
||||
key: authorization,
|
||||
database: db,
|
||||
table: tableName,
|
||||
user_id: String(req.query.user_id)
|
||||
});
|
||||
if (!apiCred?.user_id) {
|
||||
throw new Error("Api Credentials invalid!");
|
||||
}
|
||||
const { user_id } = apiCred;
|
||||
/** @type {string[] | undefined } */ let queryValues;
|
||||
if (reqQueryObject?.queryValues && typeof reqQueryObject?.queryValues === "string") {
|
||||
try {
|
||||
queryValues = JSON.parse(reqQueryObject.queryValues);
|
||||
} catch (error) {}
|
||||
}
|
||||
const dbFullName = `datasquirel_user_${user_id}_${db}`;
|
||||
/**
|
||||
* Input Validation
|
||||
*
|
||||
* @description Input Validation
|
||||
*/ if (typeof query == "string" && (query.match(/^alter|^delete|information_schema|databases|^create/i) || !query.match(/^select/i))) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Wrong Input"
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Create new user folder and file
|
||||
*
|
||||
* @description Create new user folder and file
|
||||
*/ let results;
|
||||
/** @type {import("@/package-shared/types").DSQL_DatabaseSchemaType | undefined} */ let dbSchema;
|
||||
const targetDbSchemaPath = `${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${user_id.toString().replace(/\//g, "")}/main.json`;
|
||||
if (fs.existsSync(targetDbSchemaPath)) {
|
||||
try {
|
||||
dbSchema = JSON.parse(fs.readFileSync(targetDbSchemaPath, "utf8")).filter((/** @type {any} */ db)=>db.dbFullName === dbFullName)[0];
|
||||
} catch (_err) {}
|
||||
}
|
||||
try {
|
||||
let { result , error: error1 } = await _package_shared_functions_backend_db_runQuery__WEBPACK_IMPORTED_MODULE_1___default()({
|
||||
dbFullName: dbFullName,
|
||||
query: query,
|
||||
queryValuesArray: queryValues,
|
||||
readOnly: true,
|
||||
dbSchema,
|
||||
tableName
|
||||
});
|
||||
/** @type {import("@/package-shared/types").DSQL_TableSchemaType | undefined} */ let tableSchema;
|
||||
if (dbSchema) {
|
||||
const targetTable = dbSchema.tables.find((table)=>table.tableName === tableName);
|
||||
if (targetTable) {
|
||||
const clonedTargetTable = lodash__WEBPACK_IMPORTED_MODULE_0___default().cloneDeep(targetTable);
|
||||
delete clonedTargetTable.childTable;
|
||||
delete clonedTargetTable.childTableDbFullName;
|
||||
delete clonedTargetTable.childTableName;
|
||||
delete clonedTargetTable.childrenTables;
|
||||
delete clonedTargetTable.updateData;
|
||||
delete clonedTargetTable.tableNameOld;
|
||||
delete clonedTargetTable.indexes;
|
||||
tableSchema = clonedTargetTable;
|
||||
}
|
||||
}
|
||||
if (error1) throw error1;
|
||||
if (result.error) throw new Error(result.error);
|
||||
results = result;
|
||||
/** @type {import("@/package-shared/types").GetReturn} */ const resObject = {
|
||||
success: true,
|
||||
payload: results,
|
||||
schema: tableName && tableSchema ? tableSchema : undefined
|
||||
};
|
||||
res.json(resObject);
|
||||
////////////////////////////////////////
|
||||
} catch (/** @type {any} */ error2) {
|
||||
////////////////////////////////////////
|
||||
_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_3___default()({
|
||||
component: "/api/query/get/lines-85-94",
|
||||
message: error2.message
|
||||
});
|
||||
res.json({
|
||||
success: false,
|
||||
payload: null,
|
||||
error: error2.message
|
||||
});
|
||||
}
|
||||
////////////////////////////////////////
|
||||
} catch (/** @type {any} */ error3) {
|
||||
////////////////////////////////////////
|
||||
_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_3___default()({
|
||||
component: "/api/query/get/main-catch-error",
|
||||
message: error3.message
|
||||
});
|
||||
res.json({
|
||||
success: false,
|
||||
msg: "Wrong Credentials"
|
||||
});
|
||||
////////////////////////////////////////
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// load runtime
|
||||
var __webpack_require__ = require("../../../../webpack-api-runtime.js");
|
||||
__webpack_require__.C(exports);
|
||||
var __webpack_exec__ = (moduleId) => (__webpack_require__(__webpack_require__.s = moduleId))
|
||||
var __webpack_exports__ = __webpack_require__.X(0, [2224,2163,3017,3403,7547,5886,5338,8326,1007,6147,4733], () => (__webpack_exec__(5830)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,254 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 7430;
|
||||
exports.ids = [7430];
|
||||
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");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 5687:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("https");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 1017:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("path");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 9022:
|
||||
/***/ ((__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 lodash__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(6517);
|
||||
/* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(lodash__WEBPACK_IMPORTED_MODULE_0__);
|
||||
/* harmony import */ var _package_shared_functions_backend_db_runQuery__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(8499);
|
||||
/* harmony import */ var _package_shared_functions_backend_db_runQuery__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_db_runQuery__WEBPACK_IMPORTED_MODULE_1__);
|
||||
/* harmony import */ var _package_shared_functions_backend_decrypt__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(5425);
|
||||
/* harmony import */ var _package_shared_functions_backend_decrypt__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_decrypt__WEBPACK_IMPORTED_MODULE_2__);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(2163);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_3__);
|
||||
/* harmony import */ var _package_shared_functions_backend_api_cred__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(1007);
|
||||
/* harmony import */ var _package_shared_functions_backend_api_cred__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_api_cred__WEBPACK_IMPORTED_MODULE_4__);
|
||||
// @ts-check
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/ const fs = __webpack_require__(7147);
|
||||
const path = __webpack_require__(1017);
|
||||
const { execSync } = __webpack_require__(2081);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/** ****************************************************************************** */ const config = {
|
||||
api: {
|
||||
bodyParser: {
|
||||
sizeLimit: "50mb"
|
||||
}
|
||||
}
|
||||
};
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** @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!"
|
||||
});
|
||||
/**
|
||||
* Send Response
|
||||
*
|
||||
* @description Send a boolean response
|
||||
*/ let results;
|
||||
try {
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ /**
|
||||
* Grab Body
|
||||
*/ let { query , database , tableName , queryValues } = req.body;
|
||||
const authorization = req.headers.authorization;
|
||||
const apiCred = _package_shared_functions_backend_api_cred__WEBPACK_IMPORTED_MODULE_4___default()({
|
||||
key: authorization,
|
||||
database: database,
|
||||
table: tableName,
|
||||
user_id: String(req.query.user_id)
|
||||
});
|
||||
if (!apiCred?.user_id) {
|
||||
throw new Error("Api Credentials invalid!");
|
||||
}
|
||||
const { user_id , full_access } = apiCred;
|
||||
if (!full_access) return res.json({
|
||||
success: false,
|
||||
msg: "Unauthorized"
|
||||
});
|
||||
const dbFullName = `datasquirel_user_${user_id}_${database}`;
|
||||
/**
|
||||
* Input Validation
|
||||
*
|
||||
* @description Input Validation
|
||||
*/ if (typeof query === "string" && query?.match(/^create |^alter |^drop /i)) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Wrong Input"
|
||||
});
|
||||
}
|
||||
if (typeof query === "object" && query?.action?.match(/^create |^alter |^drop /i)) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Wrong Input"
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Grab db Schema
|
||||
*/ /** @type {import("@/package-shared/types").DSQL_DatabaseSchemaType | undefined} */ let dbSchema;
|
||||
const targetDbSchemaPath = `${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${user_id.toString().replace(/\//g, "")}/main.json`;
|
||||
if (fs.existsSync(targetDbSchemaPath)) {
|
||||
try {
|
||||
dbSchema = JSON.parse(fs.readFileSync(targetDbSchemaPath, "utf8")).filter((/** @type {any} */ db)=>db.dbFullName === dbFullName)[0];
|
||||
} catch (_err) {}
|
||||
}
|
||||
/**
|
||||
* Create new user folder and file
|
||||
*
|
||||
* @description Create new user folder and file
|
||||
*/ try {
|
||||
let { result , error } = await _package_shared_functions_backend_db_runQuery__WEBPACK_IMPORTED_MODULE_1___default()({
|
||||
dbFullName: dbFullName,
|
||||
query: query,
|
||||
dbSchema: dbSchema,
|
||||
queryValuesArray: queryValues,
|
||||
tableName
|
||||
});
|
||||
results = result;
|
||||
if (error) throw error;
|
||||
/** @type {import("@/package-shared/types").DSQL_TableSchemaType | undefined} */ let tableSchema;
|
||||
if (dbSchema) {
|
||||
const targetTable = dbSchema.tables.find((table)=>table.tableName === tableName);
|
||||
if (targetTable) {
|
||||
const clonedTargetTable = lodash__WEBPACK_IMPORTED_MODULE_0___default().cloneDeep(targetTable);
|
||||
delete clonedTargetTable.childTable;
|
||||
delete clonedTargetTable.childTableDbFullName;
|
||||
delete clonedTargetTable.childTableName;
|
||||
delete clonedTargetTable.childrenTables;
|
||||
delete clonedTargetTable.updateData;
|
||||
delete clonedTargetTable.tableNameOld;
|
||||
delete clonedTargetTable.indexes;
|
||||
tableSchema = clonedTargetTable;
|
||||
}
|
||||
}
|
||||
res.json({
|
||||
success: true,
|
||||
payload: results,
|
||||
error: error,
|
||||
schema: tableName && tableSchema ? tableSchema : undefined
|
||||
});
|
||||
////////////////////////////////////////
|
||||
} catch (/** @type {any} */ error1) {
|
||||
_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_3___default()({
|
||||
component: "/api/query/post/lines-132-142",
|
||||
message: error1.message
|
||||
});
|
||||
////////////////////////////////////////
|
||||
res.json({
|
||||
success: false,
|
||||
payload: results,
|
||||
error: error1.message
|
||||
});
|
||||
}
|
||||
////////////////////////////////////////
|
||||
} catch (/** @type {any} */ error2) {
|
||||
////////////////////////////////////////
|
||||
_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_3___default()({
|
||||
component: "/api/query/post/main-catch-error",
|
||||
message: error2.message
|
||||
});
|
||||
res.json({
|
||||
success: false,
|
||||
msg: "Wrong Credentials"
|
||||
});
|
||||
////////////////////////////////////////
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// load runtime
|
||||
var __webpack_require__ = require("../../../../webpack-api-runtime.js");
|
||||
__webpack_require__.C(exports);
|
||||
var __webpack_exec__ = (moduleId) => (__webpack_require__(__webpack_require__.s = moduleId))
|
||||
var __webpack_exports__ = __webpack_require__.X(0, [2224,2163,3017,3403,7547,5886,5338,8326,1007,6147,4733], () => (__webpack_exec__(9022)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
File diff suppressed because one or more lines are too long
+194
@@ -0,0 +1,194 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 5473;
|
||||
exports.ids = [5473];
|
||||
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");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 1017:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("path");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 5425:
|
||||
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
||||
|
||||
// @ts-check
|
||||
|
||||
const { scryptSync , createDecipheriv } = __webpack_require__(6113);
|
||||
const { Buffer } = __webpack_require__(4300);
|
||||
/**
|
||||
* @param {string} encryptedString
|
||||
* @returns {string | null}
|
||||
*/ const decrypt = (encryptedString)=>{
|
||||
const algorithm = "aes-192-cbc";
|
||||
const password = process.env.DSQL_ENCRYPTION_PASSWORD || "";
|
||||
const salt = process.env.DSQL_ENCRYPTION_SALT || "";
|
||||
let key = scryptSync(password, salt, 24);
|
||||
let iv = Buffer.alloc(16, 0);
|
||||
// @ts-ignore
|
||||
const decipher = createDecipheriv(algorithm, key, iv);
|
||||
try {
|
||||
let decrypted = decipher.update(encryptedString, "hex", "utf8");
|
||||
decrypted += decipher.final("utf8");
|
||||
return decrypted;
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
module.exports = decrypt;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 4423:
|
||||
/***/ ((__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 child_process__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2081);
|
||||
/* harmony import */ var child_process__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(child_process__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 _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 _package_shared_functions_backend_api_cred__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(1007);
|
||||
/* harmony import */ var _package_shared_functions_backend_api_cred__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_api_cred__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 !== "GET") return res.json({
|
||||
msg: "Failed!"
|
||||
});
|
||||
/**
|
||||
* Send Response
|
||||
*
|
||||
* @description Send a boolean response
|
||||
*/ let results;
|
||||
try {
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const authorization = req.headers.authorization;
|
||||
if (!authorization) return res.json({
|
||||
success: false,
|
||||
msg: "Unauthorized"
|
||||
});
|
||||
const apiCred = _package_shared_functions_backend_api_cred__WEBPACK_IMPORTED_MODULE_3___default()({
|
||||
key: authorization,
|
||||
user_id: String(req.query.user_id)
|
||||
});
|
||||
if (!apiCred?.user_id) {
|
||||
throw new Error("Api Credentials invalid!");
|
||||
}
|
||||
const { user_id , full_access } = apiCred;
|
||||
if (!full_access) return res.json({
|
||||
success: false,
|
||||
msg: "Unauthorized"
|
||||
});
|
||||
/**
|
||||
* Grab the database schema
|
||||
* @note This is only for one database
|
||||
* @type {import("@/package-shared/types").DSQL_DatabaseSchemaType}
|
||||
*/ //@ts-ignore
|
||||
const schema = req.query.schema;
|
||||
/** @type {string} */ const dbSchemaPath = `${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${user_id.toString().replace(/\//g, "")}/main.json`;
|
||||
/** @type {import("@/package-shared/types").DSQL_DatabaseSchemaType[]} */ const dbSchema = JSON.parse(fs.readFileSync(dbSchemaPath, "utf8"));
|
||||
const targetDbSchemaIndex = dbSchema.findIndex((db)=>db.dbFullName == schema?.dbFullName);
|
||||
const targetDbSchema = schema?.dbFullName ? dbSchema.find((db)=>db.dbFullName == schema.dbFullName) : null;
|
||||
if (targetDbSchemaIndex < 0) {
|
||||
return res.json({
|
||||
success: false,
|
||||
payload: null
|
||||
});
|
||||
}
|
||||
dbSchema[targetDbSchemaIndex] = schema;
|
||||
fs.writeFileSync(dbSchemaPath, JSON.stringify(dbSchema, null, 4), "utf8");
|
||||
const targetPath = path.resolve(process.cwd(), "./shell");
|
||||
const dbShellUpdate = (0,child_process__WEBPACK_IMPORTED_MODULE_0__.execSync)(`node createDbFromSchema.js --user ${user_id.toString().replace(/\/| /g, "")} --database ${dbSchema[targetDbSchemaIndex].dbFullName}`, {
|
||||
cwd: targetPath
|
||||
});
|
||||
res.json({
|
||||
success: true,
|
||||
payload: "Success!"
|
||||
});
|
||||
////////////////////////////////////////
|
||||
} catch (/** @type {any} */ error) {
|
||||
////////////////////////////////////////
|
||||
_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_2___default()({
|
||||
component: "/api/query/update-schema-from-single-database/main-catch-error",
|
||||
message: error.message
|
||||
});
|
||||
res.json({
|
||||
success: false,
|
||||
payload: null,
|
||||
msg: "Something went wrong"
|
||||
});
|
||||
////////////////////////////////////////
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// 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,1007], () => (__webpack_exec__(4423)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":1,"files":["../../../../webpack-api-runtime.js","../../../../chunks/2163.js","../../../../chunks/1007.js","../../../../../package.json","../../../../../../package.json","../../../../../../shell/mariadb-users/handleGrants.js","../../../../../../shell/mariadb-users/refreshUsersAndGrants.js","../../../../../../shell/mariadb-users/resetSQLPasswords.js","../../../../../../shell/mariadb-users/users/create-user.js","../../../../../../shell/mariadb-users/users/update-user.js","../../../../../../shell/mariadb-users/users/new-user.json","../../../../../../shell/mariadb-users/users/update-user.json","../../../../../../shell/checkDb.js","../../../../../../shell/createDbFromSchema.js","../../../../../../shell/grantFullPriviledges.js","../../../../../../shell/lessWatch.js","../../../../../../shell/readImage.js","../../../../../../shell/encodingUpdate.js","../../../../../../shell/deploy.js","../../../../../../shell/recoverMainJsonFromDb.js","../../../../../../shell/resetSQLCredentials.js","../../../../../../shell/resetSQLCredentialsPasswords.js","../../../../../../shell/tailwindWatch.js","../../../../../../shell/test-external-server.js","../../../../../../shell/setSQLCredentials.js","../../../../../../shell/test.js","../../../../../../shell/testSQLEscape.js","../../../../../../shell/updateChildrenTablesOnDb.js","../../../../../../shell/updateDateTimestamps.js","../../../../../../shell/updateSSLUsers.js","../../../../../../shell/updateDbSlugsForTableRecords.js","../../../../../../shell/utils/createTable.js","../../../../../../shell/utils/generateColumnDescription.js","../../../../../../shell/utils/dbHandler.js","../../../../../../shell/utils/noDatabaseDbHandler.js","../../../../../../shell/utils/supplementTable.js","../../../../../../shell/utils/updateTable.js","../../../../../../shell/utils/varDatabaseDbHandler.js","../../../../../../shell/functions/jsonToBase64.js"]}
|
||||
Reference in New Issue
Block a user