@@ -3,18 +3,19 @@ import { handleBody, HTTPRequest_Extract_Parameters } from './requestBodyBuilder
33import type { ScrappeyRequestBody } from './types' ;
44import { genericHttpRequest } from './GenericFunctions' ;
55
6- export const PostRequest = async function ( this : IExecuteFunctions ) {
7- const body = await handleBody ( this ) ;
6+ export const PostRequest = async function ( this : IExecuteFunctions , itemIndex : number = 0 ) {
7+ const body = await handleBody ( this , itemIndex ) ;
88 const response = await genericHttpRequest . call ( this , 'POST' , '' , { body } ) ;
99 return response ;
1010} ;
1111
12- export const AutoRetryTypeBrowser = async function ( this : IExecuteFunctions ) {
13- const prev_HTTPRequest = await HTTPRequest_Extract_Parameters ( this ) ;
14- const proxyType = this . getNodeParameter ( 'proxyType' , 0 , '' ) as string ;
12+ export const AutoRetryTypeBrowser = async function ( this : IExecuteFunctions , itemIndex : number = 0 ) {
13+ const prev_HTTPRequest = await HTTPRequest_Extract_Parameters ( this , itemIndex ) ;
14+
15+ const proxyType = this . getNodeParameter ( 'proxyType' , itemIndex , '' ) as string ;
1516 const whichProxyToUse = this . getNodeParameter (
1617 'whichProxyToUse' ,
17- 0 ,
18+ itemIndex ,
1819 'proxyFromCredentials' ,
1920 ) as string ;
2021
@@ -33,20 +34,18 @@ export const AutoRetryTypeBrowser = async function (this: IExecuteFunctions) {
3334
3435 // Handle proxy settings based on the selected proxy source
3536 if ( whichProxyToUse === 'proxyFromScrappey' ) {
36- // Apply proxy type
3737 if ( proxyType && proxyType . trim ( ) !== '' ) {
3838 body [ proxyType ] = true ;
3939 }
4040
41- // Check if custom proxy country is enabled
4241 const customProxyCountryBoolean = this . getNodeParameter (
4342 'customProxyCountryBoolean' ,
44- 0 ,
43+ itemIndex ,
4544 false ,
4645 ) as boolean ;
4746
4847 if ( customProxyCountryBoolean ) {
49- const customProxyCountry = this . getNodeParameter ( 'customProxyCountry' , 0 , '' ) as string ;
48+ const customProxyCountry = this . getNodeParameter ( 'customProxyCountry' , itemIndex , '' ) as string ;
5049 if ( customProxyCountry && customProxyCountry . trim ( ) !== '' ) {
5150 body . country = customProxyCountry ;
5251 }
@@ -59,53 +58,65 @@ export const AutoRetryTypeBrowser = async function (this: IExecuteFunctions) {
5958 if ( prev_HTTPRequest . processedPostData ) {
6059 body . postData = prev_HTTPRequest . processedPostData ;
6160
62- if ( prev_HTTPRequest . contentType ) {
61+ if ( prev_HTTPRequest . contentType && body . customHeaders ) {
6362 body . customHeaders [ 'content-type' ] = prev_HTTPRequest . contentType ;
6463 }
6564 }
65+
6666 const response = await genericHttpRequest . call ( this , 'POST' , '' , { body } ) ;
6767 return response ;
6868} ;
6969
70- export const AutoRetryTypeRequest = async function ( this : IExecuteFunctions ) {
71- const prev_HTTPRequest = await HTTPRequest_Extract_Parameters ( this ) ;
72- const customProxyCountry = this . getNodeParameter ( 'customProxyCountry' , 0 , '' ) as string ;
70+ export const AutoRetryTypeRequest = async function ( this : IExecuteFunctions , itemIndex : number = 0 ) {
71+ const prev_HTTPRequest = await HTTPRequest_Extract_Parameters ( this , itemIndex ) ;
72+
73+ const customProxyCountry = this . getNodeParameter ( 'customProxyCountry' , itemIndex , '' ) as string ;
7374 const customProxyCountryBoolean = this . getNodeParameter (
7475 'customProxyCountryBoolean' ,
75- 0 ,
76+ itemIndex ,
7677 false ,
7778 ) as boolean ;
78- const proxyType = this . getNodeParameter ( 'proxyType' , 0 , '' ) as string ;
79+ const proxyType = this . getNodeParameter ( 'proxyType' , itemIndex , '' ) as string ;
7980
8081 let body : ScrappeyRequestBody = {
8182 cmd : prev_HTTPRequest . cmd ,
8283 url : prev_HTTPRequest . url as string ,
84+ requestType : 'request' , // Add this to ensure it's a request type
8385 } ;
8486
8587 if ( prev_HTTPRequest . processedHeaders ) {
8688 body . customHeaders = prev_HTTPRequest . processedHeaders ;
8789 }
8890
89- if ( prev_HTTPRequest . processedProxy ) {
91+ const whichProxyToUse = this . getNodeParameter (
92+ 'whichProxyToUse' ,
93+ itemIndex ,
94+ 'proxyFromCredentials' ,
95+ ) as string ;
96+
97+ if ( whichProxyToUse === 'proxyFromNode' && prev_HTTPRequest . processedProxy ) {
9098 body . proxy = prev_HTTPRequest . processedProxy ;
91- } else {
99+ } else if ( whichProxyToUse === 'proxyFromScrappey' ) {
92100 if ( customProxyCountryBoolean ) {
93101 body . proxyCountry = customProxyCountry ;
94102 }
95- }
96-
97- if ( proxyType && proxyType . trim ( ) !== '' ) {
98- body [ proxyType ] = true ;
103+
104+ if ( proxyType && proxyType . trim ( ) !== '' ) {
105+ body [ proxyType ] = true ;
106+ }
99107 }
100108
101109 if ( prev_HTTPRequest . processedPostData ) {
102110 body . postData = prev_HTTPRequest . processedPostData ;
103111
104112 if ( prev_HTTPRequest . contentType ) {
113+ if ( ! body . customHeaders ) {
114+ body . customHeaders = { } ;
115+ }
105116 body . customHeaders [ 'content-type' ] = prev_HTTPRequest . contentType ;
106117 }
107118 }
119+
108120 const response = await genericHttpRequest . call ( this , 'POST' , '' , { body } ) ;
109121 return response ;
110- // return { body };
111- } ;
122+ } ;
0 commit comments