fix(english): WTR-LAB fix missing chapters pagination and URL patterns (#2340) (#2342)

This commit is contained in:
Ahjie521
2026-07-26 15:16:06 +07:00
committed by GitHub
parent 50de627d33
commit a966f6eab9
+36 -28
View File
@@ -8,7 +8,7 @@ class WTRLAB implements Plugin.PluginBase {
id = 'WTRLAB';
name = 'WTR-LAB';
site = 'https://wtr-lab.com/';
version = '1.1.4';
version = '1.1.5';
icon = 'src/en/wtrlab/icon.png';
sourceLang = 'en/';
baggage = '';
@@ -341,7 +341,7 @@ class WTRLAB implements Plugin.PluginBase {
'';
}
const urlMatch = novelPath.match(/serie-(\d+)\/([^/]+)/);
const urlMatch = novelPath.match(/(?:serie|novel)-?(\d+)\/([^/]+)/);
if (urlMatch) {
rawId = parseInt(urlMatch[1]);
slug = urlMatch[2];
@@ -369,18 +369,17 @@ class WTRLAB implements Plugin.PluginBase {
}
let chapters: Plugin.ChapterItem[] = [];
if (rawId && slug && chapterCount > 0) {
if (rawId && slug) {
try {
chapters = await this.fetchAllChapters(rawId, chapterCount, slug);
chapters = await this.fetchAllChapters(rawId, slug);
} catch (error) {
console.error('Failed to fetch chapters via API:', error);
chapters = [];
}
} else {
console.warn('Could not extract rawId, slug, or chapterCount from page', {
console.warn('Could not extract rawId or slug from page', {
rawId,
slug,
chapterCount,
});
}
@@ -513,7 +512,7 @@ class WTRLAB implements Plugin.PluginBase {
let chapterNo: number | null = null;
let loadedCheerio = null;
const urlMatch = chapterPath.match(/serie-(\d+)\/[^/]+\/chapter-(\d+)/);
const urlMatch = chapterPath.match(/(?:serie|novel)-?(\d+)\/[^/]+\/chapter-(\d+)/);
if (urlMatch) {
rawId = parseInt(urlMatch[1], 10);
chapterNo = parseInt(urlMatch[2], 10);
@@ -622,14 +621,15 @@ class WTRLAB implements Plugin.PluginBase {
async fetchAllChapters(
rawId: number,
totalChapters: number,
slug: string,
): Promise<Plugin.ChapterItem[]> {
const allChapters: Plugin.ChapterItem[] = [];
const batchSize = 250;
const batchSize = 500;
let start = 1;
let hasMore = true;
for (let start = 1; start <= totalChapters; start += batchSize) {
const end = Math.min(start + batchSize - 1, totalChapters);
while (hasMore) {
const end = start + batchSize - 1;
try {
const response = await fetchApi(
@@ -644,27 +644,35 @@ class WTRLAB implements Plugin.PluginBase {
const data = await response.json();
const chapters = data.chapters ?? data.data?.chapters ?? [];
if (Array.isArray(chapters)) {
const batchChapters: Plugin.ChapterItem[] = chapters.map(
(apiChapter: ApiChapter) => ({
name: apiChapter.title,
path: `${this.sourceLang}serie-${rawId}/${slug}/chapter-${apiChapter.order}`,
releaseTime: apiChapter.updated_at?.substring(0, 10),
chapterNumber: apiChapter.order,
}),
);
allChapters.push(...batchChapters);
if (chapters.length < batchSize) {
break;
}
} else {
if (!Array.isArray(chapters) || chapters.length === 0) {
hasMore = false;
break;
}
const batchChapters: Plugin.ChapterItem[] = chapters.map(
(apiChapter: ApiChapter) => ({
name:
apiChapter.title ||
apiChapter.name ||
`Chapter ${apiChapter.order}`,
path: `${this.sourceLang}serie-${rawId}/${slug}/chapter-${apiChapter.order}`,
releaseTime: apiChapter.updated_at?.substring(0, 10),
chapterNumber: apiChapter.order,
}),
);
allChapters.push(...batchChapters);
if (chapters.length < batchSize) {
hasMore = false;
break;
}
start += batchSize;
} catch (error) {
console.error(`Failed to fetch chapters ${start}-${end}:`, error);
continue;
hasMore = false;
break;
}
}