feat: add POST /v1/screenshots/batch endpoint
Some checks failed
Build & Deploy to Staging / Build & Deploy to Staging (push) Has been cancelled
Some checks failed
Build & Deploy to Staging / Build & Deploy to Staging (push) Has been cancelled
- Batch screenshot endpoint: take 1-10 screenshots in a single request - Concurrent processing with Promise.allSettled (partial success support) - Upfront quota check for all URLs before processing - Per-URL SSRF validation via existing takeScreenshot() - Added incrementUsage() to usage middleware for granular tracking - 10 new tests covering all edge cases - Updated OpenAPI docs (JSDoc on route) - Updated Node.js and Python SDK READMEs with batch method docs
This commit is contained in:
parent
65d2fd38cc
commit
8a36826e35
6 changed files with 506 additions and 0 deletions
|
|
@ -216,6 +216,30 @@ Returns a `Promise<Buffer>` containing the screenshot image.
|
|||
| `css` | `string` | — | Custom CSS to inject before capture (max 5000 chars) |
|
||||
| `clip` | `object` | — | Crop rectangle: `{x, y, width, height}` (mutually exclusive with fullPage/selector) |
|
||||
|
||||
### `snap.batch(urls, options?)`
|
||||
|
||||
Take multiple screenshots in a single request. Each URL counts as one screenshot toward usage limits.
|
||||
|
||||
```typescript
|
||||
const results = await snap.batch(
|
||||
['https://example.com', 'https://example.org'],
|
||||
{ format: 'jpeg', width: 1920, height: 1080 }
|
||||
);
|
||||
|
||||
for (const result of results) {
|
||||
if (result.status === 'success') {
|
||||
fs.writeFileSync(`${result.url}.jpg`, Buffer.from(result.image, 'base64'));
|
||||
} else {
|
||||
console.error(`Failed: ${result.url} — ${result.error}`);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
- **Max 10 URLs per batch**
|
||||
- All options (format, width, height, etc.) are shared across all URLs
|
||||
- Returns partial results — some may succeed while others fail
|
||||
- Response is always JSON with `{ results: [...] }`
|
||||
|
||||
### `snap.health()`
|
||||
|
||||
Returns API health status.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue