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:
|
||||
|
||||
@@ -43,7 +43,7 @@ Shared TypeScript types, constants (like `APP_VERSION` and tool definitions), an
|
||||
|
||||
### API (`apps/api`)
|
||||
|
||||
A Fastify v5 server exposing 47 tool routes (34 standard image operations + 13 AI-powered) that handles:
|
||||
A Fastify v5 server exposing 47 tool routes (33 standard image operations + 14 AI-powered) that handles:
|
||||
- File uploads, temporary workspace management, and persistent file storage
|
||||
- User file library with version chains (`user_files` table) -- each processed result links back to its source file and records which tool was applied, with auto-generated thumbnails for the Files page
|
||||
- Tool execution (routes each tool request to the image engine or AI bridge)
|
||||
|
||||
@@ -9,7 +9,10 @@ All configuration is done through environment variables. Every variable has a se
|
||||
| Variable | Default | Description |
|
||||
|---|---|---|
|
||||
| `PORT` | `1349` | Port the server listens on. |
|
||||
| `RATE_LIMIT_PER_MIN` | `100` | Maximum requests per minute per IP. |
|
||||
| `RATE_LIMIT_PER_MIN` | `0` (disabled) | Maximum requests per minute per IP. Set to 0 to disable rate limiting. |
|
||||
| `CORS_ORIGIN` | (empty) | Comma-separated allowed origins for CORS, or empty for same-origin only. |
|
||||
| `LOG_LEVEL` | `info` | Log verbosity. One of: `fatal`, `error`, `warn`, `info`, `debug`, `trace`. |
|
||||
| `TRUST_PROXY` | `true` | Trust `X-Forwarded-For` headers from a reverse proxy. Set to `false` if not behind a proxy. |
|
||||
|
||||
### Authentication
|
||||
|
||||
@@ -18,7 +21,8 @@ All configuration is done through environment variables. Every variable has a se
|
||||
| `AUTH_ENABLED` | `false` | Set to `true` to require login. The Docker image defaults to `true`. |
|
||||
| `DEFAULT_USERNAME` | `admin` | Username for the initial admin account. Only used on first run. |
|
||||
| `DEFAULT_PASSWORD` | `admin` | Password for the initial admin account. Change this after first login. |
|
||||
| `MAX_USERS` | `5` | Maximum number of registered user accounts |
|
||||
| `MAX_USERS` | `0` (unlimited) | Maximum number of registered user accounts. Set to 0 for unlimited. |
|
||||
| `SESSION_DURATION_HOURS` | `168` | Login session lifetime in hours (default is 7 days). |
|
||||
| `SKIP_MUST_CHANGE_PASSWORD` | - | Set to any non-empty value to bypass the forced password-change prompt on first login |
|
||||
|
||||
### Storage
|
||||
@@ -34,17 +38,25 @@ All configuration is done through environment variables. Every variable has a se
|
||||
|
||||
| Variable | Default | Description |
|
||||
|---|---|---|
|
||||
| `MAX_UPLOAD_SIZE_MB` | `100` | Maximum file size per upload in megabytes. |
|
||||
| `MAX_BATCH_SIZE` | `200` | Maximum number of files in a single batch request. |
|
||||
| `CONCURRENT_JOBS` | `3` | Number of batch jobs that run in parallel. Higher values use more memory. |
|
||||
| `MAX_MEGAPIXELS` | `100` | Maximum image resolution allowed. Rejects images larger than this. |
|
||||
| `MAX_UPLOAD_SIZE_MB` | `0` (unlimited) | Maximum file size per upload in megabytes. Set to 0 for unlimited. |
|
||||
| `MAX_BATCH_SIZE` | `0` (unlimited) | Maximum number of files in a single batch request. Set to 0 for unlimited. |
|
||||
| `CONCURRENT_JOBS` | `0` (auto) | Number of batch jobs that run in parallel. Set to 0 to auto-detect based on available CPU cores. |
|
||||
| `MAX_MEGAPIXELS` | `0` (unlimited) | Maximum image resolution allowed in megapixels. Set to 0 for unlimited. |
|
||||
| `MAX_WORKER_THREADS` | `0` (auto) | Maximum worker threads for image processing. Set to 0 to auto-detect based on available CPU cores. |
|
||||
| `PROCESSING_TIMEOUT_S` | `0` (no limit) | Maximum processing time per request in seconds. Set to 0 for no timeout. |
|
||||
| `MAX_PIPELINE_STEPS` | `0` (no limit) | Maximum number of steps in a pipeline. Set to 0 for no limit. |
|
||||
| `MAX_CANVAS_PIXELS` | `0` (no limit) | Maximum canvas size in pixels for output images. Set to 0 for no limit. |
|
||||
| `MAX_SVG_SIZE_MB` | `0` (unlimited) | Maximum SVG file size in megabytes. Set to 0 for unlimited. |
|
||||
| `MAX_LOGO_SIZE_KB` | `500` | Maximum custom branding logo size in kilobytes. |
|
||||
| `MAX_SPLIT_GRID` | `100` | Maximum grid dimension for the image split tool. |
|
||||
| `MAX_PDF_PAGES` | `0` (unlimited) | Maximum number of PDF pages for PDF-to-image conversion. Set to 0 for unlimited. |
|
||||
|
||||
### Cleanup
|
||||
|
||||
| Variable | Default | Description |
|
||||
|---|---|---|
|
||||
| `FILE_MAX_AGE_HOURS` | `24` | How long temporary files are kept before automatic deletion. |
|
||||
| `CLEANUP_INTERVAL_MINUTES` | `30` | How often the cleanup job runs. |
|
||||
| `FILE_MAX_AGE_HOURS` | `72` | How long temporary files are kept before automatic deletion. |
|
||||
| `CLEANUP_INTERVAL_MINUTES` | `60` | How often the cleanup job runs. |
|
||||
|
||||
### Appearance
|
||||
|
||||
@@ -54,6 +66,13 @@ All configuration is done through environment variables. Every variable has a se
|
||||
| `DEFAULT_THEME` | `light` | Default theme for new sessions. `light` or `dark`. |
|
||||
| `DEFAULT_LOCALE` | `en` | Default interface language. |
|
||||
|
||||
### Docker permissions
|
||||
|
||||
| Variable | Default | Description |
|
||||
|---|---|---|
|
||||
| `PUID` | `999` | Run the container process as this UID. Set to match your host user for bind mounts (`id -u`). |
|
||||
| `PGID` | `999` | Run the container process as this GID. Set to match your host group for bind mounts (`id -g`). |
|
||||
|
||||
## Docker example
|
||||
|
||||
```yaml
|
||||
|
||||
@@ -214,5 +214,5 @@ See the [Configuration guide](/guide/configuration) for the full list. Key ones
|
||||
| `DEFAULT_USERNAME` | `admin` | Default admin username |
|
||||
| `DEFAULT_PASSWORD` | `admin` | Default admin password |
|
||||
| `SKIP_MUST_CHANGE_PASSWORD` | `false` | Skip forced password change (CI/dev only) |
|
||||
| `RATE_LIMIT_PER_MIN` | `100` | API rate limit per minute |
|
||||
| `MAX_UPLOAD_SIZE_MB` | `100` | Maximum upload size in MB |
|
||||
| `RATE_LIMIT_PER_MIN` | `0` | API rate limit per minute (0 = disabled) |
|
||||
| `MAX_UPLOAD_SIZE_MB` | `0` | Maximum upload size in MB (0 = unlimited) |
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ features:
|
||||
- title: 45+ Image Tools
|
||||
details: Resize, crop, compress, convert, watermark, color adjust, vectorize, create GIFs, build collages, generate passport photos, find duplicates, and more.
|
||||
- title: Local AI
|
||||
details: 13 AI-powered tools - remove backgrounds, upscale, restore and colorize old photos, erase objects, blur faces, enhance faces, extract text (OCR). All on your hardware, no internet required.
|
||||
details: 14 AI-powered tools - remove backgrounds, upscale, enhance images, restore and colorize old photos, erase objects, blur faces, enhance faces, extract text (OCR). All on your hardware, no internet required.
|
||||
- title: Pipelines
|
||||
details: Chain tools into reusable workflows with up to 20 steps. Batch process up to 200 images at once with a single request.
|
||||
- title: REST API
|
||||
|
||||
Reference in New Issue
Block a user