31 lines
926 B
TypeScript
31 lines
926 B
TypeScript
import type { IGetMediaPresenter, GetMediaResult } from '@core/media/application/presenters/IGetMediaPresenter';
|
|
import type { GetMediaOutputDTO } from '../dtos/GetMediaOutputDTO';
|
|
|
|
// The HTTP-facing DTO (or null when not found)
|
|
export type GetMediaViewModel = GetMediaOutputDTO | null;
|
|
|
|
export class GetMediaPresenter implements IGetMediaPresenter {
|
|
private result: GetMediaResult | null = null;
|
|
|
|
present(result: GetMediaResult) {
|
|
this.result = result;
|
|
}
|
|
|
|
get viewModel(): GetMediaViewModel {
|
|
if (!this.result || !this.result.success || !this.result.media) {
|
|
return null;
|
|
}
|
|
|
|
const media = this.result.media;
|
|
|
|
return {
|
|
id: media.id,
|
|
url: media.url,
|
|
type: media.type,
|
|
// Best-effort mapping from arbitrary metadata
|
|
category: (media.metadata as { category?: string } | undefined)?.category,
|
|
uploadedAt: media.uploadedAt,
|
|
size: media.size,
|
|
};
|
|
}
|
|
} |