Files
gridpilot.gg/apps/website/lib/view-models/MediaViewModel.ts
2025-12-18 22:19:40 +01:00

33 lines
986 B
TypeScript

import type { GetMediaOutputDTO } from '../types/generated';
/**
* Media View Model
*
* Represents media information for the UI layer
*/
export class MediaViewModel {
id: string;
url: string;
type: 'image' | 'video' | 'document';
category?: 'avatar' | 'team-logo' | 'league-cover' | 'race-result';
uploadedAt: Date;
size?: number;
constructor(dto: GetMediaOutputDTO) {
this.id = dto.id;
this.url = dto.url;
this.type = dto.type as 'image' | 'video' | 'document';
this.uploadedAt = new Date(dto.uploadedAt);
if (dto.category !== undefined) this.category = dto.category as 'avatar' | 'team-logo' | 'league-cover' | 'race-result';
if (dto.size !== undefined) this.size = dto.size;
}
/** UI-specific: Formatted file size */
get formattedSize(): string {
if (!this.size) return 'Unknown';
const kb = this.size / 1024;
if (kb < 1024) return `${kb.toFixed(2)} KB`;
const mb = kb / 1024;
return `${mb.toFixed(2)} MB`;
}
}