mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
- Rewrite OpenAPI spec to match actual code (988 lines changed):
- Fix ToolResponse schema (add previewUrl, savedFileId)
- Fix Error schema shape ({error, details} not {statusCode, error, message})
- Fix POST /api/auth/register URL (was /api/auth/users)
- Fix login/session responses (7 missing user fields + expiresAt)
- Fix 8 endpoints returning 204 → 200 with {ok: true}
- Fix pipeline execute field name (steps → pipeline)
- Fix API keys response key (keys → apiKeys)
- Fix settings response wrapper, teams UUID type
- Rewrite 7 major tool response schemas (info, barcode-read,
find-duplicates, compare, remove-background, upscale, ocr, blur-faces)
- Fix files/save-result (JSON → multipart), files/upload (201 + array)
- Fix SSE progress schema (integers not arrays)
- Add 422/501 error responses to AI and processing tools
- Fix settings required → optional on 29 tool endpoints
- Add 5 missing color adjustment fields to alias endpoints
- Rewrite rest.md tool parameter descriptions (12 tools fixed)
- Add Tool Sub-Routes section to rest.md (11 endpoints)
- Fix file library, settings, pipeline, auth docs in rest.md
- Fix API key hashing description (SHA-256 → scrypt)
- Fix "GitHub Pages" → "Cloudflare Pages" in architecture + deployment docs
- Fix tool count "45+" → "47" across all doc surfaces
- Fix branding endpoint paths in rest.md (/branding/logo → /settings/logo)
42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
import type { ResizeOptions, Sharp } from "../types.js";
|
|
|
|
export async function resize(image: Sharp, options: ResizeOptions): Promise<Sharp> {
|
|
let { width, height, fit, withoutEnlargement, percentage } = options;
|
|
|
|
if (percentage !== undefined) {
|
|
if (percentage <= 0) {
|
|
throw new Error("Resize percentage must be greater than 0");
|
|
}
|
|
const metadata = await image.metadata();
|
|
const currentWidth = metadata.width ?? 0;
|
|
const currentHeight = metadata.height ?? 0;
|
|
width = Math.round(currentWidth * (percentage / 100));
|
|
height = Math.round(currentHeight * (percentage / 100));
|
|
}
|
|
|
|
if (width !== undefined && width <= 0) {
|
|
throw new Error("Resize width must be greater than 0");
|
|
}
|
|
if (height !== undefined && height <= 0) {
|
|
throw new Error("Resize height must be greater than 0");
|
|
}
|
|
if (width === undefined && height === undefined) {
|
|
throw new Error("Resize requires width, height, or percentage");
|
|
}
|
|
|
|
if (withoutEnlargement) {
|
|
const meta = await image.metadata();
|
|
const curW = meta.width ?? 0;
|
|
const curH = meta.height ?? 0;
|
|
if (width !== undefined && width > curW) width = curW;
|
|
if (height !== undefined && height > curH) height = curH;
|
|
}
|
|
|
|
return image.resize({
|
|
width,
|
|
height,
|
|
fit: fit ?? "cover",
|
|
withoutEnlargement: withoutEnlargement ?? false,
|
|
});
|
|
}
|