diff --git a/src/modules/webtoon/webtoon/webtoon-database.service.ts b/src/modules/webtoon/webtoon/webtoon-database.service.ts index 0d2e9f5..8cd1836 100644 --- a/src/modules/webtoon/webtoon/webtoon-database.service.ts +++ b/src/modules/webtoon/webtoon/webtoon-database.service.ts @@ -264,13 +264,11 @@ export class WebtoonDatabaseService{ } }); const episodeLines: EpisodeLineModel[] = []; - for(const episode of episodes){ - const thumbnailData: Buffer | undefined = this.loadImage(episode.thumbnail.sum); - if(!thumbnailData) - throw new NotFoundException(`Thumbnail not found for episode ${episode.number}`); - const thumbnail: string = this.miscService.bufferToDataURL(thumbnailData); - episodeLines.push(new EpisodeLineModel(episode.id, episode.title, episode.number, thumbnail)); - } + const episodeLinesPromises: Promise[] = []; + for(const episode of episodes) + episodeLinesPromises.push(this.loadEpisodeLine(episode)); + for(const promise of episodeLinesPromises) + episodeLines.push(await promise); return { episodes: episodeLines, backgroundBanner: this.miscService.bufferToDataURL(this.loadImage(dbWebtoon.background_banner.sum)), @@ -280,6 +278,14 @@ export class WebtoonDatabaseService{ } as EpisodesResponse; } + private async loadEpisodeLine(episode: any): Promise{ + const thumbnailData: Buffer | undefined = this.loadImage(episode.thumbnail.sum); + if(!thumbnailData) + throw new NotFoundException(`Thumbnail not found for episode ${episode.number}`); + const thumbnail: string = this.miscService.bufferToDataURL(thumbnailData); + return new EpisodeLineModel(episode.id, episode.title, episode.number, thumbnail); + } + async getEpisodeImages(episodeId: number): Promise{ const episode = await this.prismaService.episodes.findFirst({ where: {