@@ -95,35 +95,34 @@ export class ScrapflyClient {
95
95
/**
96
96
* Handle clob and blob large objects
97
97
*/
98
- async handleLargeObjects ( result : any ) : Promise < ScrapeResult > {
99
- const format = result . format
100
- if ( format === 'clob' || format === 'blob' ) {
101
- let response : Response ;
102
- try {
103
- const url = new URL ( result . content ) ;
104
- const params = { key : this . key } ;
105
- url . search = new URLSearchParams ( params ) . toString ( ) ;
106
- response = await this . fetch ( {
107
- url : url . toString ( ) ,
108
- method : 'GET' ,
109
- headers : {
110
- 'user-agent' : this . ua ,
111
- 'accept-encoding' : 'gzip, deflate, br' ,
112
- accept : 'application/json' ,
113
- } ,
114
- } ) ;
115
- } catch ( e ) {
116
- log . error ( 'error' , e ) ;
117
- throw e ;
118
- }
119
- const content : string = await response . text ( ) ;
120
- result . content = content
121
- if ( format === 'clob' ) {
122
- result . format = 'text'
123
- }
124
- if ( format === 'blob' ) {
125
- result . format = 'binary'
126
- }
98
+ async handleLargeObjects ( result : any , format : "clob" | "blob" ) : Promise < ScrapeResult > {
99
+ let response : Response ;
100
+
101
+ try {
102
+ const url = new URL ( result . content ) ;
103
+ const params = { key : this . key } ;
104
+ url . search = new URLSearchParams ( params ) . toString ( ) ;
105
+ response = await this . fetch ( {
106
+ url : url . toString ( ) ,
107
+ method : 'GET' ,
108
+ headers : {
109
+ 'user-agent' : this . ua ,
110
+ 'accept-encoding' : 'gzip, deflate, br' ,
111
+ accept : 'application/json' ,
112
+ } ,
113
+ } ) ;
114
+ } catch ( e ) {
115
+ log . error ( 'error' , e ) ;
116
+ throw e ;
117
+ }
118
+
119
+ const content : string = await response . text ( ) ;
120
+ result . content = content
121
+ if ( format === 'clob' ) {
122
+ result . format = 'text'
123
+ }
124
+ if ( format === 'blob' ) {
125
+ result . format = 'binary'
127
126
}
128
127
return result
129
128
}
@@ -210,8 +209,11 @@ export class ScrapflyClient {
210
209
throw new errors . ApiHttpClientError ( JSON . stringify ( data ) ) ;
211
210
}
212
211
213
- const content = await this . handleLargeObjects ( data . result )
214
- data . result = content
212
+ const content_format = data . result . format
213
+ if ( content_format === 'clob' || content_format === 'blob' ) {
214
+ const content = await this . handleLargeObjects ( data . result , content_format )
215
+ data . result = content
216
+ }
215
217
216
218
const result = this . handleResponse (
217
219
response ,
0 commit comments