updates
This commit is contained in:
parent
089f1b56bd
commit
b74e2d8aa1
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "datasquirel",
|
"name": "datasquirel",
|
||||||
"version": "1.4.2",
|
"version": "1.4.3",
|
||||||
"description": "Cloud-based SQL data management tool",
|
"description": "Cloud-based SQL data management tool",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -26,12 +26,11 @@ const parseCookies = require("../utils/functions/parseCookies");
|
|||||||
* @param {http.IncomingMessage} params.request - Http request object
|
* @param {http.IncomingMessage} params.request - Http request object
|
||||||
* @param {string} params.encryptionKey - Encryption Key
|
* @param {string} params.encryptionKey - Encryption Key
|
||||||
* @param {string} params.encryptionSalt - Encryption Salt
|
* @param {string} params.encryptionSalt - Encryption Salt
|
||||||
* @param {("deep" | "normal")?} [params.level] - Optional. "Deep" value indicates an extra layer of security
|
|
||||||
* @param {string} params.database - Database Name
|
* @param {string} params.database - Database Name
|
||||||
*
|
*
|
||||||
* @returns {{ key: string | undefined, csrf: string | undefined }}
|
* @returns {{ key: string | undefined, csrf: string | undefined }}
|
||||||
*/
|
*/
|
||||||
function getToken({ request, encryptionKey, encryptionSalt, level, database }) {
|
function getToken({ request, encryptionKey, encryptionSalt, database }) {
|
||||||
try {
|
try {
|
||||||
/**
|
/**
|
||||||
* Grab the payload
|
* Grab the payload
|
||||||
@ -81,19 +80,6 @@ function getToken({ request, encryptionKey, encryptionSalt, level, database }) {
|
|||||||
/** ********************************************** */
|
/** ********************************************** */
|
||||||
/** ********************************************** */
|
/** ********************************************** */
|
||||||
|
|
||||||
/**
|
|
||||||
* Grab the payload
|
|
||||||
*
|
|
||||||
* @description Grab the payload
|
|
||||||
*/
|
|
||||||
if (level?.match(/deep/i) && !csrf?.match(new RegExp(`${userObject.csrf_k}`))) {
|
|
||||||
return { key: undefined, csrf: undefined };
|
|
||||||
}
|
|
||||||
|
|
||||||
/** ********************************************** */
|
|
||||||
/** ********************************************** */
|
|
||||||
/** ********************************************** */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return User Object
|
* Return User Object
|
||||||
*
|
*
|
||||||
|
100
utils/upload-file.js
Normal file
100
utils/upload-file.js
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
/**
|
||||||
|
* ==============================================================================
|
||||||
|
* Imports
|
||||||
|
* ==============================================================================
|
||||||
|
*/
|
||||||
|
const https = require("https");
|
||||||
|
|
||||||
|
/** ****************************************************************************** */
|
||||||
|
/** ****************************************************************************** */
|
||||||
|
/** ****************************************************************************** */
|
||||||
|
/** ****************************************************************************** */
|
||||||
|
/** ****************************************************************************** */
|
||||||
|
/** ****************************************************************************** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {Object} FunctionReturn
|
||||||
|
* @property {boolean} success - Did the function run successfully?
|
||||||
|
* @property {{
|
||||||
|
* urlPath: string,
|
||||||
|
* }} payload - Payload containing the url for the image and its thumbnail
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ==============================================================================
|
||||||
|
* Main Function
|
||||||
|
* ==============================================================================
|
||||||
|
* @async
|
||||||
|
*
|
||||||
|
* @param {Object} params - Single Param object containing params
|
||||||
|
* @param {String} params.key - *FULL ACCESS API Key
|
||||||
|
* @param {{
|
||||||
|
* fileData: string,
|
||||||
|
* fileName: string,
|
||||||
|
* mimeType?: string,
|
||||||
|
* folder?: string,
|
||||||
|
* isPrivate?: boolean,
|
||||||
|
* }} params.payload - Image Data Eg.
|
||||||
|
*
|
||||||
|
* @returns { Promise<FunctionReturn> } - Return Object
|
||||||
|
*/
|
||||||
|
async function uploadImage({ key, payload }) {
|
||||||
|
/**
|
||||||
|
* Make https request
|
||||||
|
*
|
||||||
|
* @description make a request to datasquirel.com
|
||||||
|
*/
|
||||||
|
const httpResponse = await new Promise((resolve, reject) => {
|
||||||
|
const reqPayload = JSON.stringify(payload);
|
||||||
|
|
||||||
|
const httpsRequest = https.request(
|
||||||
|
{
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Content-Length": Buffer.from(reqPayload).length,
|
||||||
|
Authorization: key,
|
||||||
|
},
|
||||||
|
port: 443,
|
||||||
|
hostname: "datasquirel.com",
|
||||||
|
path: `/api/query/add-file`,
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback Function
|
||||||
|
*
|
||||||
|
* @description https request callback
|
||||||
|
*/
|
||||||
|
(response) => {
|
||||||
|
var str = "";
|
||||||
|
|
||||||
|
response.on("data", function (chunk) {
|
||||||
|
str += chunk;
|
||||||
|
});
|
||||||
|
|
||||||
|
response.on("end", function () {
|
||||||
|
resolve(JSON.parse(str));
|
||||||
|
});
|
||||||
|
|
||||||
|
response.on("error", (err) => {
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
httpsRequest.write(reqPayload);
|
||||||
|
httpsRequest.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
/** ********************************************** */
|
||||||
|
/** ********************************************** */
|
||||||
|
/** ********************************************** */
|
||||||
|
|
||||||
|
return httpResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** ********************************************** */
|
||||||
|
/** ********************************************** */
|
||||||
|
/** ********************************************** */
|
||||||
|
|
||||||
|
module.exports = uploadImage;
|
@ -32,9 +32,10 @@ const https = require("https");
|
|||||||
* @param {{
|
* @param {{
|
||||||
* imageData: string,
|
* imageData: string,
|
||||||
* imageName: string,
|
* imageName: string,
|
||||||
* mimeType: [string],
|
* mimeType?: string,
|
||||||
* thumbnailSize: [number],
|
* thumbnailSize?: number,
|
||||||
* folder: [string],
|
* folder?: string,
|
||||||
|
* isPrivate?: boolean,
|
||||||
* }} params.payload - Image Data Eg.
|
* }} params.payload - Image Data Eg.
|
||||||
*
|
*
|
||||||
* @returns { Promise<FunctionReturn> } - Return Object
|
* @returns { Promise<FunctionReturn> } - Return Object
|
||||||
|
Loading…
Reference in New Issue
Block a user