mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
Closes #17, #18, #19, #31, #32, #33, #34 Format preservation (#17, #18, #19): - Add resolveOutputFormat to rotate, resize, text-overlay, watermark-text, border, replace-color, blur-faces, upscale, erase-object, restore-photo - Alpha-aware fallback: border with corner radius/shadow and replace-color with makeTransparent fall back to PNG for non-alpha formats (JPEG) - Python sidecar tools (blur-faces, upscale, erase-object) now convert PNG output back to input format, matching restore-photo/colorize pattern - Upscale and erase-object default to "auto" format detection instead of PNG Dispatcher stability (#31, #32): - Add gc.collect() and torch.cuda.empty_cache() after each dispatcher request - Add configurable max_requests (default 50) for periodic dispatcher restart - Add exponential backoff to dispatcher crash recovery in bridge.ts - Circuit breaker: 5 crashes within 60s permanently disables dispatcher - Reset crash counter on successful dispatcher startup Health & security (#33, #34): - Export getDispatcherStatus() from @snapotter/ai with running/ready/failed/ gpu/pid/consecutiveCrashes fields - Admin health endpoint now includes full dispatcher status - Add pip-audit job to CI workflow for Python dependency scanning
42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
import { flip, rotate } from "@snapotter/image-engine";
|
|
import type { FastifyInstance } from "fastify";
|
|
import sharp from "sharp";
|
|
import { z } from "zod";
|
|
import { resolveOutputFormat } from "../../lib/output-format.js";
|
|
import { createToolRoute } from "../tool-factory.js";
|
|
|
|
const settingsSchema = z.object({
|
|
angle: z.number().default(0),
|
|
horizontal: z.boolean().default(false),
|
|
vertical: z.boolean().default(false),
|
|
});
|
|
|
|
export function registerRotate(app: FastifyInstance) {
|
|
createToolRoute(app, {
|
|
toolId: "rotate",
|
|
settingsSchema,
|
|
process: async (inputBuffer, settings, filename) => {
|
|
const outputFormat = await resolveOutputFormat(inputBuffer, filename);
|
|
let image = sharp(inputBuffer);
|
|
|
|
// Apply rotation first
|
|
if (settings.angle !== 0) {
|
|
image = await rotate(image, { angle: settings.angle });
|
|
}
|
|
|
|
// Then apply flip/flop
|
|
if (settings.horizontal || settings.vertical) {
|
|
image = await flip(image, {
|
|
horizontal: settings.horizontal,
|
|
vertical: settings.vertical,
|
|
});
|
|
}
|
|
|
|
const buffer = await image
|
|
.toFormat(outputFormat.format, { quality: outputFormat.quality })
|
|
.toBuffer();
|
|
return { buffer, filename, contentType: outputFormat.contentType };
|
|
},
|
|
});
|
|
}
|