mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
feat: API sync and documentation audit - 100% endpoint coverage (#94)
Code quality: - Add Zod validation to 14 route handlers that used raw JSON.parse (favicon, find-duplicates, barcode-read, upscale, blur-faces, erase-object, colorize, enhance-faces, red-eye-removal, remove-background/effects, auth, api-keys, roles, teams, analytics, settings, user-files) - Standardize error responses to safeParse + formatZodErrors pattern - Replace unsafe `as` type casts with schema validation OpenAPI spec (89 -> 115 operations): - Add 14 missing tool endpoints (adjust-colors, sharpening, optimize-for-web, image-enhancement, noise-removal, red-eye-removal, restore-photo, passport-photo, colorize, enhance-faces, image-to-base64) - Add 12 missing non-tool endpoints (analytics, features, audit-log, roles, admin-health) - Add typed error schemas for 401/403/409 responses - Add descriptions to all path parameters - Bump version from 0.9.0 to 1.15.9 Documentation: - Fix 8 incorrect env var defaults in configuration guide - Add 15 undocumented env vars to configuration guide - Fix tool ID mismatch (color-adjustments -> adjust-colors) - Add 4 new API sections (Roles, Audit Log, Analytics, Features) - Add image-enhancement to AI engine reference - Update AI tool count from 13 to 14 across all docs - Add 6 missing doc links to README
This commit is contained in:
+22
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
The `@ashim/ai` package bridges Node.js to a **persistent Python sidecar** for all ML operations. The dispatcher process stays alive between requests for fast warm-start performance. GPU is auto-detected at startup and used when available.
|
||||
|
||||
13 AI tool routes. All models run locally - no internet required after initial model download.
|
||||
14 AI tool routes. All models run locally - no internet required after initial model download.
|
||||
|
||||
## Architecture
|
||||
|
||||
@@ -216,6 +216,27 @@ GPU-accelerated when an NVIDIA GPU is available.
|
||||
| `upper-body` | 4.5× face | LinkedIn / formal |
|
||||
| `half-body` | 7.0× face | Full upper body |
|
||||
|
||||
## Image Enhancement
|
||||
|
||||
**Function:** `analyzeImage` + `applyCorrections`
|
||||
**Tool route:** `image-enhancement`
|
||||
**Engine:** Analysis-based (Sharp histogram and statistics)
|
||||
|
||||
Analyzes the image and applies automatic corrections for exposure, contrast, white balance, saturation, sharpness, and noise. Supports scene-specific modes.
|
||||
|
||||
| Parameter | Type | Default | Description |
|
||||
|-----------|------|---------|-------------|
|
||||
| `mode` | `auto` \| `portrait` \| `landscape` \| `low-light` \| `food` \| `document` | `auto` | Scene mode for tuning corrections |
|
||||
| `intensity` | number (0-100) | 50 | Overall correction strength |
|
||||
| `corrections.exposure` | boolean | true | Apply exposure correction |
|
||||
| `corrections.contrast` | boolean | true | Apply contrast correction |
|
||||
| `corrections.whiteBalance` | boolean | true | Apply white balance correction |
|
||||
| `corrections.saturation` | boolean | true | Apply saturation correction |
|
||||
| `corrections.sharpness` | boolean | true | Apply sharpness correction |
|
||||
| `corrections.denoise` | boolean | true | Apply denoising |
|
||||
|
||||
An additional analysis endpoint is available at `POST /api/v1/tools/image-enhancement/analyze` which returns the detected corrections without applying them.
|
||||
|
||||
## Content-Aware Resize (Seam Carving)
|
||||
|
||||
**Function:** `seamCarve`
|
||||
|
||||
+59
-3
@@ -25,7 +25,7 @@ curl http://localhost:1349/api/v1/tools/resize \
|
||||
-H "Authorization: Bearer <session-token>"
|
||||
```
|
||||
|
||||
Sessions expire after 24 hours.
|
||||
Sessions expire after 7 days (configurable via `SESSION_DURATION_HOURS`).
|
||||
|
||||
### API Keys
|
||||
|
||||
@@ -69,6 +69,13 @@ Keys are prefixed `si_` and stored as SHA-256 hashes - the raw key is shown once
|
||||
| Manage users & teams | ✓ | - |
|
||||
| Manage branding | ✓ | - |
|
||||
|
||||
## Health Check
|
||||
|
||||
| Method | Path | Access | Description |
|
||||
|--------|------|--------|-------------|
|
||||
| `GET` | `/api/v1/health` | Public | Basic health check. Returns `{"status":"healthy","version":"..."}` with 200, or `{"status":"unhealthy"}` with 503 if the database is unreachable. |
|
||||
| `GET` | `/api/v1/admin/health` | Admin (`system:health`) | Detailed diagnostics including uptime, storage mode, database status, queue state, and GPU availability. |
|
||||
|
||||
## Using Tools
|
||||
|
||||
Every tool follows the same pattern:
|
||||
@@ -120,7 +127,7 @@ curl -X POST http://localhost:1349/api/v1/tools/<toolId>/batch \
|
||||
|
||||
| Tool ID | Name | Key settings |
|
||||
|---------|------|-------------|
|
||||
| `color-adjustments` | Adjust Colors | `brightness`, `contrast`, `exposure`, `saturation`, `temperature`, `sharpness`, `vibrance`, effects (grayscale/sepia/invert/vignette) |
|
||||
| `adjust-colors` | Adjust Colors | `brightness`, `contrast`, `exposure`, `saturation`, `temperature`, `sharpness`, `vibrance`, effects (grayscale/sepia/invert/vignette) |
|
||||
| `sharpening` | Sharpening | `mode` (adaptive/unsharp/highpass), `amount`, `radius`, `threshold` |
|
||||
| `replace-color` | Replace Color | `targetColor`, `replacementColor`, `tolerance`, `invert` |
|
||||
|
||||
@@ -197,7 +204,7 @@ curl -X POST http://localhost:1349/api/v1/tools/compress/batch \
|
||||
-F 'settings={"quality":80}'
|
||||
```
|
||||
|
||||
Limits: up to **200 files** per batch. Concurrency controlled by `CONCURRENT_JOBS` (default: 3).
|
||||
Concurrency is controlled by `CONCURRENT_JOBS` (default: auto-detected from CPU cores). Set `MAX_BATCH_SIZE` to limit the number of files per batch (default: unlimited).
|
||||
|
||||
## Pipelines
|
||||
|
||||
@@ -300,6 +307,55 @@ Runtime key-value configuration (read by any authenticated user, write by admin
|
||||
|
||||
Known keys: `disabledTools` (JSON array of tool IDs), `enableExperimentalTools` (bool string), `loginAttemptLimit` (number), `customLogo` (managed via branding endpoint).
|
||||
|
||||
## Roles
|
||||
|
||||
Custom role management with granular permissions.
|
||||
|
||||
| Method | Path | Access | Description |
|
||||
|--------|------|--------|-------------|
|
||||
| `GET` | `/api/v1/roles` | Admin (`audit:read`) | List all roles with user counts |
|
||||
| `POST` | `/api/v1/roles` | Admin (`users:manage`) | Create a custom role (`name`, `description`, `permissions`) |
|
||||
| `PUT` | `/api/v1/roles/:id` | Admin (`users:manage`) | Update a custom role (cannot modify built-in roles) |
|
||||
| `DELETE` | `/api/v1/roles/:id` | Admin (`users:manage`) | Delete a custom role (cannot delete built-in roles; affected users revert to `user` role) |
|
||||
|
||||
Available permissions: `tools:use`, `files:own`, `files:all`, `apikeys:own`, `apikeys:all`, `pipelines:own`, `pipelines:all`, `settings:read`, `settings:write`, `users:manage`, `teams:manage`, `branding:manage`, `features:manage`, `system:health`, `audit:read`.
|
||||
|
||||
## Audit Log
|
||||
|
||||
Admin-only endpoint for reviewing security-relevant actions.
|
||||
|
||||
| Method | Path | Access | Description |
|
||||
|--------|------|--------|-------------|
|
||||
| `GET` | `/api/v1/audit-log` | Admin (`audit:read`) | Paginated audit log with optional filters |
|
||||
|
||||
Query parameters:
|
||||
|
||||
| Parameter | Description |
|
||||
|-----------|-------------|
|
||||
| `page` | Page number (default: 1) |
|
||||
| `limit` | Entries per page (default: 50, max: 100) |
|
||||
| `action` | Filter by action type (e.g. `ROLE_CREATED`, `ROLE_DELETED`) |
|
||||
| `from` | Filter entries after this ISO 8601 date |
|
||||
| `to` | Filter entries before this ISO 8601 date |
|
||||
|
||||
## Analytics
|
||||
|
||||
| Method | Path | Access | Description |
|
||||
|--------|------|--------|-------------|
|
||||
| `GET` | `/api/v1/config/analytics` | Public | Get analytics configuration (PostHog key, Sentry DSN, sample rate). Returns empty values if `ANALYTICS_ENABLED=false`. |
|
||||
| `PUT` | `/api/v1/user/analytics` | Auth | Set the current user's analytics consent (`enabled: true/false`) or defer with `remindLater: true`. |
|
||||
|
||||
## Features / AI Bundles
|
||||
|
||||
Manage AI feature bundles (install/uninstall AI model packages in the Docker environment).
|
||||
|
||||
| Method | Path | Access | Description |
|
||||
|--------|------|--------|-------------|
|
||||
| `GET` | `/api/v1/features` | Auth | List all feature bundles and their install status |
|
||||
| `POST` | `/api/v1/admin/features/:bundleId/install` | Admin (`features:manage`) | Install a feature bundle (async, returns `jobId` for progress tracking) |
|
||||
| `POST` | `/api/v1/admin/features/:bundleId/uninstall` | Admin (`features:manage`) | Uninstall a feature bundle and clean up model files |
|
||||
| `GET` | `/api/v1/admin/features/disk-usage` | Admin (`features:manage`) | Get total disk usage of AI models |
|
||||
|
||||
## Error Responses
|
||||
|
||||
All errors return JSON:
|
||||
|
||||
Reference in New Issue
Block a user