harden media
This commit is contained in:
28
apps/website/lib/utilities/media.ts
Normal file
28
apps/website/lib/utilities/media.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* 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}`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user