From 224dbf41753b83965c562b96eb86865cb543bd4e Mon Sep 17 00:00:00 2001 From: Tben <52448020+BenjaminToby@users.noreply.github.com> Date: Sat, 6 May 2023 13:18:44 +0100 Subject: [PATCH] updates --- package.json | 2 +- users/add-user.js | 72 +++++++++++++++++++++--------------------- users/login-user.js | 73 ++++++++++++++++++++++--------------------- utils/post.js | 65 ++++++++++++++++++++------------------ utils/upload-image.js | 65 ++++++++++++++++++++------------------ 5 files changed, 142 insertions(+), 135 deletions(-) diff --git a/package.json b/package.json index ed9b16d..1ed5ade 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "datasquirel", - "version": "1.0.5", + "version": "1.0.6", "description": "Cloud-based SQL data management tool", "main": "index.js", "scripts": { diff --git a/users/add-user.js b/users/add-user.js index a0d2f7b..d8921a4 100644 --- a/users/add-user.js +++ b/users/add-user.js @@ -35,47 +35,47 @@ module.exports = async function ({ key, payload, database }) { * @description make a request to datasquirel.com */ const httpResponse = await new Promise((resolve, reject) => { - https - .request( - { - method: "POST", - headers: { - "Content-Type": "application/json", - Authorization: key, - }, - port: 443, - hostname: "datasquirel.com", - path: `/api/user/add-user`, + const reqPayload = JSON.stringify({ + payload, + database, + }); + + const httpsRequest = https.request( + { + method: "POST", + headers: { + "Content-Type": "application/json", + "Content-Length": reqPayload.length, + Authorization: key, }, + port: 443, + hostname: "datasquirel.com", + path: `/api/user/add-user`, + }, - /** - * Callback Function - * - * @description https request callback - */ - (response) => { - var str = ""; + /** + * Callback Function + * + * @description https request callback + */ + (response) => { + var str = ""; - response.on("data", function (chunk) { - str += chunk; - }); + response.on("data", function (chunk) { + str += chunk; + }); - response.on("end", function () { - resolve(JSON.parse(str)); - }); + response.on("end", function () { + resolve(JSON.parse(str)); + }); - response.on("error", (err) => { - reject(err); - }); - } - ) - .write( - JSON.stringify({ - payload, - database, - }) - ) - .end(); + response.on("error", (err) => { + reject(err); + }); + } + ); + httpsRequest.write(reqPayload); + httpsRequest.end(); }); /** ********************************************** */ diff --git a/users/login-user.js b/users/login-user.js index e70735d..3bcf7e7 100644 --- a/users/login-user.js +++ b/users/login-user.js @@ -72,47 +72,48 @@ module.exports = async function ({ key, payload, database, response, encryptionK * @description make a request to datasquirel.com */ const httpResponse = await new Promise((resolve, reject) => { - https - .request( - { - method: "POST", - headers: { - "Content-Type": "application/json", - Authorization: key, - }, - port: 443, - hostname: "datasquirel.com", - path: `/api/user/login-user`, + const reqPayload = JSON.stringify({ + payload, + database, + }); + + const httpsRequest = https.request( + { + method: "POST", + headers: { + "Content-Type": "application/json", + "Content-Length": reqPayload.length, + Authorization: key, }, + port: 443, + hostname: "datasquirel.com", + path: `/api/user/login-user`, + }, - /** - * Callback Function - * - * @description https request callback - */ - (response) => { - var str = ""; + /** + * Callback Function + * + * @description https request callback + */ + (response) => { + var str = ""; - response.on("data", function (chunk) { - str += chunk; - }); + response.on("data", function (chunk) { + str += chunk; + }); - response.on("end", function () { - resolve(JSON.parse(str)); - }); + response.on("end", function () { + resolve(JSON.parse(str)); + }); - response.on("error", (err) => { - reject(err); - }); - } - ) - .write( - JSON.stringify({ - payload, - database, - }) - ) - .end(); + response.on("error", (err) => { + reject(err); + }); + } + ); + + httpsRequest.write(reqPayload); + httpsRequest.end(); }); /** ********************************************** */ diff --git a/utils/post.js b/utils/post.js index 35ad378..fff280e 100644 --- a/utils/post.js +++ b/utils/post.js @@ -34,42 +34,45 @@ module.exports = async function ({ key, payload }) { * @description make a request to datasquirel.com */ const httpResponse = await new Promise((resolve, reject) => { - https - .request( - { - method: "POST", - headers: { - "Content-Type": "application/json", - Authorization: key, - }, - port: 443, - hostname: "datasquirel.com", - path: `/api/query/post`, + const reqPayload = JSON.stringify(payload); + + const httpsRequest = https.request( + { + method: "POST", + headers: { + "Content-Type": "application/json", + "Content-Length": reqPayload.length, + Authorization: key, }, + port: 443, + hostname: "datasquirel.com", + path: `/api/query/post`, + }, - /** - * Callback Function - * - * @description https request callback - */ - (response) => { - var str = ""; + /** + * Callback Function + * + * @description https request callback + */ + (response) => { + var str = ""; - response.on("data", function (chunk) { - str += chunk; - }); + response.on("data", function (chunk) { + str += chunk; + }); - response.on("end", function () { - resolve(JSON.parse(str)); - }); + response.on("end", function () { + resolve(JSON.parse(str)); + }); - response.on("error", (err) => { - reject(err); - }); - } - ) - .write(JSON.stringify(payload)) - .end(); + response.on("error", (err) => { + reject(err); + }); + } + ); + + httpsRequest.write(reqPayload); + httpsRequest.end(); }); /** ********************************************** */ diff --git a/utils/upload-image.js b/utils/upload-image.js index 68277df..da25ec0 100644 --- a/utils/upload-image.js +++ b/utils/upload-image.js @@ -31,42 +31,45 @@ module.exports = async function ({ key, payload }) { * @description make a request to datasquirel.com */ const httpResponse = await new Promise((resolve, reject) => { - https - .request( - { - method: "POST", - headers: { - "Content-Type": "application/json", - Authorization: key, - }, - port: 443, - hostname: "datasquirel.com", - path: `/api/query/post`, + const reqPayload = JSON.stringify(payload); + + const httpsRequest = https.request( + { + method: "POST", + headers: { + "Content-Type": "application/json", + "Content-Length": reqPayload.length, + Authorization: key, }, + port: 443, + hostname: "datasquirel.com", + path: `/api/query/post`, + }, - /** - * Callback Function - * - * @description https request callback - */ - (response) => { - var str = ""; + /** + * Callback Function + * + * @description https request callback + */ + (response) => { + var str = ""; - response.on("data", function (chunk) { - str += chunk; - }); + response.on("data", function (chunk) { + str += chunk; + }); - response.on("end", function () { - resolve(JSON.parse(str)); - }); + response.on("end", function () { + resolve(JSON.parse(str)); + }); - response.on("error", (err) => { - reject(err); - }); - } - ) - .write(JSON.stringify(payload)) - .end(); + response.on("error", (err) => { + reject(err); + }); + } + ); + + httpsRequest.write(reqPayload); + httpsRequest.end(); }); /** ********************************************** */