Mark sparse MangaDex hosted catalogs as partial

This commit is contained in:
Codex committed 2026-10-13 22:01:57 +02:00
1 parent 47de081721
commit 0fc1a7b52a
2 files changed
+9 -2

No files matched your search

+5 -1
View File
@@ -72,6 +72,10 @@ function availabilitySummary(attributes, releases, chapters, externalReleases =
const numbered = chapters.filter(ref => !ref.special);
const expected = chapterNumber(attributes.lastChapter);
const maximum = numbered.length ? Math.max(...numbered.map(ref => Number(ref.number))) : null;
// Reaching the final chapter number is not full coverage when the catalog
// contains fewer distinct numbered releases than the expected chapter span.
const expectedCount = expected && /^\d+$/.test(expected) ? Number(expected) : null;
const sparse = expectedCount && numbered.length < expectedCount;
const reason = chapters.length ? null : externalReleases > 0 ? 'external-only'
: Array.isArray(attributes.availableTranslatedLanguages) && !attributes.availableTranslatedLanguages.includes('en') ? 'no-english' : 'no-hosted-pages';
const message = reason === 'external-only' ? `MangaDex lists ${externalReleases} English external-link releases, but no hosted English pages. External links are not downloaded.`
@@ -80,7 +84,7 @@ function availabilitySummary(attributes, releases, chapters, externalReleases =
return { language: 'en', hostedReleases: releases.filter(r => !r.attributes?.externalUrl && Number(r.attributes?.pages) > 0).length,
selectedChapters: chapters.length, numberedChapters: numbered.length, specialReleases: chapters.length - numbered.length,
externalReleases, expectedLastChapter: expected, highestHostedChapter: maximum,
coverage: expected && (maximum === null || maximum < Number(expected)) ? 'partial' : 'unknown', reason, message };
coverage: expected && (maximum === null || maximum < Number(expected) || sparse) ? 'partial' : 'unknown', reason, message };
}
async function jsonGet(http, url) {
+4 -1
View File
@@ -39,7 +39,9 @@ test('availability distinguishes no English, external-only, and partial hosted c
const chapters = selectChapterReleases([release('regular-fixture', '336')]);
const summary = availabilitySummary({ lastChapter: '686' }, [release('regular-fixture', '336')], chapters);
assert.equal(summary.coverage, 'partial'); assert.equal(summary.selectedChapters, 1);
assert.equal(availabilitySummary({ lastChapter: '336' }, [], chapters).coverage, 'unknown', 'Highest number alone does not prove completeness');
assert.equal(availabilitySummary({ lastChapter: '336' }, [], chapters).coverage, 'partial', 'One late chapter does not cover the earlier 335');
const full = selectChapterReleases(['1', '2', '3'].map((number, index) => release(`full-${index}`, number)));
assert.equal(availabilitySummary({ lastChapter: '3' }, [], full).coverage, 'unknown', 'A plausible count is still not proof of whole-series completeness');
});
test('catalog uses separate external-only feed only when hosted selections are empty', async () => {
@@ -130,6 +132,7 @@ test('inspection waits for confirmation, survives restart, and uses one normal s
test('edition change after confirmation cannot silently download another edition', async () => {
const service = Object.create(ScraperService.prototype);
service.persist = async () => {};
service.state = { sourceLedger: {} };
const item = { title: 'slug', confirmedSourceTitle: 'Pilot edition' };
await assert.rejects(service.recordCatalog(item, { title: 'Main edition', chapters: [] }), /edition title changed/);
});