From 57025734d0bcac7acab49cacb5cf5dd6af5be7d3 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Fri, 27 Mar 2026 11:05:26 +0000 Subject: fix(manga): restore progress-based volume recommendations --- apps/proxy/src/mangadex.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'apps/proxy/src/mangadex.js') diff --git a/apps/proxy/src/mangadex.js b/apps/proxy/src/mangadex.js index d2a42154..dea33e70 100644 --- a/apps/proxy/src/mangadex.js +++ b/apps/proxy/src/mangadex.js @@ -223,9 +223,37 @@ const chooseLatestAggregateChapter = (volumes) => { return latest; }; +const buildVolumeChapterBoundaries = (volumes) => { + const boundaries = {}; + + for (const [volumeKey, volumeEntry] of Object.entries(volumes || {})) { + const chapters = volumeEntry?.chapters || {}; + + for (const chapterEntry of Object.values(chapters)) { + const volumeText = + chapterEntry?.volume || volumeEntry?.volume || volumeKey || null; + const volumeNumber = parseOptionalNumber(volumeText); + const chapterNumber = parseOptionalNumber(chapterEntry?.chapter || null); + + if (volumeNumber === null || chapterNumber === null) continue; + + const key = String(volumeNumber); + const current = boundaries[key]; + + if (current === undefined || chapterNumber > current) + boundaries[key] = chapterNumber; + } + } + + return Object.keys(boundaries).length ? boundaries : null; +}; + const buildIndexedRow = (manga, mangadexId, aggregateResponse) => { const now = new Date().toISOString(); const latest = chooseLatestAggregateChapter(aggregateResponse?.volumes); + const volumeChapterBoundaries = buildVolumeChapterBoundaries( + aggregateResponse?.volumes, + ); return { anilist_id: manga.anilistId, @@ -233,6 +261,7 @@ const buildIndexedRow = (manga, mangadexId, aggregateResponse) => { latest_en_chapter_text: latest?.chapterText || null, latest_en_chapter_number: latest?.chapterNumber || null, latest_en_volume_text: latest?.volumeText || null, + volume_chapter_boundaries: volumeChapterBoundaries, latest_en_chapter_id: latest?.chapterId || null, latest_chapter_updated_at: now, last_seen_at: now, -- cgit v1.2.3