mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
feat(shared): add apiToolPath() and section-prefixed routes; drop MODALITY_URL_SLUG
This commit is contained in:
@@ -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[] = [
|
||||
|
||||
@@ -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";
|
||||
|
||||
Reference in New Issue
Block a user