Skip to content

Commit

Permalink
feat(mangadex): add cover image (#94)
Browse files Browse the repository at this point in the history
added a cover image in mangaInfo payload for the mangadex provider
  • Loading branch information
tyo authored Nov 1, 2022
1 parent 5047e6f commit 5144054
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/providers/manga/mangadex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,17 @@ class MangaDex extends MangaParser {
};

const allChapters = await this.fetchAllChapters(mangaId, 0);

for (const chapter of allChapters) {
mangaInfo.chapters?.push({
id: chapter.id,
title: chapter.attributes.title ? chapter.attributes.title : chapter.attributes.chapter,
pages: chapter.attributes.pages,
});
}

const coverArt = await this.fetchCoverImage(data.data.relationships[2].id);
mangaInfo.image = `${this.baseUrl}/covers/${mangaInfo.id}/${coverArt}`;

return mangaInfo;
} catch (err) {
if ((err as AxiosError).code == 'ERR_BAD_REQUEST') {
Expand Down Expand Up @@ -139,6 +142,14 @@ class MangaDex extends MangaParser {

return [...response.data.data, ...(await this.fetchAllChapters(mangaId, offset + 96, response))];
};

private fetchCoverImage = async (coverId: string): Promise<string> => {
const { data } = await axios.get(`${this.apiUrl}/cover/${coverId}`);

const fileName = data.data.attributes.fileName;

return fileName;
};
}

export default MangaDex;

0 comments on commit 5144054

Please sign in to comment.