This commit is contained in:
+36
-28
@@ -8,7 +8,7 @@ class WTRLAB implements Plugin.PluginBase {
|
|||||||
id = 'WTRLAB';
|
id = 'WTRLAB';
|
||||||
name = 'WTR-LAB';
|
name = 'WTR-LAB';
|
||||||
site = 'https://wtr-lab.com/';
|
site = 'https://wtr-lab.com/';
|
||||||
version = '1.1.4';
|
version = '1.1.5';
|
||||||
icon = 'src/en/wtrlab/icon.png';
|
icon = 'src/en/wtrlab/icon.png';
|
||||||
sourceLang = 'en/';
|
sourceLang = 'en/';
|
||||||
baggage = '';
|
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) {
|
if (urlMatch) {
|
||||||
rawId = parseInt(urlMatch[1]);
|
rawId = parseInt(urlMatch[1]);
|
||||||
slug = urlMatch[2];
|
slug = urlMatch[2];
|
||||||
@@ -369,18 +369,17 @@ class WTRLAB implements Plugin.PluginBase {
|
|||||||
}
|
}
|
||||||
let chapters: Plugin.ChapterItem[] = [];
|
let chapters: Plugin.ChapterItem[] = [];
|
||||||
|
|
||||||
if (rawId && slug && chapterCount > 0) {
|
if (rawId && slug) {
|
||||||
try {
|
try {
|
||||||
chapters = await this.fetchAllChapters(rawId, chapterCount, slug);
|
chapters = await this.fetchAllChapters(rawId, slug);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to fetch chapters via API:', error);
|
console.error('Failed to fetch chapters via API:', error);
|
||||||
chapters = [];
|
chapters = [];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.warn('Could not extract rawId, slug, or chapterCount from page', {
|
console.warn('Could not extract rawId or slug from page', {
|
||||||
rawId,
|
rawId,
|
||||||
slug,
|
slug,
|
||||||
chapterCount,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -513,7 +512,7 @@ class WTRLAB implements Plugin.PluginBase {
|
|||||||
let chapterNo: number | null = null;
|
let chapterNo: number | null = null;
|
||||||
let loadedCheerio = null;
|
let loadedCheerio = null;
|
||||||
|
|
||||||
const urlMatch = chapterPath.match(/serie-(\d+)\/[^/]+\/chapter-(\d+)/);
|
const urlMatch = chapterPath.match(/(?:serie|novel)-?(\d+)\/[^/]+\/chapter-(\d+)/);
|
||||||
if (urlMatch) {
|
if (urlMatch) {
|
||||||
rawId = parseInt(urlMatch[1], 10);
|
rawId = parseInt(urlMatch[1], 10);
|
||||||
chapterNo = parseInt(urlMatch[2], 10);
|
chapterNo = parseInt(urlMatch[2], 10);
|
||||||
@@ -622,14 +621,15 @@ class WTRLAB implements Plugin.PluginBase {
|
|||||||
|
|
||||||
async fetchAllChapters(
|
async fetchAllChapters(
|
||||||
rawId: number,
|
rawId: number,
|
||||||
totalChapters: number,
|
|
||||||
slug: string,
|
slug: string,
|
||||||
): Promise<Plugin.ChapterItem[]> {
|
): Promise<Plugin.ChapterItem[]> {
|
||||||
const allChapters: 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) {
|
while (hasMore) {
|
||||||
const end = Math.min(start + batchSize - 1, totalChapters);
|
const end = start + batchSize - 1;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetchApi(
|
const response = await fetchApi(
|
||||||
@@ -644,27 +644,35 @@ class WTRLAB implements Plugin.PluginBase {
|
|||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
const chapters = data.chapters ?? data.data?.chapters ?? [];
|
const chapters = data.chapters ?? data.data?.chapters ?? [];
|
||||||
|
|
||||||
if (Array.isArray(chapters)) {
|
if (!Array.isArray(chapters) || chapters.length === 0) {
|
||||||
const batchChapters: Plugin.ChapterItem[] = chapters.map(
|
hasMore = false;
|
||||||
(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 {
|
|
||||||
break;
|
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) {
|
} catch (error) {
|
||||||
console.error(`Failed to fetch chapters ${start}-${end}:`, error);
|
console.error(`Failed to fetch chapters ${start}-${end}:`, error);
|
||||||
continue;
|
hasMore = false;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user