File tree Expand file tree Collapse file tree 3 files changed +44
-3
lines changed Expand file tree Collapse file tree 3 files changed +44
-3
lines changed Original file line number Diff line number Diff line change @@ -75,9 +75,11 @@ askLinkup()
7575
7676You can use the fetch endpoint to retrieve the content of a given URL in clean ` markdown ` format.
7777
78- You can also use the ` renderJs ` flag to execute the JavaScript code of the page before returning the content.
78+ Use ` renderJs ` to execute the JavaScript code of the page before returning the content.
7979
80- You can also ask to ` includeRawHtml ` if you feel like it.
80+ Use ` includeRawHtml ` to get the raw HTML of the page.
81+
82+ Use ` extractImages ` to get an extracted list of images from the page.
8183
8284#### 📝 Example
8385
Original file line number Diff line number Diff line change @@ -259,6 +259,40 @@ describe('LinkupClient', () => {
259259 } ) ;
260260 } ) ;
261261
262+ it ( 'should handle fetch with extractImages parameter' , async ( ) => {
263+ const mockResponse = {
264+ data : {
265+ images : [
266+ {
267+ alt : 'Image 1' ,
268+ url : 'https://example.com/image.jpg' ,
269+ } ,
270+ ] ,
271+ markdown : 'Fetched content' ,
272+ } ,
273+ } ;
274+ mockAxiosInstance . post . mockResolvedValueOnce ( mockResponse as AxiosResponse ) ;
275+
276+ const result = await underTest . fetch ( {
277+ extractImages : true ,
278+ url : 'https://example.com' ,
279+ } ) ;
280+
281+ expect ( mockAxiosInstance . post ) . toHaveBeenCalledWith ( '/fetch' , {
282+ extractImages : true ,
283+ url : 'https://example.com' ,
284+ } ) ;
285+ expect ( result ) . toEqual ( {
286+ images : [
287+ {
288+ alt : 'Image 1' ,
289+ url : 'https://example.com/image.jpg' ,
290+ } ,
291+ ] ,
292+ markdown : 'Fetched content' ,
293+ } ) ;
294+ } ) ;
295+
262296 it ( 'should handle fetch errors' , async ( ) => {
263297 const fetchError : LinkupApiError = {
264298 error : {
Original file line number Diff line number Diff line change 1+ /** biome-ignore-all lint/complexity/noBannedTypes: needed for conditional props */
12import { ZodObject , ZodRawShape } from 'zod' ;
23
34export type SearchDepth = 'standard' | 'deep' ;
@@ -78,8 +79,12 @@ export interface FetchParams {
7879 url : string ;
7980 renderJs ?: boolean ;
8081 includeRawHtml ?: boolean ;
82+ extractImages ?: boolean ;
8183}
8284
85+ type ConditionalProp < Condition , PropType > = Condition extends true ? PropType : { } ;
86+
8387export type LinkupFetchResponse < T extends FetchParams = FetchParams > = {
8488 markdown : string ;
85- } & ( T [ 'includeRawHtml' ] extends true ? { rawHtml : string } : Record < string , never > ) ;
89+ } & ConditionalProp < T [ 'includeRawHtml' ] , { rawHtml : string } > &
90+ ConditionalProp < T [ 'extractImages' ] , { images : string [ ] } > ;
You can’t perform that action at this time.
0 commit comments