mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
fix(api): section override for backwards-compat alias routes (adjust-colors)
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
||||
ANALYTICS_EVENTS,
|
||||
apiToolPath,
|
||||
getBundleForTool,
|
||||
type Section,
|
||||
TOOL_BUNDLE_MAP,
|
||||
TOOLS,
|
||||
} from "@snapotter/shared";
|
||||
@@ -73,6 +74,12 @@ export type ToolProcessV2 = (ctx: ToolProcessCtxV2) => Promise<ToolProcessResult
|
||||
export interface ToolRouteConfig<T> {
|
||||
/** Unique tool identifier, used as the URL path segment. */
|
||||
toolId: string;
|
||||
/**
|
||||
* Override the URL section for non-catalog alias routes kept for
|
||||
* backwards-compatible URLs (e.g. adjust-colors' brightness-contrast).
|
||||
* Catalog tools omit this; their section is derived via apiToolPath.
|
||||
*/
|
||||
section?: Section;
|
||||
/**
|
||||
* How many file parts the route accepts (default 1). Inputs beyond the
|
||||
* first are validated by the same modality handler and appended to
|
||||
@@ -217,7 +224,9 @@ export function createToolRoute<T>(app: FastifyInstance, config: ToolRouteConfig
|
||||
toolRegistry.set(config.toolId, resolved);
|
||||
|
||||
app.post(
|
||||
apiToolPath(config.toolId),
|
||||
config.section
|
||||
? `/api/v1/tools/${config.section}/${config.toolId}`
|
||||
: apiToolPath(config.toolId),
|
||||
{ config: { rateLimit: { max: 60, timeWindow: "1 minute" } } },
|
||||
async (request: FastifyRequest, reply: FastifyReply) => {
|
||||
// Check per-tool access before processing uploads
|
||||
|
||||
@@ -133,14 +133,20 @@ async function processColorAdjustments(
|
||||
}
|
||||
|
||||
export function registerColorAdjustments(app: FastifyInstance) {
|
||||
const allIds = [
|
||||
"adjust-colors",
|
||||
"brightness-contrast",
|
||||
"saturation",
|
||||
"color-channels",
|
||||
"color-effects",
|
||||
];
|
||||
for (const toolId of allIds) {
|
||||
createToolRoute(app, { toolId, settingsSchema, process: processColorAdjustments });
|
||||
createToolRoute(app, {
|
||||
toolId: "adjust-colors",
|
||||
settingsSchema,
|
||||
process: processColorAdjustments,
|
||||
});
|
||||
// Backwards-compatible alias routes consolidated into adjust-colors. These
|
||||
// ids are not catalog TOOLS, so pass the section explicitly (all image).
|
||||
const aliasIds = ["brightness-contrast", "saturation", "color-channels", "color-effects"];
|
||||
for (const toolId of aliasIds) {
|
||||
createToolRoute(app, {
|
||||
toolId,
|
||||
section: "image",
|
||||
settingsSchema,
|
||||
process: processColorAdjustments,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user