Added new novel strategy

This commit is contained in:
qwsdcvghyu89
2026-06-17 08:11:21 +10:00
parent 5ac2ba6fb5
commit b2e268c6fc
3 changed files with 105 additions and 6 deletions
+4 -2
View File
@@ -46,8 +46,10 @@ export interface NovelDefinition {
slug: string;
type: 'epub' | 'web-scraped';
source: {
url?: string;
urls?: string[];
url?: string; // web-scraped TOC strategy: the table-of-contents page URL
urls?: string[]; // epub: download URL(s)
urlTemplate?: string; // web-scraped increment strategy: template with {n} placeholder, e.g. "https://example.com/chapter-{n}"
startIndex?: number; // increment: chapter number of the first {n} value (default 1)
};
selectors?: {
toc?: TocSelector;
+21 -1
View File
@@ -145,7 +145,7 @@ export function registerNovelFromConfig(
cache: Cache,
appConfig: AppConfig,
): number {
const sourceUrl = def.source.url ?? def.source.urls?.[0] ?? '';
const sourceUrl = def.source.url ?? def.source.urls?.[0] ?? def.source.urlTemplate ?? '';
const hash = createHash('sha256').update(def.slug + sourceUrl).digest('hex');
let registeredId = -1;
@@ -162,7 +162,27 @@ export function registerNovelFromConfig(
registry.updateRange(registeredId, start, end),
),
});
} else if (def.source.urlTemplate) {
// Increment strategy: chapter URLs follow a predictable pattern — no TOC fetch needed.
// {n} is replaced with the chapter number directly; endsAt is unknown so set to MAX_SAFE_INTEGER.
const startIndex = def.source.startIndex ?? 1;
const template = def.source.urlTemplate;
registeredId = registry.register({
hash,
slug: def.slug,
startsAt: startIndex,
endsAt: Number.MAX_SAFE_INTEGER,
url: template,
fetch: async (from, to) => {
const urls = Array.from(
{ length: to - from + 1 },
(_, i) => template.replace('{n}', String(from + i)),
);
return fetchChapters(def, registeredId, from, urls, cache);
},
});
} else {
// TOC strategy: scrape the table-of-contents page to discover all chapter URLs.
registeredId = registry.register({
hash,
slug: def.slug,