This commit is contained in:
Benjamin Toby
2024-11-15 15:37:53 +01:00
parent ee35543885
commit 5e13f064aa
18 changed files with 74 additions and 151 deletions
+5 -28
View File
@@ -1,21 +1,9 @@
// @ts-check
/**
* ==============================================================================
* Imports
* ==============================================================================
*/
const http = require("http");
const https = require("https");
const grabHostNames = require("../package-shared/utils/grab-host-names");
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/**
* @typedef {Object} FunctionReturn
* @property {boolean} success - Did the function run successfully?
@@ -27,9 +15,7 @@ const grabHostNames = require("../package-shared/utils/grab-host-names");
*/
/**
* ==============================================================================
* Main Function
* ==============================================================================
* # Delete File via API
* @async
*
* @param {Object} params - Single Param object containing params
@@ -56,7 +42,10 @@ async function uploadImage({ key, url }) {
headers: {
"Content-Type": "application/json",
"Content-Length": Buffer.from(reqPayload).length,
Authorization: key,
Authorization:
key ||
process.env.DSQL_FULL_ACCESS_API_KEY ||
process.env.DSQL_API_KEY,
},
port,
hostname: host,
@@ -89,16 +78,8 @@ async function uploadImage({ key, url }) {
httpsRequest.end();
});
/** ********************************************** */
/** ********************************************** */
/** ********************************************** */
return httpResponse;
} catch (/** @type {*} */ error) {
/** ********************************************** */
/** ********************************************** */
/** ********************************************** */
console.log("Error deleting file: ", error.message);
return {
@@ -109,8 +90,4 @@ async function uploadImage({ key, url }) {
}
}
/** ********************************************** */
/** ********************************************** */
/** ********************************************** */
module.exports = uploadImage;
+4 -21
View File
@@ -1,21 +1,9 @@
// @ts-check
/**
* ==============================================================================
* Imports
* ==============================================================================
*/
const http = require("http");
const https = require("https");
const grabHostNames = require("../package-shared/utils/grab-host-names");
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/**
* @typedef {Object} GetSchemaReturn
* @property {boolean} success - Did the function run successfully?
@@ -52,7 +40,10 @@ async function getSchema({ key, database, field, table }) {
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: key,
Authorization:
key ||
process.env.DSQL_FULL_ACCESS_API_KEY ||
process.env.DSQL_API_KEY,
},
port,
hostname: host,
@@ -85,15 +76,7 @@ async function getSchema({ key, database, field, table }) {
.end();
});
/** ********************************************** */
/** ********************************************** */
/** ********************************************** */
return httpResponse;
}
/** ********************************************** */
/** ********************************************** */
/** ********************************************** */
module.exports = getSchema;
+6 -14
View File
@@ -1,10 +1,5 @@
// @ts-check
/**
* ==============================================================================
* Imports
* ==============================================================================
*/
const http = require("node:http");
const https = require("node:https");
const path = require("path");
@@ -13,13 +8,6 @@ const localGet = require("../engine/query/get");
const serializeQuery = require("./functions/serialize-query");
const grabHostNames = require("../package-shared/utils/grab-host-names");
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/**
* Make a get request to Datasquirel API
* ==============================================================================
@@ -80,7 +68,7 @@ async function get({ key, db, query, queryValues, tableName }) {
const httpResponse = await new Promise((resolve, reject) => {
/** @type {import("../package-shared/types").GetReqQueryObject} */
const queryObject = {
db: String(db),
db: process.env.DSQL_API_DB_NAME || String(db),
query: String(
query
.replace(/\n|\r|\n\r/g, "")
@@ -100,7 +88,11 @@ async function get({ key, db, query, queryValues, tableName }) {
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: key,
Authorization:
key ||
process.env.DSQL_READ_ONLY_API_KEY ||
process.env.DSQL_FULL_ACCESS_API_KEY ||
process.env.DSQL_API_KEY,
},
port,
hostname: host,
+6 -14
View File
@@ -1,8 +1,5 @@
// @ts-check
/**
* Imports
*/
const http = require("http");
const https = require("https");
const path = require("path");
@@ -10,16 +7,8 @@ const fs = require("fs");
const localPost = require("../engine/query/post");
const grabHostNames = require("../package-shared/utils/grab-host-names");
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/**
* Make a post request to Datasquirel API
* ==============================================================================
* # Make a post request to Datasquirel API
* @async
*
* @param {Object} params - Single object passed
@@ -78,7 +67,7 @@ async function post({ key, query, queryValues, database, tableName }) {
const reqPayloadString = JSON.stringify({
query,
queryValues,
database,
database: process.env.DSQL_API_DB_NAME || database,
tableName: tableName ? tableName : null,
}).replace(/\n|\r|\n\r/gm, "");
@@ -103,7 +92,10 @@ async function post({ key, query, queryValues, database, tableName }) {
headers: {
"Content-Type": "application/json",
"Content-Length": Buffer.from(reqPayload).length,
Authorization: key,
Authorization:
key ||
process.env.DSQL_FULL_ACCESS_API_KEY ||
process.env.DSQL_API_KEY,
},
port,
hostname: host,
+5 -16
View File
@@ -1,21 +1,9 @@
// @ts-check
/**
* ==============================================================================
* Imports
* ==============================================================================
*/
const http = require("http");
const https = require("https");
const grabHostNames = require("../package-shared/utils/grab-host-names");
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/**
* @typedef {Object} FunctionReturn
* @property {boolean} success - Did the function run successfully?
@@ -26,9 +14,7 @@ const grabHostNames = require("../package-shared/utils/grab-host-names");
*/
/**
* ==============================================================================
* Main Function
* ==============================================================================
* # Upload File via API
* @async
*
* @param {Object} params - Single Param object containing params
@@ -61,7 +47,10 @@ async function uploadImage({ key, payload }) {
headers: {
"Content-Type": "application/json",
"Content-Length": Buffer.from(reqPayload).length,
Authorization: key,
Authorization:
key ||
process.env.DSQL_FULL_ACCESS_API_KEY ||
process.env.DSQL_API_KEY,
},
port,
hostname: host,
+5 -16
View File
@@ -1,21 +1,9 @@
// @ts-check
/**
* ==============================================================================
* Imports
* ==============================================================================
*/
const http = require("http");
const https = require("https");
const grabHostNames = require("../package-shared/utils/grab-host-names");
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/**
* @typedef {Object} FunctionReturn
* @property {boolean} success - Did the function run successfully?
@@ -27,9 +15,7 @@ const grabHostNames = require("../package-shared/utils/grab-host-names");
*/
/**
* ==============================================================================
* Main Function
* ==============================================================================
* # Upload Image via API
* @async
*
* @param {Object} params - Single Param object containing params
@@ -63,7 +49,10 @@ async function uploadImage({ key, payload }) {
headers: {
"Content-Type": "application/json",
"Content-Length": Buffer.from(reqPayload).length,
Authorization: key,
Authorization:
key ||
process.env.DSQL_FULL_ACCESS_API_KEY ||
process.env.DSQL_API_KEY,
},
port,
hostname: host,