fix(api): section override for backwards-compat alias routes (adjust-colors)

This commit is contained in:
SnapOtter
2026-06-20 12:02:00 +08:00
parent 414f126a33
commit fc205c7428
2 changed files with 25 additions and 10 deletions
+10 -1
View File
@@ -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
+15 -9
View File
@@ -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,
});
}
}