Checkpoint opt-in MangaDex parser worker

This commit is contained in:
Codex committed 2026-10-13 21:57:59 +02:00
1 parent 93f07e838e
commit 1c61686c9b
11 files changed
+298 -24

No files matched your search

+27 -1
View File
@@ -21,10 +21,36 @@ function imageUrl(value) {
return url.href;
}
function mangaDexUrl(value, kind) {
const url = new URL(value);
if (url.protocol !== 'https:' || url.username || url.password || url.port) throw new Error('Invalid MangaDex plugin URL');
if (kind === 'chapter' && (url.hostname !== 'mangadex.org' || !url.pathname.startsWith('/chapter/'))) {
throw new Error('Unexpected MangaDex chapter URL');
}
if (kind === 'page' && !(url.hostname === 'uploads.mangadex.org' || url.hostname.endsWith('.mangadex.network'))) {
throw new Error('Unexpected MangaDex page host');
}
return url.href;
}
function validate(plugin, operation, output) {
if (plugin !== 'weebcentral' || !output || typeof output !== 'object' || Array.isArray(output)) {
if (!['weebcentral', 'mangadex'].includes(plugin) || !output || typeof output !== 'object' || Array.isArray(output)) {
throw new Error('Invalid source plugin output');
}
if (plugin === 'mangadex') {
if (operation === 'metadata') {
if (typeof output.title !== 'string' || !output.availabilityAttributes || typeof output.specialLabel !== 'string') throw new Error('Invalid MangaDex metadata');
} else if (operation === 'feed') {
if (!Array.isArray(output.releases) || output.releases.some(ref => typeof ref?.id !== 'string' || !ref.attributes)) throw new Error('Invalid MangaDex feed');
} else if (operation === 'catalog') {
if (!Array.isArray(output.chapters) || !output.availability) throw new Error('Invalid MangaDex catalog');
for (const chapter of output.chapters) mangaDexUrl(chapter.url, 'chapter');
} else if (operation === 'atHome') {
if (!Array.isArray(output.pages) || !output.pages.length) throw new Error('Invalid MangaDex pages');
for (const page of output.pages) mangaDexUrl(page.url, 'page');
} else throw new Error('Unknown source plugin operation');
return output;
}
if (operation === 'series') {
if (typeof output.title !== 'string' || typeof output.listUrl !== 'string' && output.listUrl !== null) throw new Error('Invalid series parse');
if (output.listUrl !== null) sourceUrl(output.listUrl, '/series/');