This commit is contained in:
Benjamin Toby
2024-11-27 12:23:44 +01:00
parent d13ba5057b
commit 551f4ec130
271 changed files with 562 additions and 512 deletions
+3 -1
View File
@@ -10,14 +10,16 @@ exports.modules = {
const fs = __webpack_require__(7147);
const decrypt = __webpack_require__(5425);
/** @type {import("../../types").CheckApiCredentialsFn} */ const grabApiCred = ({ key , database , table })=>{
/** @type {import("../../types").CheckApiCredentialsFn} */ const grabApiCred = ({ key , database , table , user_id })=>{
if (!key) return null;
if (!user_id) return null;
try {
const allowedKeysPath = process.env.DSQL_API_KEYS_PATH;
if (!allowedKeysPath) throw new Error("process.env.DSQL_API_KEYS_PATH variable not found");
const ApiJSON = decrypt(key);
/** @type {import("../../types").ApiKeyObject} */ const ApiObject = JSON.parse(ApiJSON || "");
const isApiKeyValid = fs.existsSync(`${allowedKeysPath}/${ApiObject.sign}`);
if (String(ApiObject.user_id) !== String(user_id)) return null;
if (!isApiKeyValid) return null;
if (!ApiObject.target_database) return ApiObject;
if (!database && ApiObject.target_database) return null;