This commit is contained in:
Tben 2023-08-10 16:01:16 +01:00
parent af6ebfe15c
commit 5f9f1ceeba
3 changed files with 117 additions and 87 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "datasquirel", "name": "datasquirel",
"version": "1.4.4", "version": "1.4.5",
"description": "Cloud-based SQL data management tool", "description": "Cloud-based SQL data management tool",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {

View File

@ -18,6 +18,7 @@ const https = require("https");
* @property {{ * @property {{
* urlPath: string, * urlPath: string,
* }} payload - Payload containing the url for the image and its thumbnail * }} payload - Payload containing the url for the image and its thumbnail
* @property {string} [msg] - An optional message
*/ */
/** /**
@ -39,58 +40,72 @@ const https = require("https");
* @returns { Promise<FunctionReturn> } - Return Object * @returns { Promise<FunctionReturn> } - Return Object
*/ */
async function uploadImage({ key, payload }) { async function uploadImage({ key, payload }) {
/** try {
* Make https request /**
* * Make https request
* @description make a request to datasquirel.com *
*/ * @description make a request to datasquirel.com
const httpResponse = await new Promise((resolve, reject) => { */
const reqPayload = JSON.stringify(payload); const httpResponse = await new Promise((resolve, reject) => {
const reqPayload = JSON.stringify(payload);
const httpsRequest = https.request( const httpsRequest = https.request(
{ {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
"Content-Length": Buffer.from(reqPayload).length, "Content-Length": Buffer.from(reqPayload).length,
Authorization: key, Authorization: key,
},
port: 443,
hostname: "datasquirel.com",
path: `/api/query/add-file`,
}, },
port: 443,
hostname: "datasquirel.com",
path: `/api/query/add-file`,
},
/** /**
* Callback Function * Callback Function
* *
* @description https request callback * @description https request callback
*/ */
(response) => { (response) => {
var str = ""; var str = "";
response.on("data", function (chunk) { response.on("data", function (chunk) {
str += chunk; str += chunk;
}); });
response.on("end", function () { response.on("end", function () {
resolve(JSON.parse(str)); resolve(JSON.parse(str));
}); });
response.on("error", (err) => { response.on("error", (err) => {
reject(err); reject(err);
}); });
} }
); );
httpsRequest.write(reqPayload); httpsRequest.write(reqPayload);
httpsRequest.end(); httpsRequest.end();
}); });
/** ********************************************** */ /** ********************************************** */
/** ********************************************** */ /** ********************************************** */
/** ********************************************** */ /** ********************************************** */
return httpResponse; return httpResponse;
} catch (error) {
/** ********************************************** */
/** ********************************************** */
/** ********************************************** */
console.log("Error in uploading file: ", error.message);
return {
success: false,
payload: null,
msg: error.message,
};
}
} }
/** ********************************************** */ /** ********************************************** */

View File

@ -19,6 +19,7 @@ const https = require("https");
* urlPath: string, * urlPath: string,
* urlThumbnailPath: string * urlThumbnailPath: string
* }} payload - Payload containing the url for the image and its thumbnail * }} payload - Payload containing the url for the image and its thumbnail
* @property {string} [msg] - An optional message
*/ */
/** /**
@ -41,58 +42,72 @@ const https = require("https");
* @returns { Promise<FunctionReturn> } - Return Object * @returns { Promise<FunctionReturn> } - Return Object
*/ */
async function uploadImage({ key, payload }) { async function uploadImage({ key, payload }) {
/** try {
* Make https request /**
* * Make https request
* @description make a request to datasquirel.com *
*/ * @description make a request to datasquirel.com
const httpResponse = await new Promise((resolve, reject) => { */
const reqPayload = JSON.stringify(payload); const httpResponse = await new Promise((resolve, reject) => {
const reqPayload = JSON.stringify(payload);
const httpsRequest = https.request( const httpsRequest = https.request(
{ {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
"Content-Length": Buffer.from(reqPayload).length, "Content-Length": Buffer.from(reqPayload).length,
Authorization: key, Authorization: key,
},
port: 443,
hostname: "datasquirel.com",
path: `/api/query/add-image`,
}, },
port: 443,
hostname: "datasquirel.com",
path: `/api/query/add-image`,
},
/** /**
* Callback Function * Callback Function
* *
* @description https request callback * @description https request callback
*/ */
(response) => { (response) => {
var str = ""; var str = "";
response.on("data", function (chunk) { response.on("data", function (chunk) {
str += chunk; str += chunk;
}); });
response.on("end", function () { response.on("end", function () {
resolve(JSON.parse(str)); resolve(JSON.parse(str));
}); });
response.on("error", (err) => { response.on("error", (err) => {
reject(err); reject(err);
}); });
} }
); );
httpsRequest.write(reqPayload); httpsRequest.write(reqPayload);
httpsRequest.end(); httpsRequest.end();
}); });
/** ********************************************** */ /** ********************************************** */
/** ********************************************** */ /** ********************************************** */
/** ********************************************** */ /** ********************************************** */
return httpResponse; return httpResponse;
} catch (error) {
/** ********************************************** */
/** ********************************************** */
/** ********************************************** */
console.log("Error in uploading image: ", error.message);
return {
success: false,
payload: null,
msg: error.message,
};
}
} }
/** ********************************************** */ /** ********************************************** */