@@ -92,6 +92,42 @@ export class ScrapflyClient {
92
92
return new errors . ScrapflyError ( message , args ) ;
93
93
}
94
94
95
+ /**
96
+ * Handle clob and blob large objects
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
+ }
127
+ }
128
+ return result
129
+ }
130
+
95
131
/**
96
132
* Turn scrapfly API response to ScrapeResult or raise one of ScrapflyError
97
133
*/
@@ -173,6 +209,10 @@ export class ScrapflyClient {
173
209
}
174
210
throw new errors . ApiHttpClientError ( JSON . stringify ( data ) ) ;
175
211
}
212
+
213
+ const content = await this . handleLargeObjects ( data . result )
214
+ data . result = content
215
+
176
216
const result = this . handleResponse (
177
217
response ,
178
218
new ScrapeResult ( {
0 commit comments