Skip to content

Commit 41cf82b

Browse files
committed
feat: add extract images parameter
1 parent 053c91e commit 41cf82b

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,11 @@ askLinkup()
7575

7676
You 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

src/__tests__/linkup-client.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff 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: {

src/types.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/** biome-ignore-all lint/complexity/noBannedTypes: needed for conditional props */
12
import { ZodObject, ZodRawShape } from 'zod';
23

34
export 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+
8387
export 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[] }>;

0 commit comments

Comments
 (0)