This commit is contained in:
Benjamin Toby 2024-12-17 18:39:50 +01:00
parent 4b8e8de71f
commit a2ba913340
5 changed files with 16 additions and 10 deletions

View File

@ -4,7 +4,7 @@ const fs = require("fs");
const decrypt = require("../dsql/decrypt"); const decrypt = require("../dsql/decrypt");
/** @type {import("../../types").CheckApiCredentialsFn} */ /** @type {import("../../types").CheckApiCredentialsFn} */
const grabApiCred = ({ key, database, table, user_id }) => { const grabApiCred = ({ key, database, table, user_id, media }) => {
if (!key) return null; if (!key) return null;
if (!user_id) return null; if (!user_id) return null;
@ -27,6 +27,8 @@ const grabApiCred = ({ key, database, table, user_id }) => {
if (!isApiKeyValid) return null; if (!isApiKeyValid) return null;
if (!ApiObject.target_database) return ApiObject; if (!ApiObject.target_database) return ApiObject;
if (media) return ApiObject;
if (!database && ApiObject.target_database) return null; if (!database && ApiObject.target_database) return null;
const isDatabaseAllowed = ApiObject.target_database const isDatabaseAllowed = ApiObject.target_database
?.split(",") ?.split(",")
@ -41,7 +43,7 @@ const grabApiCred = ({ key, database, table, user_id }) => {
return null; return null;
} catch (/** @type {any} */ error) { } catch (/** @type {any} */ error) {
console.log(`api-cred ERROR: ${error.message}`); console.log(`api-cred ERROR: ${error.message}`);
return null; return { error: `api-cred ERROR: ${error.message}` };
} }
}; };

View File

@ -172,7 +172,7 @@ function sqlGenerator({ tableName, genObject }) {
return str; return str;
})(); })();
if (sqlSearhString) { if (sqlSearhString?.[0] && sqlSearhString.find((str) => str)) {
const stringOperator = genObject?.searchOperator || "AND"; const stringOperator = genObject?.searchOperator || "AND";
queryString += ` WHERE ${sqlSearhString.join(` ${stringOperator} `)} `; queryString += ` WHERE ${sqlSearhString.join(` ${stringOperator} `)} `;
} }

View File

@ -864,12 +864,13 @@ export interface MYSQL_delegated_user_tables_table_def {
date_updated_timestamp?: string; date_updated_timestamp?: string;
} }
export type ApiKeyObject = { export type ApiKeyObject = {
user_id: string | number; user_id?: string | number;
full_access?: boolean; full_access?: boolean;
sign: string; sign?: string;
date_code: number; date_code?: number;
target_database?: string; target_database?: string;
target_table?: string; target_table?: string;
error?: string;
}; };
export type AddApiKeyRequestBody = { export type AddApiKeyRequestBody = {
api_key_name: string; api_key_name: string;
@ -884,6 +885,7 @@ export type CheckApiCredentialsFnParam = {
database?: string; database?: string;
table?: string; table?: string;
user_id?: string | number; user_id?: string | number;
media?: boolean;
}; };
export type FetchApiFn = (url: string, options?: FetchApiOptions, csrf?: boolean) => Promise<any>; export type FetchApiFn = (url: string, options?: FetchApiOptions, csrf?: boolean) => Promise<any>;
export type FetchApiOptions = RequestInit & { export type FetchApiOptions = RequestInit & {

View File

@ -1020,12 +1020,13 @@ export interface MYSQL_delegated_user_tables_table_def {
} }
export type ApiKeyObject = { export type ApiKeyObject = {
user_id: string | number; user_id?: string | number;
full_access?: boolean; full_access?: boolean;
sign: string; sign?: string;
date_code: number; date_code?: number;
target_database?: string; target_database?: string;
target_table?: string; target_table?: string;
error?: string;
}; };
export type AddApiKeyRequestBody = { export type AddApiKeyRequestBody = {
@ -1044,6 +1045,7 @@ export type CheckApiCredentialsFnParam = {
database?: string; database?: string;
table?: string; table?: string;
user_id?: string | number; user_id?: string | number;
media?: boolean;
}; };
export type FetchApiFn = ( export type FetchApiFn = (

View File

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