This commit is contained in:
Benjamin Toby 2024-11-06 12:58:41 +01:00
parent 2c2ae5de0d
commit 880a74dbcb
6 changed files with 65 additions and 12 deletions

View File

@ -5,6 +5,8 @@ const decrypt = require("./decrypt");
/** @type {import("../../types").CheckApiCredentialsFn} */ /** @type {import("../../types").CheckApiCredentialsFn} */
const grabApiCred = ({ key, database, table }) => { const grabApiCred = ({ key, database, table }) => {
if (!key) return null;
try { try {
const allowedKeysPath = process.env.DSQL_API_KEYS_PATH; const allowedKeysPath = process.env.DSQL_API_KEYS_PATH;

View File

@ -2,7 +2,7 @@
const { IncomingMessage } = require("http"); const { IncomingMessage } = require("http");
const decrypt = require("./decrypt"); const decrypt = require("./decrypt");
const parseCookies = require("../../../utils/functions/parseCookies"); const parseCookies = require("../../utils/backend/parseCookies");
/** /**
* @async * @async

View File

@ -1092,7 +1092,7 @@ export type CheckApiCredentialsFn = (
param: CheckApiCredentialsFnParam param: CheckApiCredentialsFnParam
) => ApiKeyObject | null | undefined; ) => ApiKeyObject | null | undefined;
export type CheckApiCredentialsFnParam = { export type CheckApiCredentialsFnParam = {
key: string; key?: string;
database?: string; database?: string;
table?: string; table?: string;
}; };

View File

@ -3,15 +3,6 @@
const fs = require("fs"); const fs = require("fs");
const path = require("path"); const path = require("path");
// const mysql = require("mysql");
// const NO_DB = mysql.createConnection({
// host: process.env.DSQL_DB_HOST,
// user: process.env.DSQL_DB_USERNAME,
// password: process.env.DSQL_DB_PASSWORD,
// charset: "utf8mb4",
// });
const mysql = require("serverless-mysql"); const mysql = require("serverless-mysql");
const SSL_DIR = const SSL_DIR =

View File

@ -0,0 +1,60 @@
// @ts-check
/**
* ==============================================================================
* Imports
* ==============================================================================
*/
const http = require("http");
/**
* Parse request cookies
* ==============================================================================
*
* @description This function takes in a request object and returns the cookies as a JS object
*
* @async
*
* @param {object} params - main params object
* @param {http.IncomingMessage} params.request - HTTPS request object
*
* @returns {any | null}
*/
module.exports = function ({ request }) {
/**
* Check inputs
*
* @description Check inputs
*/
/** @type {string | undefined} */
const cookieString = request.headers.cookie;
if (!cookieString || typeof cookieString !== "string") {
return null;
}
/** @type {string[]} */
const cookieSplitArray = cookieString.split(";");
/** @type {*} */
let cookieObject = {};
cookieSplitArray.forEach((keyValueString) => {
const [key, value] = keyValueString.split("=");
if (key && typeof key == "string") {
cookieObject[key.replace(/^ +| +$/, "")] =
value && typeof value == "string"
? value.replace(/^ +| +$/, "")
: null;
}
});
/**
* Make https request
*
* @description make a request to datasquirel.com
*/
return cookieObject;
};

View File

@ -1,6 +1,6 @@
{ {
"name": "datasquirel", "name": "datasquirel",
"version": "2.4.0", "version": "2.4.1",
"description": "Cloud-based SQL data management tool", "description": "Cloud-based SQL data management tool",
"main": "index.js", "main": "index.js",
"bin": { "bin": {