This commit is contained in:
seb
2026-09-27 16:19:43 +02:00
parent 69f27a2942
commit 3e64fff747
13 changed files with 697 additions and 7 deletions

View File

@@ -0,0 +1,54 @@
# `POST /serper/images`
Protected. Requires a valid session cookie (`credentials: 'include'`).
Search images via Serper.dev and stream WebP thumbnails (SSE)
Queries Google Image search via `https://google.serper.dev/images` using the
company setting `keys.serper` (or server `SERPER_API_KEY`), and streams the
results via Server-Sent Events (`text/event-stream`).
1. First emits an `images` event with the full search result list (including `imageUrl`).
2. Then streams `thumb` events with WebP base64 thumbnails (max 200×200) as they are generated.
3. Emits `done` when all thumbnails have completed (or `error` on failure).
## Body (JSON)
```json
{
"q": "Purize logo",
"gl": "de",
"hl": "de",
"num": 100
}
```
## SSE Events
The response is a `text/event-stream`. Events are emitted in order until the stream closes.
| Event | Description | Payload |
|-------|-------------|---------|
| `images` | First event; list of search result images with id, url, width, and height | `{ "images": [ { "id": 0, "url": "…", "width": 1000, "height": 800 } ] }` |
| `thumb` | Emitted for each image as its 200×200 max WebP thumbnail is generated | `{ "id": 0, "dataUrl": "data:image/webp;base64,…" }` |
| `done` | Emitted after all thumbnails have finished streaming; closes the SSE stream | `{ "total": 100 }` |
| `error` | Emitted when an error occurs during Serper request or processing | `{ "error": "…" }` |
## Response `200`
`text/event-stream` — emits `images`, `thumb`, `done` (and `error` on failure).
## Errors
| Status | Description |
|--------|-------------|
| 400 | Query missing, invalid input, or Serper API key not configured — `{"error":"…"}` |
| 401 | Unauthorized — `{"error":"…"}` |
| 403 | Not authorized — `{"error":"…"}` |
| 404 | Company not found — `{"error":"…"}` |
---
_Generated from `@openapi` JSDoc. Do not edit by hand — run `npm run docs:api`._