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,
|
ANALYTICS_EVENTS,
|
||||||
apiToolPath,
|
apiToolPath,
|
||||||
getBundleForTool,
|
getBundleForTool,
|
||||||
|
type Section,
|
||||||
TOOL_BUNDLE_MAP,
|
TOOL_BUNDLE_MAP,
|
||||||
TOOLS,
|
TOOLS,
|
||||||
} from "@snapotter/shared";
|
} from "@snapotter/shared";
|
||||||
@@ -73,6 +74,12 @@ export type ToolProcessV2 = (ctx: ToolProcessCtxV2) => Promise<ToolProcessResult
|
|||||||
export interface ToolRouteConfig<T> {
|
export interface ToolRouteConfig<T> {
|
||||||
/** Unique tool identifier, used as the URL path segment. */
|
/** Unique tool identifier, used as the URL path segment. */
|
||||||
toolId: string;
|
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
|
* How many file parts the route accepts (default 1). Inputs beyond the
|
||||||
* first are validated by the same modality handler and appended to
|
* 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);
|
toolRegistry.set(config.toolId, resolved);
|
||||||
|
|
||||||
app.post(
|
app.post(
|
||||||
apiToolPath(config.toolId),
|
config.section
|
||||||
|
? `/api/v1/tools/${config.section}/${config.toolId}`
|
||||||
|
: apiToolPath(config.toolId),
|
||||||
{ config: { rateLimit: { max: 60, timeWindow: "1 minute" } } },
|
{ config: { rateLimit: { max: 60, timeWindow: "1 minute" } } },
|
||||||
async (request: FastifyRequest, reply: FastifyReply) => {
|
async (request: FastifyRequest, reply: FastifyReply) => {
|
||||||
// Check per-tool access before processing uploads
|
// Check per-tool access before processing uploads
|
||||||
|
|||||||
@@ -133,14 +133,20 @@ async function processColorAdjustments(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function registerColorAdjustments(app: FastifyInstance) {
|
export function registerColorAdjustments(app: FastifyInstance) {
|
||||||
const allIds = [
|
createToolRoute(app, {
|
||||||
"adjust-colors",
|
toolId: "adjust-colors",
|
||||||
"brightness-contrast",
|
settingsSchema,
|
||||||
"saturation",
|
process: processColorAdjustments,
|
||||||
"color-channels",
|
});
|
||||||
"color-effects",
|
// Backwards-compatible alias routes consolidated into adjust-colors. These
|
||||||
];
|
// ids are not catalog TOOLS, so pass the section explicitly (all image).
|
||||||
for (const toolId of allIds) {
|
const aliasIds = ["brightness-contrast", "saturation", "color-channels", "color-effects"];
|
||||||
createToolRoute(app, { toolId, settingsSchema, process: processColorAdjustments });
|
for (const toolId of aliasIds) {
|
||||||
|
createToolRoute(app, {
|
||||||
|
toolId,
|
||||||
|
section: "image",
|
||||||
|
settingsSchema,
|
||||||
|
process: processColorAdjustments,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user