1+ import { cloneDeep } from 'lodash' ;
12import { computeNodeVariables , computeVariables } from '../compute/utils' ;
23import { LogLevel } from '../GraphLogger' ;
34import Node from './node' ;
45
56class requestNode extends Node {
6- constructor ( nodeData , prevNodeOutputData , envVariables , auth , logger ) {
7+ constructor ( nodeData , prevNodeOutputData , envVariables , auth , logger , collectionPath ) {
78 super ( 'requestNode' ) ;
89 this . nodeData = nodeData ;
910 this . prevNodeOutputData = prevNodeOutputData ;
1011 this . envVariables = envVariables ;
1112 this . auth = auth ;
1213 this . logger = logger ;
14+ this . collectionPath = collectionPath ;
1315 }
1416
1517 async evaluate ( ) {
@@ -28,14 +30,10 @@ class requestNode extends Node {
2830 console . debug ( 'Evaluated Url: ' , finalUrl ) ;
2931
3032 // step 3
31- const options = this . formulateRequest ( finalUrl , variablesDict ) ;
33+ const options = await this . formulateRequest ( finalUrl , variablesDict ) ;
3234
3335 const res = await this . runHttpRequest ( options ) ;
3436
35- if ( this . nodeData ?. requestBody ?. type === 'form-data' ) {
36- options . data . value = '<BASE64_ENCODED_FILE_DATA>' ;
37- }
38-
3937 if ( res . error ) {
4038 this . logger . add ( LogLevel . ERROR , 'HTTP request failed' , {
4139 type : 'requestNode' ,
@@ -81,7 +79,7 @@ class requestNode extends Node {
8179 }
8280 }
8381
84- formulateRequest ( finalUrl , variablesDict ) {
82+ async formulateRequest ( finalUrl , variablesDict ) {
8583 let restMethod = this . nodeData . requestType . toLowerCase ( ) ;
8684 let contentType = 'application/json' ;
8785 let requestData = undefined ;
@@ -94,19 +92,16 @@ class requestNode extends Node {
9492 : JSON . parse ( '{}' ) ;
9593 } else if ( this . nodeData . requestBody . type === 'form-data' ) {
9694 contentType = 'multipart/form-data' ;
97- requestData = {
98- key : computeVariables ( this . nodeData . requestBody . body . key , variablesDict ) ,
99- value : this . nodeData . requestBody . body . value ,
100- name : this . nodeData . requestBody . body . name ,
101- } ;
95+ const params = cloneDeep ( this . nodeData . requestBody . body ) ;
96+ requestData = params ;
10297 }
10398 }
10499
105100 const options = {
106101 method : restMethod ,
107102 url : finalUrl ,
108103 headers : {
109- 'Content -type' : contentType ,
104+ 'content -type' : contentType ,
110105 } ,
111106 data : requestData ,
112107 } ;
@@ -124,7 +119,7 @@ class requestNode extends Node {
124119 const { ipcRenderer } = window ;
125120
126121 return new Promise ( ( resolve , reject ) => {
127- ipcRenderer . invoke ( 'renderer:run-http-request' , request ) . then ( resolve ) . catch ( reject ) ;
122+ ipcRenderer . invoke ( 'renderer:run-http-request' , request , this . collectionPath ) . then ( resolve ) . catch ( reject ) ;
128123 } ) ;
129124 }
130125}
0 commit comments