Skip to content

Commit

Permalink
Have to page when there's a million volumes for one manga, annoyingly…
Browse files Browse the repository at this point in the history
…. Still fewer requests than getting them individually
  • Loading branch information
milesoc committed Jun 18, 2024
1 parent 4d0e3db commit 50b3dca
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/MangaDex/MangaDex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -593,14 +593,15 @@ export class MangaDex implements ChapterProviding, SearchResultsProviding, HomeP
})
}

async appendCoverArt(sourceMangaAsync: Promise<PartialSourceManga[]>, thumbnailSelector: any): Promise<PartialSourceManga[]> {
async appendCoverArt(sourceMangaAsync: Promise<PartialSourceManga[]>, thumbnailSelector: any, offset: number = 0): Promise<PartialSourceManga[]> {
return sourceMangaAsync.then((sourceManga) => {
const request = App.createRequest({
url: new URLBuilder(this.MANGADEX_API)
.addPathComponent('cover')
.addQueryParameter('manga', sourceManga.map((manga) => manga.mangaId))
.addQueryParameter('includes', ['manga'])
.addQueryParameter('limit', 100)
.addQueryParameter('offset', offset)
.addQueryParameter('order', { volume: 'asc' })
.buildUrl(),
method: 'GET'
Expand All @@ -615,6 +616,16 @@ export class MangaDex implements ChapterProviding, SearchResultsProviding, HomeP

const json = (typeof response.data === 'string') ? JSON.parse(response.data) : response.data

const total = Number(json.total)
const limit = Number(json.limit)
const offset = Number(json.offset)

if (total > limit + offset) {
return addFileNamesToManga(sourceManga, json.data, this, thumbnailSelector).then((manga) => {
return this.appendCoverArt(Promise.resolve(manga), thumbnailSelector, offset + limit)
})
}

return addFileNamesToManga(sourceManga, json.data, this, thumbnailSelector)
})
})
Expand Down

0 comments on commit 50b3dca

Please sign in to comment.