feat(shared): add apiToolPath() and section-prefixed routes; drop MODALITY_URL_SLUG

This commit is contained in:
SnapOtter
2026-06-20 11:05:44 +08:00
parent 790747188a
commit 9ca901f8d5
4 changed files with 47 additions and 18 deletions
+14 -8
View File
@@ -1,10 +1,5 @@
import {
AUDIO_INPUTS,
IMAGE_INPUTS,
MODALITY_URL_SLUG,
SUBTITLE_INPUTS,
VIDEO_INPUTS,
} from "./modality.js";
import { AUDIO_INPUTS, IMAGE_INPUTS, SUBTITLE_INPUTS, VIDEO_INPUTS } from "./modality.js";
import { toolSection } from "./section.js";
import type { CategoryInfo, SocialMediaPreset, Tool } from "./types.js";
export const CATEGORIES: CategoryInfo[] = [
@@ -1790,7 +1785,18 @@ export const TOOLS: Tool[] = [
];
for (const tool of TOOLS) {
tool.route = `/${MODALITY_URL_SLUG[tool.modality]}${tool.route}`;
const slug = `/${toolSection(tool)}`;
if (!tool.route.startsWith(`${slug}/`)) {
tool.route = `${slug}${tool.route}`;
}
}
export function apiToolPath(
toolOrId: string | Pick<Tool, "id" | "modality" | "acceptedInputs">,
): string {
const tool = typeof toolOrId === "string" ? TOOLS.find((t) => t.id === toolOrId) : toolOrId;
if (!tool) throw new Error(`apiToolPath: unknown tool "${String(toolOrId)}"`);
return `/api/v1/tools/${toolSection(tool)}/${tool.id}`;
}
export const SOCIAL_MEDIA_PRESETS: SocialMediaPreset[] = [
-8
View File
@@ -117,14 +117,6 @@ export const DOCUMENT_INPUTS = [
];
export const FILE_INPUTS = [".csv", ".json", ".xml", ".yaml", ".yml", ".zip"];
export const MODALITY_URL_SLUG: Record<Modality, string> = {
image: "image",
video: "video",
audio: "audio",
document: "document",
file: "data",
};
export function detectModalityFromMime(mime: string): Modality {
if (mime.startsWith("image/")) return "image";
if (mime.startsWith("video/")) return "video";