mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
refactor: Removal of request lib from the code (#6413)
* refactor: Removal of request lib from the code
This commit is contained in:
committed by
कारतोफ्फेलस्क्रिप्ट™
parent
1197811a1e
commit
632ea275b7
@@ -97,9 +97,8 @@ import get from 'lodash/get';
|
||||
import type { Request, Response } from 'express';
|
||||
import FormData from 'form-data';
|
||||
import path from 'path';
|
||||
import type { OptionsWithUri, OptionsWithUrl, RequestCallback, RequiredUriUrl } from 'request';
|
||||
import type { OptionsWithUri, OptionsWithUrl } from 'request';
|
||||
import type { RequestPromiseOptions } from 'request-promise-native';
|
||||
import requestPromise from 'request-promise-native';
|
||||
import FileType from 'file-type';
|
||||
import { lookup, extension } from 'mime-types';
|
||||
import type { IncomingHttpHeaders } from 'http';
|
||||
@@ -142,10 +141,6 @@ axios.defaults.paramsSerializer = (params) => {
|
||||
return stringify(params, { arrayFormat: 'indices' });
|
||||
};
|
||||
|
||||
const requestPromiseWithDefaults = requestPromise.defaults({
|
||||
timeout: 300000, // 5 minutes
|
||||
});
|
||||
|
||||
const pushFormDataValue = (form: FormData, key: string, value: any) => {
|
||||
if (value?.hasOwnProperty('value') && value.hasOwnProperty('options')) {
|
||||
form.append(key, value.value, value.options);
|
||||
@@ -596,21 +591,12 @@ type ConfigObject = {
|
||||
};
|
||||
|
||||
export async function proxyRequestToAxios(
|
||||
workflow: Workflow,
|
||||
additionalData: IWorkflowExecuteAdditionalData,
|
||||
node: INode,
|
||||
uriOrObject: string | IDataObject,
|
||||
options?: IDataObject,
|
||||
workflow: Workflow | undefined,
|
||||
additionalData: IWorkflowExecuteAdditionalData | undefined,
|
||||
node: INode | undefined,
|
||||
uriOrObject: string | object,
|
||||
options?: object,
|
||||
): Promise<any> {
|
||||
// Check if there's a better way of getting this config here
|
||||
if (process.env.N8N_USE_DEPRECATED_REQUEST_LIB) {
|
||||
return requestPromiseWithDefaults.call(
|
||||
null,
|
||||
uriOrObject as unknown as RequiredUriUrl & RequestPromiseOptions,
|
||||
options as unknown as RequestCallback,
|
||||
);
|
||||
}
|
||||
|
||||
let axiosConfig: AxiosRequestConfig = {
|
||||
maxBodyLength: Infinity,
|
||||
maxContentLength: Infinity,
|
||||
@@ -667,7 +653,7 @@ export async function proxyRequestToAxios(
|
||||
body = undefined;
|
||||
}
|
||||
}
|
||||
await additionalData.hooks?.executeHookFunctions('nodeFetchedData', [workflow.id, node]);
|
||||
await additionalData?.hooks?.executeHookFunctions('nodeFetchedData', [workflow?.id, node]);
|
||||
return {
|
||||
body,
|
||||
headers: response.headers,
|
||||
@@ -684,7 +670,7 @@ export async function proxyRequestToAxios(
|
||||
body = undefined;
|
||||
}
|
||||
}
|
||||
await additionalData.hooks?.executeHookFunctions('nodeFetchedData', [workflow.id, node]);
|
||||
await additionalData?.hooks?.executeHookFunctions('nodeFetchedData', [workflow?.id, node]);
|
||||
return body;
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -1074,13 +1060,13 @@ async function prepareBinaryData(
|
||||
/**
|
||||
* Makes a request using OAuth data for authentication
|
||||
*
|
||||
* @param {(OptionsWithUri | requestPromise.RequestPromiseOptions)} requestOptions
|
||||
* @param {(OptionsWithUri | RequestPromiseOptions)} requestOptions
|
||||
*
|
||||
*/
|
||||
export async function requestOAuth2(
|
||||
this: IAllExecuteFunctions,
|
||||
credentialsType: string,
|
||||
requestOptions: OptionsWithUri | requestPromise.RequestPromiseOptions | IHttpRequestOptions,
|
||||
requestOptions: OptionsWithUri | RequestPromiseOptions | IHttpRequestOptions,
|
||||
node: INode,
|
||||
additionalData: IWorkflowExecuteAdditionalData,
|
||||
oAuth2Options?: IOAuth2Options,
|
||||
@@ -1311,11 +1297,7 @@ export async function requestOAuth2(
|
||||
export async function requestOAuth1(
|
||||
this: IAllExecuteFunctions,
|
||||
credentialsType: string,
|
||||
requestOptions:
|
||||
| OptionsWithUrl
|
||||
| OptionsWithUri
|
||||
| requestPromise.RequestPromiseOptions
|
||||
| IHttpRequestOptions,
|
||||
requestOptions: OptionsWithUrl | OptionsWithUri | RequestPromiseOptions | IHttpRequestOptions,
|
||||
isN8nRequest = false,
|
||||
) {
|
||||
const credentials = await this.getCredentials(credentialsType);
|
||||
@@ -1569,7 +1551,7 @@ export function normalizeItems(
|
||||
export async function requestWithAuthentication(
|
||||
this: IAllExecuteFunctions,
|
||||
credentialsType: string,
|
||||
requestOptions: OptionsWithUri | requestPromise.RequestPromiseOptions,
|
||||
requestOptions: OptionsWithUri | RequestPromiseOptions,
|
||||
workflow: Workflow,
|
||||
node: INode,
|
||||
additionalData: IWorkflowExecuteAdditionalData,
|
||||
@@ -2228,7 +2210,7 @@ const getRequestHelperFunctions = (
|
||||
async requestOAuth1(
|
||||
this: IAllExecuteFunctions,
|
||||
credentialsType: string,
|
||||
requestOptions: OptionsWithUrl | requestPromise.RequestPromiseOptions,
|
||||
requestOptions: OptionsWithUrl | RequestPromiseOptions,
|
||||
): Promise<any> {
|
||||
return requestOAuth1.call(this, credentialsType, requestOptions);
|
||||
},
|
||||
@@ -2236,7 +2218,7 @@ const getRequestHelperFunctions = (
|
||||
async requestOAuth2(
|
||||
this: IAllExecuteFunctions,
|
||||
credentialsType: string,
|
||||
requestOptions: OptionsWithUri | requestPromise.RequestPromiseOptions,
|
||||
requestOptions: OptionsWithUri | RequestPromiseOptions,
|
||||
oAuth2Options?: IOAuth2Options,
|
||||
): Promise<any> {
|
||||
return requestOAuth2.call(
|
||||
@@ -2732,7 +2714,9 @@ export function getExecuteSingleFunctions(
|
||||
export function getCredentialTestFunctions(): ICredentialTestFunctions {
|
||||
return {
|
||||
helpers: {
|
||||
request: requestPromiseWithDefaults,
|
||||
request: async (uriOrObject: string | object, options?: object) => {
|
||||
return proxyRequestToAxios(undefined, undefined, undefined, uriOrObject, options);
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user