24 lines
892 B
TypeScript
24 lines
892 B
TypeScript
|
|
|
|
import type { ViewDataBuilder } from '@/lib/contracts/builders/ViewDataBuilder';
|
|
import type { GetMediaOutputDTO } from '@/lib/types/generated/GetMediaOutputDTO';
|
|
import type { AvatarViewData } from '@/lib/view-data/AvatarViewData';
|
|
|
|
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>;
|