This commit is contained in:
Benjamin Toby
2024-12-05 08:03:33 +01:00
parent 9686a22c96
commit 3ffd2d6777
821 changed files with 3251 additions and 91996 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -1,163 +1 @@
"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__;
})();
"use strict";(()=>{var e={};e.id=2127,e.ids=[2127],e.modules={28187:e=>{e.exports=require("@moduletrace/datasquirel")},75600:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},9973:e=>{e.exports=require("serverless-mysql")},79428:e=>{e.exports=require("buffer")},55511:e=>{e.exports=require("crypto")},29021:e=>{e.exports=require("fs")},81630:e=>{e.exports=require("http")},96762:(e,r)=>{Object.defineProperty(r,"M",{enumerable:!0,get:function(){return function e(r,t){return t in r?r[t]:"then"in r&&"function"==typeof r.then?r.then(r=>e(r,t)):"function"==typeof r&&"default"===t?r:void 0}}})},97243:(e,r,t)=>{t.r(r),t.d(r,{config:()=>d,default:()=>p,routeModule:()=>f});var s={};t.r(s),t.d(s,{default:()=>l});var n=t(89947),a=t(2706),i=t(96762),o=t(6420),u=t.n(o);let c=t(29021);async function l(e,r){if("POST"!==e.method)return r.json({success:!1,msg:"Failed!"});let t=await u()(e,r,!0);if(!t)return r.json({success:!1,msg:"Unauthorized"});try{let s=JSON.parse(e.body).path.replace(/ /g,"").replace(/\.\./g,"");if(s?.match(/\.\./))return r.json({success:!1,msg:"Error!",error:"Invalid url"});let n=`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${t.id.toString().replace(/\//g,"")}`,a=s.replace(/\@/,n);c.createReadStream(a).pipe(r)}catch(e){console.log("ERROR in getPrivateMedia api route:",e.message),r.json({success:!1,msg:"Error!",error:e})}}t(28187);let p=(0,i.M)(s,"default"),d=(0,i.M)(s,"config"),f=new n.PagesAPIRouteModule({definition:{kind:a.A.PAGES_API,page:"/api/media/getPrivateMedia",pathname:"/api/media/getPrivateMedia",bundlePath:"",filename:""},userland:s})},6420:(e,r,t)=>{t(81630);let s=t(51348),n=t(72907),a=t(29021);async function i(e,r,t,i){if(!e.cookies?.datasquirelAuthKey?.match(/./))return null;let o=n(e.cookies.datasquirelAuthKey);if(!o)return null;let u=JSON.parse(o);if(!u.csrf_k||t&&!e.headers["x-csrf-auth"]?.match(RegExp(`${u.csrf_k}`)))return null;let c=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!c)return console.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(t&&!a.existsSync(`${c}/${u.csrf_k}`))return null;if(0==u.verification_status&&!t){let e=await s(`SELECT verification_status FROM users WHERE id='${u.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}return u?.date&&Date.now()-u.date>6048e5?null:u}e.exports=i},72907:(e,r,t)=>{let{scryptSync:s,createDecipheriv:n}=t(55511),{Buffer:a}=t(79428);e.exports=e=>{let r=n("aes-192-cbc",s(process.env.DSQL_ENCRYPTION_PASSWORD||"",process.env.DSQL_ENCRYPTION_SALT||"",24),a.alloc(16,0));try{let t=r.update(e,"hex","utf8");return t+=r.final("utf8")}catch(e){return null}}},51348:(e,r,t)=>{let s=t(9973),n=t(21580),a=s({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_USERNAME,password:process.env.DSQL_DB_PASSWORD,database:process.env.DSQL_DB_NAME,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void 0,charset:"utf8mb4",ssl:n()}});async function i(...e){try{let r=await a.query(...e);return await a.end(),JSON.parse(JSON.stringify(r))}catch(e){return console.log("DB Error =>",e),{success:!1,error:e.message}}}e.exports=i},21580:(e,r,t)=>{let s=t(29021);e.exports=function(){let e=process.env.DSQL_SSL_DIR;if(!e?.match(/./))return;let r=`${e}/ca-cert.pem`;if(!s.existsSync(r)){console.log(`${r} does not exist`);return}return{ca:s.readFileSync(`${e}/ca-cert.pem`)}}},2706:(e,r)=>{var t;Object.defineProperty(r,"A",{enumerable:!0,get:function(){return t}}),function(e){e.PAGES="PAGES",e.PAGES_API="PAGES_API",e.APP_PAGE="APP_PAGE",e.APP_ROUTE="APP_ROUTE",e.IMAGE="IMAGE"}(t||(t={}))},89947:(e,r,t)=>{e.exports=t(75600)}};var r=require("../../../webpack-api-runtime.js");r.C(e);var t=r(r.s=97243);module.exports=t})();
File diff suppressed because one or more lines are too long