Major Bugfix and Refactoring
This commit is contained in:
+8
-15
@@ -1,3 +1,5 @@
|
||||
// @ts-check
|
||||
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Imports
|
||||
@@ -5,6 +7,7 @@
|
||||
*/
|
||||
const http = require("http");
|
||||
const https = require("https");
|
||||
const grabHostNames = require("../package-shared/utils/grab-host-names");
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
@@ -19,7 +22,7 @@ const https = require("https");
|
||||
* @property {{
|
||||
* urlPath: string,
|
||||
* urlThumbnailPath: string
|
||||
* }} payload - Payload containing the url for the image and its thumbnail
|
||||
* } | null} payload - Payload containing the url for the image and its thumbnail
|
||||
* @property {string} [msg] - An optional message
|
||||
*/
|
||||
|
||||
@@ -36,15 +39,7 @@ const https = require("https");
|
||||
* @returns { Promise<FunctionReturn> } - Image Url
|
||||
*/
|
||||
async function uploadImage({ key, url }) {
|
||||
const scheme = process.env.DSQL_HTTP_SCHEME;
|
||||
const localHost = process.env.DSQL_LOCAL_HOST;
|
||||
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;
|
||||
const { host, port, scheme } = grabHostNames();
|
||||
|
||||
try {
|
||||
/**
|
||||
@@ -55,9 +50,7 @@ async function uploadImage({ key, url }) {
|
||||
const httpResponse = await new Promise((resolve, reject) => {
|
||||
const reqPayload = JSON.stringify({ url: url });
|
||||
|
||||
const httpsRequest = (
|
||||
scheme?.match(/^http$/i) ? http : https
|
||||
).request(
|
||||
const httpsRequest = scheme.request(
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
@@ -65,8 +58,8 @@ async function uploadImage({ key, url }) {
|
||||
"Content-Length": Buffer.from(reqPayload).length,
|
||||
Authorization: key,
|
||||
},
|
||||
port: remoteHostPort || localHostPort || 443,
|
||||
hostname: remoteHost || localHost || "datasquirel.com",
|
||||
port,
|
||||
hostname: host,
|
||||
path: `/api/query/delete-file`,
|
||||
},
|
||||
|
||||
|
||||
+5
-12
@@ -7,6 +7,7 @@
|
||||
*/
|
||||
const http = require("http");
|
||||
const https = require("https");
|
||||
const grabHostNames = require("../package-shared/utils/grab-host-names");
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
@@ -28,15 +29,7 @@ const https = require("https");
|
||||
* @returns { Promise<GetSchemaReturn> } - Return Object
|
||||
*/
|
||||
async function getSchema({ key, database, field, table }) {
|
||||
const scheme = process.env.DSQL_HTTP_SCHEME;
|
||||
const localHost = process.env.DSQL_LOCAL_HOST;
|
||||
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;
|
||||
const { host, port, scheme } = grabHostNames();
|
||||
|
||||
/**
|
||||
* Make https request
|
||||
@@ -53,7 +46,7 @@ async function getSchema({ key, database, field, table }) {
|
||||
.map((k) => `${k}=${queryObject[k]}`)
|
||||
.join("&");
|
||||
|
||||
(scheme?.match(/^http$/i) ? http : https)
|
||||
scheme
|
||||
.request(
|
||||
{
|
||||
method: "GET",
|
||||
@@ -61,8 +54,8 @@ async function getSchema({ key, database, field, table }) {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: key,
|
||||
},
|
||||
port: remoteHostPort || localHostPort || 443,
|
||||
hostname: remoteHost || localHost || "datasquirel.com",
|
||||
port,
|
||||
hostname: host,
|
||||
path:
|
||||
"/api/query/get-schema" +
|
||||
(query?.match(/./) ? `?${query}` : ""),
|
||||
|
||||
+5
-12
@@ -11,6 +11,7 @@ const path = require("path");
|
||||
const fs = require("fs");
|
||||
const localGet = require("../engine/query/get");
|
||||
const serializeQuery = require("./functions/serialize-query");
|
||||
const grabHostNames = require("../package-shared/utils/grab-host-names");
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
@@ -34,15 +35,7 @@ const serializeQuery = require("./functions/serialize-query");
|
||||
* @returns { Promise<import("../package-shared/types").GetReturn> } - Return Object
|
||||
*/
|
||||
async function get({ key, db, query, queryValues, tableName }) {
|
||||
const scheme = process.env.DSQL_HTTP_SCHEME;
|
||||
const localHost = process.env.DSQL_LOCAL_HOST;
|
||||
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;
|
||||
const { host, port, scheme } = grabHostNames();
|
||||
|
||||
/**
|
||||
* Check for local DB settings
|
||||
@@ -109,12 +102,12 @@ async function get({ key, db, query, queryValues, tableName }) {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: key,
|
||||
},
|
||||
port: remoteHostPort || localHostPort || 443,
|
||||
hostname: remoteHost || localHost || "datasquirel.com",
|
||||
port,
|
||||
hostname: host,
|
||||
path: encodeURI(path),
|
||||
};
|
||||
|
||||
(scheme?.match(/^http$/i) ? http : https)
|
||||
scheme
|
||||
.request(
|
||||
requestObject,
|
||||
|
||||
|
||||
+5
-12
@@ -8,6 +8,7 @@ const https = require("https");
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
const localPost = require("../engine/query/post");
|
||||
const grabHostNames = require("../package-shared/utils/grab-host-names");
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
@@ -31,15 +32,7 @@ const localPost = require("../engine/query/post");
|
||||
* @returns { Promise<import("../package-shared/types").PostReturn> } - Return Object
|
||||
*/
|
||||
async function post({ key, query, queryValues, database, tableName }) {
|
||||
const scheme = process.env.DSQL_HTTP_SCHEME;
|
||||
const localHost = process.env.DSQL_LOCAL_HOST;
|
||||
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;
|
||||
const { host, port, scheme } = grabHostNames();
|
||||
|
||||
/**
|
||||
* Check for local DB settings
|
||||
@@ -104,7 +97,7 @@ async function post({ key, query, queryValues, database, tableName }) {
|
||||
|
||||
const reqPayload = reqPayloadString;
|
||||
|
||||
const httpsRequest = (scheme?.match(/^http$/i) ? http : https).request(
|
||||
const httpsRequest = scheme.request(
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
@@ -112,8 +105,8 @@ async function post({ key, query, queryValues, database, tableName }) {
|
||||
"Content-Length": Buffer.from(reqPayload).length,
|
||||
Authorization: key,
|
||||
},
|
||||
port: remoteHostPort || localHostPort || 443,
|
||||
hostname: remoteHost || localHost || "datasquirel.com",
|
||||
port,
|
||||
hostname: host,
|
||||
path: `/api/query/post`,
|
||||
},
|
||||
|
||||
|
||||
+5
-14
@@ -7,6 +7,7 @@
|
||||
*/
|
||||
const http = require("http");
|
||||
const https = require("https");
|
||||
const grabHostNames = require("../package-shared/utils/grab-host-names");
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
@@ -43,15 +44,7 @@ const https = require("https");
|
||||
* @returns { Promise<FunctionReturn> } - Return Object
|
||||
*/
|
||||
async function uploadImage({ key, payload }) {
|
||||
const scheme = process.env.DSQL_HTTP_SCHEME;
|
||||
const localHost = process.env.DSQL_LOCAL_HOST;
|
||||
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;
|
||||
const { host, port, scheme } = grabHostNames();
|
||||
|
||||
try {
|
||||
/**
|
||||
@@ -62,9 +55,7 @@ async function uploadImage({ key, payload }) {
|
||||
const httpResponse = await new Promise((resolve, reject) => {
|
||||
const reqPayload = JSON.stringify(payload);
|
||||
|
||||
const httpsRequest = (
|
||||
scheme?.match(/^http$/i) ? http : https
|
||||
).request(
|
||||
const httpsRequest = scheme.request(
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
@@ -72,8 +63,8 @@ async function uploadImage({ key, payload }) {
|
||||
"Content-Length": Buffer.from(reqPayload).length,
|
||||
Authorization: key,
|
||||
},
|
||||
port: remoteHostPort || localHostPort || 443,
|
||||
hostname: remoteHost || localHost || "datasquirel.com",
|
||||
port,
|
||||
hostname: host,
|
||||
path: `/api/query/add-file`,
|
||||
},
|
||||
|
||||
|
||||
+5
-14
@@ -7,6 +7,7 @@
|
||||
*/
|
||||
const http = require("http");
|
||||
const https = require("https");
|
||||
const grabHostNames = require("../package-shared/utils/grab-host-names");
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
@@ -45,15 +46,7 @@ const https = require("https");
|
||||
* @returns { Promise<FunctionReturn> } - Return Object
|
||||
*/
|
||||
async function uploadImage({ key, payload }) {
|
||||
const scheme = process.env.DSQL_HTTP_SCHEME;
|
||||
const localHost = process.env.DSQL_LOCAL_HOST;
|
||||
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;
|
||||
const { host, port, scheme } = grabHostNames();
|
||||
|
||||
try {
|
||||
/**
|
||||
@@ -64,9 +57,7 @@ async function uploadImage({ key, payload }) {
|
||||
const httpResponse = await new Promise((resolve, reject) => {
|
||||
const reqPayload = JSON.stringify(payload);
|
||||
|
||||
const httpsRequest = (
|
||||
scheme?.match(/^http$/i) ? http : https
|
||||
).request(
|
||||
const httpsRequest = scheme.request(
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
@@ -74,8 +65,8 @@ async function uploadImage({ key, payload }) {
|
||||
"Content-Length": Buffer.from(reqPayload).length,
|
||||
Authorization: key,
|
||||
},
|
||||
port: remoteHostPort || localHostPort || 443,
|
||||
hostname: remoteHost || localHost || "datasquirel.com",
|
||||
port,
|
||||
hostname: host,
|
||||
path: `/api/query/add-image`,
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user