Major Bugfix and Refactoring
This commit is contained in:
parent
a1e7439958
commit
d4e210abdb
@ -7,6 +7,7 @@ const https = require("https");
|
||||
const http = require("http");
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
const grabHostNames = require("../../package-shared/utils/grab-host-names");
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
@ -38,10 +39,7 @@ async function updateApiSchemaFromLocalDb() {
|
||||
const key = process.env.DSQL_KEY || "";
|
||||
|
||||
const dbSchema = JSON.parse(fs.readFileSync(dbSchemaPath, "utf8"));
|
||||
|
||||
const scheme = process.env.DSQL_HTTP_SCHEME;
|
||||
const localHost = process.env.DSQL_LOCAL_HOST;
|
||||
const localHostPort = process.env.DSQL_LOCAL_HOST_PORT;
|
||||
const { host, port, scheme } = grabHostNames();
|
||||
|
||||
/**
|
||||
* Make https request
|
||||
@ -68,9 +66,7 @@ async function updateApiSchemaFromLocalDb() {
|
||||
|
||||
const reqPayload = reqPayloadString;
|
||||
|
||||
const httpsRequest = (
|
||||
scheme?.match(/^http$/i) ? http : https
|
||||
).request(
|
||||
const httpsRequest = scheme.request(
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
@ -78,8 +74,8 @@ async function updateApiSchemaFromLocalDb() {
|
||||
"Content-Length": Buffer.from(reqPayload).length,
|
||||
Authorization: key,
|
||||
},
|
||||
port: localHostPort || 443,
|
||||
hostname: localHost || "datasquirel.com",
|
||||
port,
|
||||
hostname: host,
|
||||
path: `/api/query/update-schema-from-single-database`,
|
||||
},
|
||||
|
||||
|
@ -6,13 +6,9 @@
|
||||
* ==============================================================================
|
||||
*/
|
||||
const http = require("http");
|
||||
const https = require("https");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const encrypt = require("../../../functions/encrypt");
|
||||
const decrypt = require("../../../functions/decrypt");
|
||||
const handleSocialDb = require("./utils/handleSocialDb");
|
||||
const httpsRequest = require("./utils/httpsRequest");
|
||||
const grabHostNames = require("../../../package-shared/utils/grab-host-names");
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
@ -60,9 +56,7 @@ async function localGoogleAuth({
|
||||
*
|
||||
* @description Send a boolean response
|
||||
*/
|
||||
const scheme = process.env.DSQL_HTTP_SCHEME;
|
||||
const localHost = process.env.DSQL_LOCAL_HOST;
|
||||
const localHostPort = process.env.DSQL_LOCAL_HOST_PORT;
|
||||
const { host, port, scheme } = grabHostNames();
|
||||
|
||||
try {
|
||||
/**
|
||||
@ -73,7 +67,7 @@ async function localGoogleAuth({
|
||||
*/
|
||||
const payloadResponse = await httpsRequest({
|
||||
method: "POST",
|
||||
hostname: localHost || "datasquirel.com",
|
||||
hostname: host,
|
||||
path: "/user/grab-google-user-from-token",
|
||||
body: {
|
||||
token: token,
|
||||
|
@ -1,9 +1,10 @@
|
||||
// @ts-check
|
||||
|
||||
/**
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/
|
||||
const https = require("https");
|
||||
const http = require("http");
|
||||
const grabHostNames = require("../../../../package-shared/utils/grab-host-names");
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
@ -28,18 +29,17 @@ const http = require("http");
|
||||
function httpsRequest({ url, method, hostname, path, href, headers, body }) {
|
||||
const reqPayloadString = body ? JSON.stringify(body) : null;
|
||||
|
||||
const scheme = process.env.DSQL_HTTP_SCHEME;
|
||||
const localHost = process.env.DSQL_LOCAL_HOST;
|
||||
const localHostPort = process.env.DSQL_LOCAL_HOST_PORT;
|
||||
const { host, port, scheme } = grabHostNames();
|
||||
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
|
||||
/** @type {any} */
|
||||
let requestOptions = {
|
||||
method: method,
|
||||
hostname: localHost || hostname,
|
||||
port: localHostPort || 443,
|
||||
hostname: host,
|
||||
port,
|
||||
headers: {},
|
||||
};
|
||||
|
||||
@ -59,7 +59,7 @@ function httpsRequest({ url, method, hostname, path, href, headers, body }) {
|
||||
////////////////////////////////////////////////
|
||||
|
||||
return new Promise((res, rej) => {
|
||||
const httpsRequest = (scheme?.match(/^http$/i) ? http : https).request(
|
||||
const httpsRequest = scheme.request(
|
||||
/* ====== Request Options object ====== */
|
||||
// @ts-ignore
|
||||
url ? url : requestOptions,
|
||||
|
35
package-shared/utils/grab-host-names.js
Normal file
35
package-shared/utils/grab-host-names.js
Normal file
@ -0,0 +1,35 @@
|
||||
// @ts-check
|
||||
|
||||
const https = require("https");
|
||||
const http = require("http");
|
||||
|
||||
/**
|
||||
* @typedef {object} GrabHostNamesReturn
|
||||
* @property {string} host
|
||||
* @property {number | string} port
|
||||
* @property {typeof http | typeof https} scheme
|
||||
*/
|
||||
|
||||
/**
|
||||
* # Grab Names For Query
|
||||
* @returns {GrabHostNamesReturn}
|
||||
*/
|
||||
function grabHostNames() {
|
||||
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;
|
||||
|
||||
return {
|
||||
host: remoteHost || localHost || "datasquirel.com",
|
||||
port: remoteHostPort || localHostPort || 443,
|
||||
scheme: scheme?.match(/^http$/i) ? http : https,
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = grabHostNames;
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@moduletrace/datasquirel",
|
||||
"version": "2.6.2",
|
||||
"version": "2.6.3",
|
||||
"description": "Cloud-based SQL data management tool",
|
||||
"main": "index.js",
|
||||
"bin": {
|
||||
|
@ -10,6 +10,7 @@ const http = require("http");
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
const localAddUser = require("../engine/user/add-user");
|
||||
const grabHostNames = require("../package-shared/utils/grab-host-names");
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
@ -54,9 +55,7 @@ async function addUser({
|
||||
DSQL_FULL_SYNC,
|
||||
} = process.env;
|
||||
|
||||
const scheme = process.env.DSQL_HTTP_SCHEME;
|
||||
const localHost = process.env.DSQL_LOCAL_HOST;
|
||||
const localHostPort = process.env.DSQL_LOCAL_HOST_PORT;
|
||||
const { host, port, scheme } = grabHostNames();
|
||||
|
||||
if (
|
||||
DSQL_HOST?.match(/./) &&
|
||||
@ -97,7 +96,7 @@ async function addUser({
|
||||
encryptionKey,
|
||||
});
|
||||
|
||||
const httpsRequest = (scheme?.match(/^http$/i) ? http : https).request(
|
||||
const httpsRequest = scheme.request(
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
@ -105,8 +104,8 @@ async function addUser({
|
||||
"Content-Length": Buffer.from(reqPayload).length,
|
||||
Authorization: key,
|
||||
},
|
||||
port: localHostPort || 443,
|
||||
hostname: localHost || "datasquirel.com",
|
||||
port,
|
||||
hostname: host,
|
||||
path: `/api/user/add-user`,
|
||||
},
|
||||
|
||||
|
@ -1,11 +1,16 @@
|
||||
// @ts-check
|
||||
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
const https = require("https");
|
||||
const http = require("http");
|
||||
const getLocalUser = require("../engine/user/get-user");
|
||||
const grabHostNames = require("../package-shared/utils/grab-host-names");
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
@ -26,7 +31,7 @@ const getLocalUser = require("../engine/user/get-user");
|
||||
* @param {number} params.userId - user id
|
||||
* @param {string[]} [params.fields] - fields to select
|
||||
*
|
||||
* @returns { Promise<import("../types/user.td").GetUserFunctionReturn>}
|
||||
* @returns { Promise<import("../package-shared/types").GetUserFunctionReturn>}
|
||||
*/
|
||||
async function getUser({ key, userId, database, fields }) {
|
||||
/**
|
||||
@ -58,9 +63,7 @@ async function getUser({ key, userId, database, fields }) {
|
||||
fields: [...new Set(updatedFields)],
|
||||
});
|
||||
|
||||
const scheme = process.env.DSQL_HTTP_SCHEME;
|
||||
const localHost = process.env.DSQL_LOCAL_HOST;
|
||||
const localHostPort = process.env.DSQL_LOCAL_HOST_PORT;
|
||||
const { host, port, scheme } = grabHostNames();
|
||||
|
||||
/**
|
||||
* Check for local DB settings
|
||||
@ -83,7 +86,7 @@ async function getUser({ key, userId, database, fields }) {
|
||||
DSQL_PASS?.match(/./) &&
|
||||
DSQL_DB_NAME?.match(/./)
|
||||
) {
|
||||
/** @type {DSQL_DatabaseSchemaType | undefined} */
|
||||
/** @type {import("../package-shared/types").DSQL_DatabaseSchemaType | undefined} */
|
||||
let dbSchema;
|
||||
|
||||
try {
|
||||
@ -109,7 +112,7 @@ async function getUser({ key, userId, database, fields }) {
|
||||
* @description make a request to datasquirel.com
|
||||
*/
|
||||
const httpResponse = await new Promise((resolve, reject) => {
|
||||
const httpsRequest = (scheme?.match(/^http$/i) ? http : https).request(
|
||||
const httpsRequest = scheme.request(
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
@ -117,8 +120,8 @@ async function getUser({ key, userId, database, fields }) {
|
||||
"Content-Length": Buffer.from(reqPayload).length,
|
||||
Authorization: key,
|
||||
},
|
||||
port: localHostPort || 443,
|
||||
hostname: localHost || "datasquirel.com",
|
||||
port,
|
||||
hostname: host,
|
||||
path: `/api/user/get-user`,
|
||||
},
|
||||
|
||||
|
@ -11,6 +11,7 @@ const fs = require("fs");
|
||||
const path = require("path");
|
||||
const encrypt = require("../functions/encrypt");
|
||||
const loginLocalUser = require("../engine/user/login-user");
|
||||
const grabHostNames = require("../package-shared/utils/grab-host-names");
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
@ -56,9 +57,7 @@ async function loginUser({
|
||||
temp_code_field,
|
||||
token,
|
||||
}) {
|
||||
const scheme = process.env.DSQL_HTTP_SCHEME;
|
||||
const localHost = process.env.DSQL_LOCAL_HOST;
|
||||
const localHostPort = process.env.DSQL_LOCAL_HOST_PORT;
|
||||
const { host, port, scheme } = grabHostNames();
|
||||
|
||||
const defaultTempLoginFieldName = "temp_login_code";
|
||||
const emailLoginTempCodeFieldName = email_login
|
||||
@ -171,9 +170,7 @@ async function loginUser({
|
||||
|
||||
const reqPayloadJSON = JSON.stringify(reqPayload);
|
||||
|
||||
const httpsRequest = (
|
||||
scheme?.match(/^http$/i) ? http : https
|
||||
).request(
|
||||
const httpsRequest = scheme.request(
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
@ -181,8 +178,8 @@ async function loginUser({
|
||||
"Content-Length": Buffer.from(reqPayloadJSON).length,
|
||||
Authorization: key,
|
||||
},
|
||||
port: localHostPort || 443,
|
||||
hostname: localHost || "datasquirel.com",
|
||||
port,
|
||||
hostname: host,
|
||||
path: `/api/user/login-user`,
|
||||
},
|
||||
|
||||
|
@ -13,6 +13,7 @@ const encrypt = require("../functions/encrypt");
|
||||
|
||||
const userAuth = require("./user-auth");
|
||||
const localReauthUser = require("../engine/user/reauth-user");
|
||||
const grabHostNames = require("../package-shared/utils/grab-host-names");
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
@ -56,9 +57,7 @@ async function reauthUser({
|
||||
*
|
||||
* @description Check Encryption Keys
|
||||
*/
|
||||
const scheme = process.env.DSQL_HTTP_SCHEME;
|
||||
const localHost = process.env.DSQL_LOCAL_HOST;
|
||||
const localHostPort = process.env.DSQL_LOCAL_HOST_PORT;
|
||||
const { host, port, scheme } = grabHostNames();
|
||||
|
||||
const existingUser = userAuth({
|
||||
database,
|
||||
@ -134,9 +133,7 @@ async function reauthUser({
|
||||
additionalFields,
|
||||
});
|
||||
|
||||
const httpsRequest = (
|
||||
scheme?.match(/^http$/i) ? http : https
|
||||
).request(
|
||||
const httpsRequest = scheme.request(
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
@ -144,8 +141,8 @@ async function reauthUser({
|
||||
"Content-Length": Buffer.from(reqPayload).length,
|
||||
Authorization: key,
|
||||
},
|
||||
port: localHostPort || 443,
|
||||
hostname: localHost || "datasquirel.com",
|
||||
port,
|
||||
hostname: host,
|
||||
path: `/api/user/reauth-user`,
|
||||
},
|
||||
|
||||
|
@ -12,6 +12,7 @@ const path = require("path");
|
||||
const encrypt = require("../functions/encrypt");
|
||||
const loginLocalUser = require("../engine/user/login-user");
|
||||
const localSendEmailCode = require("../engine/user/send-email-code");
|
||||
const grabHostNames = require("../package-shared/utils/grab-host-names");
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
@ -54,9 +55,7 @@ async function sendEmailCode({
|
||||
mail_port,
|
||||
sender,
|
||||
}) {
|
||||
const scheme = process.env.DSQL_HTTP_SCHEME;
|
||||
const localHost = process.env.DSQL_LOCAL_HOST;
|
||||
const localHostPort = process.env.DSQL_LOCAL_HOST_PORT;
|
||||
const { host, port, scheme } = grabHostNames();
|
||||
|
||||
const defaultTempLoginFieldName = "temp_login_code";
|
||||
const emailLoginTempCodeFieldName = temp_code_field
|
||||
@ -164,9 +163,7 @@ async function sendEmailCode({
|
||||
),
|
||||
});
|
||||
|
||||
const httpsRequest = (
|
||||
scheme?.match(/^http$/i) ? http : https
|
||||
).request(
|
||||
const httpsRequest = scheme.request(
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
@ -174,8 +171,8 @@ async function sendEmailCode({
|
||||
"Content-Length": Buffer.from(reqPayload).length,
|
||||
Authorization: key,
|
||||
},
|
||||
port: localHostPort || 443,
|
||||
hostname: localHost || "datasquirel.com",
|
||||
port,
|
||||
hostname: host,
|
||||
path: `/api/user/send-email-code`,
|
||||
},
|
||||
|
||||
|
@ -11,6 +11,7 @@ const fs = require("fs");
|
||||
const path = require("path");
|
||||
const encrypt = require("../../functions/encrypt");
|
||||
const localGithubAuth = require("../../engine/user/social/github-auth");
|
||||
const grabHostNames = require("../../package-shared/utils/grab-host-names");
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
@ -64,9 +65,7 @@ async function githubAuth({
|
||||
*
|
||||
* @description Check inputs
|
||||
*/
|
||||
const scheme = process.env.DSQL_HTTP_SCHEME;
|
||||
const localHost = process.env.DSQL_LOCAL_HOST;
|
||||
const localHostPort = process.env.DSQL_LOCAL_HOST_PORT;
|
||||
const { host, port, scheme } = grabHostNames();
|
||||
|
||||
if (!key || key?.match(/ /)) {
|
||||
return {
|
||||
@ -193,9 +192,7 @@ async function githubAuth({
|
||||
additionalFields,
|
||||
});
|
||||
|
||||
const httpsRequest = (
|
||||
scheme?.match(/^http$/i) ? http : https
|
||||
).request(
|
||||
const httpsRequest = scheme.request(
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
@ -203,8 +200,8 @@ async function githubAuth({
|
||||
"Content-Length": Buffer.from(reqPayload).length,
|
||||
Authorization: key,
|
||||
},
|
||||
port: localHostPort || 443,
|
||||
hostname: localHost || "datasquirel.com",
|
||||
port,
|
||||
hostname: host,
|
||||
path: `/api/user/github-login`,
|
||||
},
|
||||
|
||||
|
@ -11,6 +11,7 @@ const fs = require("fs");
|
||||
const path = require("path");
|
||||
const encrypt = require("../../functions/encrypt");
|
||||
const localGoogleAuth = require("../../engine/user/social/google-auth");
|
||||
const grabHostNames = require("../../package-shared/utils/grab-host-names");
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
@ -55,9 +56,7 @@ async function googleAuth({
|
||||
encryptionSalt,
|
||||
additionalFields,
|
||||
}) {
|
||||
const scheme = process.env.DSQL_HTTP_SCHEME;
|
||||
const localHost = process.env.DSQL_LOCAL_HOST;
|
||||
const localHostPort = process.env.DSQL_LOCAL_HOST_PORT;
|
||||
const { host, port, scheme } = grabHostNames();
|
||||
|
||||
/**
|
||||
* Check inputs
|
||||
@ -189,9 +188,7 @@ async function googleAuth({
|
||||
additionalFields,
|
||||
});
|
||||
|
||||
const httpsRequest = (
|
||||
scheme?.match(/^http$/i) ? http : https
|
||||
).request(
|
||||
const httpsRequest = scheme.request(
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
@ -199,8 +196,8 @@ async function googleAuth({
|
||||
"Content-Length": Buffer.from(reqPayload).length,
|
||||
Authorization: key,
|
||||
},
|
||||
port: localHostPort || 443,
|
||||
hostname: localHost || "datasquirel.com",
|
||||
port,
|
||||
hostname: host,
|
||||
path: `/api/user/google-login`,
|
||||
},
|
||||
|
||||
|
@ -10,6 +10,7 @@ const https = require("https");
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
const localUpdateUser = require("../engine/user/update-user");
|
||||
const grabHostNames = require("../package-shared/utils/grab-host-names");
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
@ -47,9 +48,7 @@ async function updateUser({ key, payload, database }) {
|
||||
DSQL_FULL_SYNC,
|
||||
} = process.env;
|
||||
|
||||
const scheme = process.env.DSQL_HTTP_SCHEME;
|
||||
const localHost = process.env.DSQL_LOCAL_HOST;
|
||||
const localHostPort = process.env.DSQL_LOCAL_HOST_PORT;
|
||||
const { host, port, scheme } = grabHostNames();
|
||||
|
||||
if (
|
||||
DSQL_HOST?.match(/./) &&
|
||||
@ -87,7 +86,7 @@ async function updateUser({ key, payload, database }) {
|
||||
database,
|
||||
});
|
||||
|
||||
const httpsRequest = (scheme?.match(/^http$/i) ? http : https).request(
|
||||
const httpsRequest = scheme.request(
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
@ -95,8 +94,8 @@ async function updateUser({ key, payload, database }) {
|
||||
"Content-Length": Buffer.from(reqPayload).length,
|
||||
Authorization: key,
|
||||
},
|
||||
port: localHostPort || 443,
|
||||
hostname: localHost || "datasquirel.com",
|
||||
port,
|
||||
hostname: host,
|
||||
path: `/api/user/update-user`,
|
||||
},
|
||||
|
||||
|
@ -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`,
|
||||
},
|
||||
|
||||
|
@ -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}` : ""),
|
||||
|
17
utils/get.js
17
utils/get.js
@ -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,
|
||||
|
||||
|
@ -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`,
|
||||
},
|
||||
|
||||
|
@ -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`,
|
||||
},
|
||||
|
||||
|
@ -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`,
|
||||
},
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user