chore: refactor podcast dto to hold different image sizes

This commit is contained in:
2024-04-18 22:54:20 +02:00
parent 21925d101e
commit 9370066464
2 changed files with 18 additions and 4 deletions

View File

@@ -32,7 +32,7 @@ export function Home() {
key={podcast.id}
title={podcast.title}
author={podcast.author}
imageUrl={podcast.imageUrl}
imageUrl={podcast.images.large}
/>
))}
</div>

View File

@@ -1,15 +1,29 @@
import { Entry } from "./podcasts.types";
import { Entry, ImImage } from "./podcasts.types";
export class PodcastDTO {
id: string;
title: string;
author: string;
imageUrl: string;
images: { small: string; medium: string; large: string };
description: string;
constructor(podcast: Entry) {
this.id = podcast.id.attributes["im:id"];
this.title = podcast["im:name"].label;
this.author = podcast["im:artist"].label;
this.imageUrl = podcast["im:image"][0].label;
this.description = podcast["summary"].label;
this.images = this.convertImages(podcast["im:image"]);
}
private convertImages(images: ImImage[]) {
const sortedImages = [...images].sort((a, b) => {
return parseInt(a.attributes.height) - parseInt(b.attributes.height);
});
return {
small: sortedImages[0].label,
medium: sortedImages[1].label,
large: sortedImages[2].label,
};
}
}