dsql-admin/dsql-app/.local_dist/server/pages/api/media/getPrivateMedia.js
2024-11-06 13:57:20 +01:00

163 lines
4.9 KiB
JavaScript

"use strict";
(() => {
var exports = {};
exports.id = 3876;
exports.ids = [3876];
exports.modules = {
/***/ 9538:
/***/ ((module) => {
module.exports = require("datasquirel");
/***/ }),
/***/ 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");
/***/ }),
/***/ 1635:
/***/ ((__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
* ==============================================================================
*/ const fs = __webpack_require__(7147);
const datasquirel = __webpack_require__(9538);
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/**
* addPrivateMedia API handler
* ==============================================================================
* @type {import("next").NextApiHandler} - Next API handler
*/ async function handler(req, res) {
/**
* Check method
* =========================================
* @description Check if the request method is correct
*/ if (req.method !== "POST") {
return res.json({
success: false,
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"
});
}
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* Send Response
* =========================================
* @description Send a response to the client
*/ try {
/**
* Grab request data
* =========================================
* @description Grab data from the request
*/ const filePath = JSON.parse(req.body).path.replace(/ /g, "").replace(/\.\./g, "");
if (filePath?.match(/\.\./)) {
return res.json({
success: false,
msg: "Error!",
error: "Invalid url"
});
}
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* Handle request logic here
*/ const rootFolder = `${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${user.id.toString().replace(/\//g, "")}`;
const rootPath = filePath.replace(/\@/, rootFolder);
const fileStream = fs.createReadStream(rootPath);
/**
* Response data
*/ fileStream.pipe(res);
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
} catch (/** @type {any} */ error) {
/**
* Handle error
* =========================================
* @description Handle errors that occur during
* the request
*/ console.log("ERROR in getPrivateMedia api route:", error.message);
res.json({
success: false,
msg: "Error!",
error: error
});
}
}
/***/ })
};
;
// 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,6825], () => (__webpack_exec__(1635)));
module.exports = __webpack_exports__;
})();