Files
gridpilot.gg/apps/website/lib/builders/view-data/AvatarViewDataBuilder.ts
2026-01-24 00:52:27 +01:00

24 lines
905 B
TypeScript

'use client';
import type { GetMediaOutputDTO } from '@/lib/types/generated/GetMediaOutputDTO';
import type { AvatarViewData } from '@/lib/view-data/AvatarViewData';
import type { ViewDataBuilder } from '@/lib/contracts/builders/ViewDataBuilder';
export class AvatarViewDataBuilder {
public static build(apiDto: GetMediaOutputDTO): 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.type;
return {
buffer: buffer ? Buffer.from(buffer).toString('base64') : '',
contentType,
};
}
}
AvatarViewDataBuilder satisfies ViewDataBuilder<GetMediaOutputDTO, AvatarViewData>;