@@ -92,6 +92,41 @@ 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 , 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'
126
+ }
127
+ return result
128
+ }
129
+
95
130
/**
96
131
* Turn scrapfly API response to ScrapeResult or raise one of ScrapflyError
97
132
*/
@@ -173,6 +208,12 @@ export class ScrapflyClient {
173
208
}
174
209
throw new errors . ApiHttpClientError ( JSON . stringify ( data ) ) ;
175
210
}
211
+
212
+ const content_format = data . result . format
213
+ if ( content_format === 'clob' || content_format === 'blob' ) {
214
+ data . result = await this . handleLargeObjects ( data . result , content_format )
215
+ }
216
+
176
217
const result = this . handleResponse (
177
218
response ,
178
219
new ScrapeResult ( {
0 commit comments