Files
warren/frontend/utils/api.ts
2025-08-29 15:32:23 +02:00

28 lines
879 B
TypeScript

import type { Share } from '~/shared/types/shares';
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(warrenId: string, path: string): string {
const warrenStore = useWarrenStore();
if (!(warrenId in warrenStore.warrens)) {
return path;
}
const warrenName = warrenStore.warrens[warrenId].name;
return `${warrenName}${path}`;
}
export function getShareLink(share: Share): string {
return `${window.location.origin}/share?id=${share.id}`;
}