import type { ViewDataBuilder } from '@/lib/contracts/builders/ViewDataBuilder'; import type { MediaBinaryDTO } from '@/lib/types/MediaBinaryDTO'; import type { AvatarViewData } from '@/lib/view-data/AvatarViewData'; export class AvatarViewDataBuilder { public static build(apiDto: MediaBinaryDTO): AvatarViewData { // Note: GetMediaOutputDTO from OpenAPI doesn't have buffer, // but the implementation expects it for binary data. // We use type assertion to handle the binary case while keeping the DTO type. const binaryDto = apiDto as unknown as { buffer?: ArrayBuffer }; const buffer = binaryDto.buffer; const contentType = apiDto.contentType; return { buffer: buffer ? Buffer.from(buffer).toString('base64') : '', contentType, }; } } AvatarViewDataBuilder satisfies ViewDataBuilder;