feat(api): add generic tool route factory for all image tools

- createToolRoute<T> factory: handles multipart parsing, file validation,
  Zod settings validation, workspace management, and error handling
- Each tool only needs to provide toolId, settingsSchema, and process function
- Registers POST /api/v1/tools/:toolId routes automatically
- Tool registry stub at routes/tools/index.ts ready for tool implementations
- Catches Sharp errors and returns clean API error envelopes (422)
This commit is contained in:
Siddharth Kumar Sah
2026-03-22 03:48:11 +08:00
parent ece341e8c4
commit d53f6733b8
3 changed files with 172 additions and 0 deletions
+15
View File
@@ -0,0 +1,15 @@
import type { FastifyInstance } from "fastify";
/**
* Registry that imports and registers all tool routes.
* Each tool uses the createToolRoute factory from tool-factory.ts.
*
* Tools will be added here as they are implemented in Phase 2 Tasks 4-10.
*/
export async function registerToolRoutes(app: FastifyInstance): Promise<void> {
// Tool routes will be registered here as they are implemented.
// Example:
// const { registerResizeTool } = await import("./resize.js");
// registerResizeTool(app);
app.log.info("Tool routes registered");
}