Files
warren/frontend/utils/api.ts
2025-07-13 12:35:48 +02:00

22 lines
665 B
TypeScript

export function getApiUrl(path: string): string {
const API_BASE_URL = useRuntimeConfig().public.apiBase;
return `${API_BASE_URL}/${path}`;
}
/**
* Replaces the warren's id in a warren path to its name
* @param path - The warren path (e.g. `a3f79579-9155-4492-a579-b0253c8d3bf8/my-directory/`)
* @returns A prettier path `a3f79579-9155-4492-a579-b0253c8d3bf8/my-directory` -> `my-warren/my-directory`
*/
export function routeWithWarrenName(path: string): string {
const warrens = useWarrenStore().warrens;
const id = path.split('/')[0];
if (!(id in warrens)) {
return path;
}
return path.replace(id, warrens[id].name);
}