Major refactoring: Add user id to API routes
This commit is contained in:
@@ -21,11 +21,13 @@ const grabHostNames = require("../package-shared/utils/grab-host-names");
|
||||
* @param {Object} params - Single Param object containing params
|
||||
* @param {String} params.key - *FULL ACCESS API Key
|
||||
* @param { string } params.url - File URL
|
||||
* @param { string | number } [params.user_id]
|
||||
*
|
||||
* @returns { Promise<FunctionReturn> } - Image Url
|
||||
*/
|
||||
async function uploadImage({ key, url }) {
|
||||
const { host, port, scheme } = grabHostNames();
|
||||
async function deleteFile({ key, url, user_id }) {
|
||||
const grabedHostNames = grabHostNames();
|
||||
const { host, port, scheme } = grabedHostNames;
|
||||
|
||||
try {
|
||||
/**
|
||||
@@ -49,7 +51,9 @@ async function uploadImage({ key, url }) {
|
||||
},
|
||||
port,
|
||||
hostname: host,
|
||||
path: `/api/query/delete-file`,
|
||||
path: `/api/query/${
|
||||
user_id || grabedHostNames.user_id
|
||||
}/delete-file`,
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -90,4 +94,4 @@ async function uploadImage({ key, url }) {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = uploadImage;
|
||||
module.exports = deleteFile;
|
||||
|
||||
+6
-4
@@ -16,8 +16,9 @@ const grabHostNames = require("../package-shared/utils/grab-host-names");
|
||||
*
|
||||
* @returns { Promise<GetSchemaReturn> } - Return Object
|
||||
*/
|
||||
async function getSchema({ key, database, field, table }) {
|
||||
const { host, port, scheme } = grabHostNames();
|
||||
async function getSchema({ key, database, field, table, user_id }) {
|
||||
const grabedHostNames = grabHostNames();
|
||||
const { host, port, scheme } = grabedHostNames;
|
||||
|
||||
/**
|
||||
* Make https request
|
||||
@@ -48,8 +49,9 @@ async function getSchema({ key, database, field, table }) {
|
||||
port,
|
||||
hostname: host,
|
||||
path:
|
||||
"/api/query/get-schema" +
|
||||
(query?.match(/./) ? `?${query}` : ""),
|
||||
`/api/query/${
|
||||
user_id || grabedHostNames.user_id
|
||||
}/get-schema` + (query?.match(/./) ? `?${query}` : ""),
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
+15
-3
@@ -20,11 +20,21 @@ const grabHostNames = require("../package-shared/utils/grab-host-names");
|
||||
* @param {string[]} [params.queryValues] - An array of query values if using "?" placeholders
|
||||
* @param {string} [params.tableName] - Name of the table to query
|
||||
* @param {boolean} [params.useLocal] - Whether to use a remote database instead of API
|
||||
* @param {boolean} [params.user_id] - User ID
|
||||
*
|
||||
* @returns { Promise<import("../package-shared/types").GetReturn> } - Return Object
|
||||
*/
|
||||
async function get({ key, db, query, queryValues, tableName, useLocal }) {
|
||||
const { host, port, scheme } = grabHostNames();
|
||||
async function get({
|
||||
key,
|
||||
db,
|
||||
query,
|
||||
queryValues,
|
||||
tableName,
|
||||
useLocal,
|
||||
user_id,
|
||||
}) {
|
||||
const grabedHostNames = grabHostNames();
|
||||
const { host, port, scheme } = grabedHostNames;
|
||||
|
||||
/**
|
||||
* Check for local DB settings
|
||||
@@ -83,7 +93,9 @@ async function get({ key, db, query, queryValues, tableName, useLocal }) {
|
||||
|
||||
const queryString = serializeQuery({ query: queryObject });
|
||||
|
||||
let path = `/api/query/get${queryString}`;
|
||||
let path = `/api/query/${
|
||||
user_id || grabedHostNames.user_id
|
||||
}/get${queryString}`;
|
||||
|
||||
/** @type {https.RequestOptions} */
|
||||
const requestObject = {
|
||||
|
||||
+5
-2
@@ -16,6 +16,7 @@ const grabHostNames = require("../package-shared/utils/grab-host-names");
|
||||
* @param {any[]} [params.queryValues] - Query Values if using "?" placeholders
|
||||
* @param {string} [params.tableName] - Name of the table to query
|
||||
* @param {boolean} [params.useLocal] - Whether to use a remote database instead of API
|
||||
* @param {boolean} [params.user_id] - User ID
|
||||
*
|
||||
* @returns { Promise<import("../package-shared/types").PostReturn> } - Return Object
|
||||
*/
|
||||
@@ -26,8 +27,10 @@ async function post({
|
||||
database,
|
||||
tableName,
|
||||
useLocal,
|
||||
user_id,
|
||||
}) {
|
||||
const { host, port, scheme } = grabHostNames();
|
||||
const grabedHostNames = grabHostNames();
|
||||
const { host, port, scheme } = grabedHostNames;
|
||||
|
||||
/**
|
||||
* Check for local DB settings
|
||||
@@ -106,7 +109,7 @@ async function post({
|
||||
},
|
||||
port,
|
||||
hostname: host,
|
||||
path: `/api/query/post`,
|
||||
path: `/api/query/${user_id || grabedHostNames.user_id}/post`,
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,13 +24,15 @@ const grabHostNames = require("../package-shared/utils/grab-host-names");
|
||||
* fileName: string,
|
||||
* mimeType?: string,
|
||||
* folder?: string,
|
||||
* isPrivate?: boolean,
|
||||
* isPrivate?: boolean
|
||||
* }} params.payload - Image Data Eg.
|
||||
* @param {boolean} [params.user_id] - User ID
|
||||
*
|
||||
* @returns { Promise<FunctionReturn> } - Return Object
|
||||
*/
|
||||
async function uploadImage({ key, payload }) {
|
||||
const { host, port, scheme } = grabHostNames();
|
||||
async function uploadImage({ key, payload, user_id }) {
|
||||
const grabedHostNames = grabHostNames();
|
||||
const { host, port, scheme } = grabedHostNames;
|
||||
|
||||
try {
|
||||
/**
|
||||
@@ -54,7 +56,9 @@ async function uploadImage({ key, payload }) {
|
||||
},
|
||||
port,
|
||||
hostname: host,
|
||||
path: `/api/query/add-file`,
|
||||
path: `/api/query/${
|
||||
user_id || grabedHostNames.user_id
|
||||
}/add-file`,
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -28,11 +28,13 @@ const grabHostNames = require("../package-shared/utils/grab-host-names");
|
||||
* folder?: string,
|
||||
* isPrivate?: boolean,
|
||||
* }} params.payload - Image Data Eg.
|
||||
* @param {boolean} [params.user_id] - User ID
|
||||
*
|
||||
* @returns { Promise<FunctionReturn> } - Return Object
|
||||
*/
|
||||
async function uploadImage({ key, payload }) {
|
||||
const { host, port, scheme } = grabHostNames();
|
||||
async function uploadImage({ key, payload, user_id }) {
|
||||
const grabedHostNames = grabHostNames();
|
||||
const { host, port, scheme } = grabedHostNames;
|
||||
|
||||
try {
|
||||
/**
|
||||
@@ -56,7 +58,9 @@ async function uploadImage({ key, payload }) {
|
||||
},
|
||||
port,
|
||||
hostname: host,
|
||||
path: `/api/query/add-image`,
|
||||
path: `/api/query/${
|
||||
user_id || grabedHostNames.user_id
|
||||
}/add-image`,
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user