Add Remote API

This commit is contained in:
Benjamin Toby 2024-11-06 07:37:42 +01:00
parent 190598aa3f
commit 6c78cae127
8 changed files with 55 additions and 35 deletions

View File

@ -1,22 +1,10 @@
/**
* ==============================================================================
* Imports
* ==============================================================================
*/
import imageInputFileToBase64 from "./imageInputFileToBase64"; import imageInputFileToBase64 from "./imageInputFileToBase64";
import imageInputToBase64 from "./imageInputToBase64"; import imageInputToBase64 from "./imageInputToBase64";
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** /**
* ============================================================================== * ==========================
* Media Functions Object * Media Functions Object
* ============================================================================== * ==========================
*/ */
const media = { const media = {
imageInputToBase64: imageInputToBase64, imageInputToBase64: imageInputToBase64,
@ -24,9 +12,9 @@ const media = {
}; };
/** /**
* ============================================================================== * ==========================
* Media Functions Object * Media Functions Object
* ============================================================================== * ==========================
*/ */
const auth = { const auth = {
imageInputToBase64: imageInputToBase64, imageInputToBase64: imageInputToBase64,
@ -34,16 +22,12 @@ const auth = {
}; };
/** /**
* ============================================================================== * ==========================
* Main Export * Main Export
* ============================================================================== * ==========================
*/ */
const datasquirelClient = { const datasquirelClient = {
media: media, media: media,
}; };
export default datasquirelClient; export default datasquirelClient;
/** ********************************************** */
/** ********************************************** */
/** ********************************************** */

View File

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

View File

@ -39,6 +39,12 @@ async function uploadImage({ key, url }) {
const scheme = process.env.DSQL_HTTP_SCHEME; const scheme = process.env.DSQL_HTTP_SCHEME;
const localHost = process.env.DSQL_LOCAL_HOST; const localHost = process.env.DSQL_LOCAL_HOST;
const localHostPort = process.env.DSQL_LOCAL_HOST_PORT; const localHostPort = process.env.DSQL_LOCAL_HOST_PORT;
const remoteHost = process.env.DSQL_API_REMOTE_HOST?.match(/.*\..*/)
? process.env.DSQL_API_REMOTE_HOST
: undefined;
const remoteHostPort = process.env.DSQL_API_REMOTE_HOST_PORT?.match(/./)
? process.env.DSQL_API_REMOTE_HOST_PORT
: undefined;
try { try {
/** /**
@ -59,8 +65,8 @@ async function uploadImage({ key, url }) {
"Content-Length": Buffer.from(reqPayload).length, "Content-Length": Buffer.from(reqPayload).length,
Authorization: key, Authorization: key,
}, },
port: localHostPort || 443, port: remoteHostPort || localHostPort || 443,
hostname: localHost || "datasquirel.com", hostname: remoteHost || localHost || "datasquirel.com",
path: `/api/query/delete-file`, path: `/api/query/delete-file`,
}, },

View File

@ -31,6 +31,12 @@ async function getSchema({ key, database, field, table }) {
const scheme = process.env.DSQL_HTTP_SCHEME; const scheme = process.env.DSQL_HTTP_SCHEME;
const localHost = process.env.DSQL_LOCAL_HOST; const localHost = process.env.DSQL_LOCAL_HOST;
const localHostPort = process.env.DSQL_LOCAL_HOST_PORT; const localHostPort = process.env.DSQL_LOCAL_HOST_PORT;
const remoteHost = process.env.DSQL_API_REMOTE_HOST?.match(/.*\..*/)
? process.env.DSQL_API_REMOTE_HOST
: undefined;
const remoteHostPort = process.env.DSQL_API_REMOTE_HOST_PORT?.match(/./)
? process.env.DSQL_API_REMOTE_HOST_PORT
: undefined;
/** /**
* Make https request * Make https request
@ -55,8 +61,8 @@ async function getSchema({ key, database, field, table }) {
"Content-Type": "application/json", "Content-Type": "application/json",
Authorization: key, Authorization: key,
}, },
port: localHostPort || 443, port: remoteHostPort || localHostPort || 443,
hostname: localHost || "datasquirel.com", hostname: remoteHost || localHost || "datasquirel.com",
path: path:
"/api/query/get-schema" + "/api/query/get-schema" +
(query?.match(/./) ? `?${query}` : ""), (query?.match(/./) ? `?${query}` : ""),

View File

@ -37,6 +37,12 @@ async function get({ key, db, query, queryValues, tableName }) {
const scheme = process.env.DSQL_HTTP_SCHEME; const scheme = process.env.DSQL_HTTP_SCHEME;
const localHost = process.env.DSQL_LOCAL_HOST; const localHost = process.env.DSQL_LOCAL_HOST;
const localHostPort = process.env.DSQL_LOCAL_HOST_PORT; const localHostPort = process.env.DSQL_LOCAL_HOST_PORT;
const remoteHost = process.env.DSQL_API_REMOTE_HOST?.match(/.*\..*/)
? process.env.DSQL_API_REMOTE_HOST
: undefined;
const remoteHostPort = process.env.DSQL_API_REMOTE_HOST_PORT?.match(/./)
? process.env.DSQL_API_REMOTE_HOST_PORT
: undefined;
/** /**
* Check for local DB settings * Check for local DB settings
@ -107,8 +113,8 @@ async function get({ key, db, query, queryValues, tableName }) {
"Content-Type": "application/json", "Content-Type": "application/json",
Authorization: key, Authorization: key,
}, },
port: localHostPort || 443, port: remoteHostPort || localHostPort || 443,
hostname: localHost || "datasquirel.com", hostname: remoteHost || localHost || "datasquirel.com",
path: encodeURI(path), path: encodeURI(path),
}; };

View File

@ -34,6 +34,12 @@ async function post({ key, query, queryValues, database, tableName }) {
const scheme = process.env.DSQL_HTTP_SCHEME; const scheme = process.env.DSQL_HTTP_SCHEME;
const localHost = process.env.DSQL_LOCAL_HOST; const localHost = process.env.DSQL_LOCAL_HOST;
const localHostPort = process.env.DSQL_LOCAL_HOST_PORT; const localHostPort = process.env.DSQL_LOCAL_HOST_PORT;
const remoteHost = process.env.DSQL_API_REMOTE_HOST?.match(/.*\..*/)
? process.env.DSQL_API_REMOTE_HOST
: undefined;
const remoteHostPort = process.env.DSQL_API_REMOTE_HOST_PORT?.match(/./)
? process.env.DSQL_API_REMOTE_HOST_PORT
: undefined;
/** /**
* Check for local DB settings * Check for local DB settings
@ -113,8 +119,8 @@ async function post({ key, query, queryValues, database, tableName }) {
"Content-Length": Buffer.from(reqPayload).length, "Content-Length": Buffer.from(reqPayload).length,
Authorization: key, Authorization: key,
}, },
port: localHostPort || 443, port: remoteHostPort || localHostPort || 443,
hostname: localHost || "datasquirel.com", hostname: remoteHost || localHost || "datasquirel.com",
path: `/api/query/post`, path: `/api/query/post`,
}, },

View File

@ -46,6 +46,12 @@ async function uploadImage({ key, payload }) {
const scheme = process.env.DSQL_HTTP_SCHEME; const scheme = process.env.DSQL_HTTP_SCHEME;
const localHost = process.env.DSQL_LOCAL_HOST; const localHost = process.env.DSQL_LOCAL_HOST;
const localHostPort = process.env.DSQL_LOCAL_HOST_PORT; const localHostPort = process.env.DSQL_LOCAL_HOST_PORT;
const remoteHost = process.env.DSQL_API_REMOTE_HOST?.match(/.*\..*/)
? process.env.DSQL_API_REMOTE_HOST
: undefined;
const remoteHostPort = process.env.DSQL_API_REMOTE_HOST_PORT?.match(/./)
? process.env.DSQL_API_REMOTE_HOST_PORT
: undefined;
try { try {
/** /**
@ -66,8 +72,8 @@ async function uploadImage({ key, payload }) {
"Content-Length": Buffer.from(reqPayload).length, "Content-Length": Buffer.from(reqPayload).length,
Authorization: key, Authorization: key,
}, },
port: localHostPort || 443, port: remoteHostPort || localHostPort || 443,
hostname: localHost || "datasquirel.com", hostname: remoteHost || localHost || "datasquirel.com",
path: `/api/query/add-file`, path: `/api/query/add-file`,
}, },

View File

@ -48,6 +48,12 @@ async function uploadImage({ key, payload }) {
const scheme = process.env.DSQL_HTTP_SCHEME; const scheme = process.env.DSQL_HTTP_SCHEME;
const localHost = process.env.DSQL_LOCAL_HOST; const localHost = process.env.DSQL_LOCAL_HOST;
const localHostPort = process.env.DSQL_LOCAL_HOST_PORT; const localHostPort = process.env.DSQL_LOCAL_HOST_PORT;
const remoteHost = process.env.DSQL_API_REMOTE_HOST?.match(/.*\..*/)
? process.env.DSQL_API_REMOTE_HOST
: undefined;
const remoteHostPort = process.env.DSQL_API_REMOTE_HOST_PORT?.match(/./)
? process.env.DSQL_API_REMOTE_HOST_PORT
: undefined;
try { try {
/** /**
@ -68,8 +74,8 @@ async function uploadImage({ key, payload }) {
"Content-Length": Buffer.from(reqPayload).length, "Content-Length": Buffer.from(reqPayload).length,
Authorization: key, Authorization: key,
}, },
port: localHostPort || 443, port: remoteHostPort || localHostPort || 443,
hostname: localHost || "datasquirel.com", hostname: remoteHost || localHost || "datasquirel.com",
path: `/api/query/add-image`, path: `/api/query/add-image`,
}, },