Updates
This commit is contained in:
@@ -4,7 +4,7 @@ const fs = require("fs");
|
||||
const decrypt = require("../dsql/decrypt");
|
||||
|
||||
/** @type {import("../../types").CheckApiCredentialsFn} */
|
||||
const grabApiCred = ({ key, database, table, user_id }) => {
|
||||
const grabApiCred = ({ key, database, table, user_id, media }) => {
|
||||
if (!key) return null;
|
||||
if (!user_id) return null;
|
||||
|
||||
@@ -27,6 +27,8 @@ const grabApiCred = ({ key, database, table, user_id }) => {
|
||||
|
||||
if (!isApiKeyValid) return null;
|
||||
if (!ApiObject.target_database) return ApiObject;
|
||||
if (media) return ApiObject;
|
||||
|
||||
if (!database && ApiObject.target_database) return null;
|
||||
const isDatabaseAllowed = ApiObject.target_database
|
||||
?.split(",")
|
||||
@@ -41,7 +43,7 @@ const grabApiCred = ({ key, database, table, user_id }) => {
|
||||
return null;
|
||||
} catch (/** @type {any} */ error) {
|
||||
console.log(`api-cred ERROR: ${error.message}`);
|
||||
return null;
|
||||
return { error: `api-cred ERROR: ${error.message}` };
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -4,7 +4,10 @@ const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
const grabAuthDirs = () => {
|
||||
const ROOT_DIR = path.resolve(process.cwd(), "./.tmp");
|
||||
const DSQL_AUTH_DIR = process.env.DSQL_AUTH_DIR;
|
||||
const ROOT_DIR = DSQL_AUTH_DIR?.match(/./)
|
||||
? DSQL_AUTH_DIR
|
||||
: path.resolve(process.cwd(), "./.tmp");
|
||||
const AUTH_DIR = path.join(ROOT_DIR, "logins");
|
||||
|
||||
return { root: ROOT_DIR, auth: AUTH_DIR };
|
||||
|
||||
@@ -7,15 +7,17 @@
|
||||
* @param {string} [params.database]
|
||||
* @param {string | number} [params.userId]
|
||||
*
|
||||
* @returns {{ keyCookieName: string, csrfCookieName: string }}
|
||||
* @returns {{ keyCookieName: string, csrfCookieName: string, oneTimeCodeName: string }}
|
||||
*/
|
||||
module.exports = function getAuthCookieNames(params) {
|
||||
const cookiesPrefix = process.env.DSQL_COOKIES_PREFIX || "dsql_";
|
||||
const cookiesKeyName = process.env.DSQL_COOKIES_KEY_NAME || "key";
|
||||
const cookiesCSRFName = process.env.DSQL_COOKIES_CSRF_NAME || "csrf";
|
||||
const cookieOneTimeCodeName =
|
||||
process.env.DSQL_COOKIES_ONE_TIME_CODE_NAME || "one-time-code";
|
||||
|
||||
const targetDatabase =
|
||||
params?.database ||
|
||||
params?.database?.replace(/^datasquirel_user_\d+_/, "") ||
|
||||
process.env.DSQL_DB_NAME?.replace(/^datasquirel_user_\d+_/, "");
|
||||
|
||||
let keyCookieName = cookiesPrefix;
|
||||
@@ -28,8 +30,14 @@ module.exports = function getAuthCookieNames(params) {
|
||||
if (targetDatabase) csrfCookieName += `${targetDatabase}_`;
|
||||
csrfCookieName += cookiesCSRFName;
|
||||
|
||||
let oneTimeCodeName = cookiesPrefix;
|
||||
if (params?.userId) oneTimeCodeName += `user_${params.userId}_`;
|
||||
if (targetDatabase) oneTimeCodeName += `${targetDatabase}_`;
|
||||
oneTimeCodeName += cookieOneTimeCodeName;
|
||||
|
||||
return {
|
||||
keyCookieName,
|
||||
csrfCookieName,
|
||||
oneTimeCodeName,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
const sanitizeHtml = require("sanitize-html");
|
||||
const sanitizeHtmlOptions = require("../html/sanitizeHtmlOptions");
|
||||
const updateDb = require("./updateDbEntry");
|
||||
const updateDbEntry = require("./updateDbEntry");
|
||||
const _ = require("lodash");
|
||||
const DB_HANDLER = require("../../../utils/backend/global-db/DB_HANDLER");
|
||||
@@ -160,7 +159,9 @@ async function addDbEntry({
|
||||
console.log("DSQL: Encrypted value =>", value);
|
||||
}
|
||||
|
||||
if (targetFieldSchema?.richText) {
|
||||
const htmlRegex = /<[^>]+>/g;
|
||||
|
||||
if (targetFieldSchema?.richText || String(value).match(htmlRegex)) {
|
||||
value = sanitizeHtml(value, sanitizeHtmlOptions);
|
||||
}
|
||||
|
||||
|
||||
@@ -98,7 +98,9 @@ async function updateDbEntry({
|
||||
|
||||
if (value == null || value == undefined) continue;
|
||||
|
||||
if (targetFieldSchema?.richText) {
|
||||
const htmlRegex = /<[^>]+>/g;
|
||||
|
||||
if (targetFieldSchema?.richText || String(value).match(htmlRegex)) {
|
||||
value = sanitizeHtml(value, sanitizeHtmlOptions);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ const path = require("path");
|
||||
* @param {string | number} params.userId
|
||||
* @returns {import("../../types").DSQL_DatabaseSchemaType[] | null}
|
||||
*/
|
||||
export default function grabUserSchemaData({ userId }) {
|
||||
module.exports = function grabUserSchemaData({ userId }) {
|
||||
try {
|
||||
const userSchemaFilePath = path.resolve(
|
||||
process.cwd(),
|
||||
@@ -36,7 +36,7 @@ export default function grabUserSchemaData({ userId }) {
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
|
||||
@@ -18,7 +18,7 @@ const path = require("path");
|
||||
* @param {import("../../types").DSQL_DatabaseSchemaType[]} params.schemaData
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export default function setUserSchemaData({ userId, schemaData }) {
|
||||
module.exports = function setUserSchemaData({ userId, schemaData }) {
|
||||
try {
|
||||
const userSchemaFilePath = path.resolve(
|
||||
process.cwd(),
|
||||
@@ -39,7 +39,7 @@ export default function setUserSchemaData({ userId, schemaData }) {
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
|
||||
Reference in New Issue
Block a user