Files
2025-12-31 15:39:28 +01:00

28 lines
831 B
TypeScript

/**
* Media utilities for handling image URLs and placeholders
*/
export type MediaType = 'driver-avatar' | 'team-logo' | 'league-logo' | 'league-cover';
/**
* Get media URL for generated assets when only ID is available
* Returns canonical /media/... paths that match the API routes
*
* @param type - The type of media
* @param id - The entity ID
* @returns Canonical path like /media/teams/{id}/logo
*/
export function getMediaUrl(type: MediaType, id: string): string {
switch (type) {
case 'driver-avatar':
return `/media/avatar/${id}`;
case 'team-logo':
return `/media/teams/${id}/logo`;
case 'league-logo':
return `/media/leagues/${id}/logo`;
case 'league-cover':
return `/media/leagues/${id}/cover`;
default:
throw new Error(`Unknown media type: ${type}`);
}
}