Skip to content

Commit 382068c

Browse files
committed
feat: add pagination and download support to getCrawlRequestResults API
1 parent 82104a3 commit 382068c

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

src/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,12 @@ export class WaterCrawlAPIClient extends BaseAPIClient {
8989
});
9090
}
9191

92-
async getCrawlRequestResults(itemId: string): Promise<{ results: CrawlResult[] }> {
93-
return this.get(`/api/v1/core/crawl-requests/${itemId}/results/`);
92+
async getCrawlRequestResults(itemId: string, page?: number, pageSize?: number, download?: boolean): Promise<{ results: CrawlResult[] }> {
93+
return this.get(`/api/v1/core/crawl-requests/${itemId}/results/`, {
94+
page,
95+
page_size: pageSize,
96+
prefetched: download
97+
});
9498
}
9599

96100
/**

test/api.test.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,40 @@ describe('WaterCrawlAPI', () => {
8787
expect(Array.isArray(response.results)).toBe(true);
8888
}, 60000);
8989

90+
test('getCrawlRequestResults with pagination and download', async () => {
91+
// Find a crawl request with results
92+
const crawlList = await api.getCrawlRequestsList();
93+
let targetCrawl: CrawlRequest | undefined;
94+
for (const crawl of crawlList.results) {
95+
const results = await api.getCrawlRequestResults(crawl.uuid);
96+
if (results.results.length > 1) {
97+
targetCrawl = crawl;
98+
break;
99+
}
100+
}
101+
102+
if (!targetCrawl) {
103+
console.log('Skipping pagination test: No suitable crawl with multiple results found.');
104+
return;
105+
}
106+
107+
// Test pagination
108+
const pageSize = 1;
109+
const paginatedResponse = await api.getCrawlRequestResults(targetCrawl.uuid, 1, pageSize);
110+
expect(Array.isArray(paginatedResponse.results)).toBe(true);
111+
expect(paginatedResponse.results.length).toBe(pageSize);
112+
113+
// Test download=true
114+
const downloadResponse = await api.getCrawlRequestResults(targetCrawl.uuid, 1, pageSize, true);
115+
expect(Array.isArray(downloadResponse.results)).toBe(true);
116+
if (downloadResponse.results.length > 0) {
117+
const result = downloadResponse.results[0];
118+
// When downloaded, the result object should be more than just a URL string
119+
expect(typeof result.result).toBe('object');
120+
expect(result.result).not.toBeNull();
121+
}
122+
}, 60000);
123+
90124
test('downloadResult downloads a specific result', async () => {
91125
const resultCrawl = await api.getCrawlRequestsList();
92126
let index = 0;
@@ -123,7 +157,7 @@ describe('WaterCrawlAPI', () => {
123157
const items = await api.getCrawlRequestsList();
124158
const completedItem = items.results.find(
125159
(item) =>
126-
item.status === ('completed' as CrawlStatus) || item.status === ('finished' as CrawlStatus),
160+
item.status === ('finished' as CrawlStatus),
127161
);
128162

129163
if (completedItem) {

0 commit comments

Comments
 (0)