@acanthis-dec/linovelib 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2026 ConstasJ
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,78 @@
1
+ # @acanthis-dec/linovelib
2
+
3
+ [中文文档](./README.zh-CN.md) | [Workspace README](../../README.md)
4
+
5
+ Acanthis adapter for a named reading source. It keeps the source-specific navigation, session, parsing, queueing, and content restoration details behind a `LinovelibClient`, then returns normalized novel metadata, search results, covers, and chapter HTML to the rest of the system.
6
+
7
+ The package is intentionally described as an adapter rather than a public map of the source. Its role is to make the wider project more free and better while keeping the noisy details quiet.
8
+
9
+ ## Installation
10
+
11
+ Workspace usage:
12
+
13
+ ```powershell
14
+ pnpm install --frozen-lockfile
15
+ pnpm --filter=@acanthis-dec/linovelib run check-types
16
+ pnpm --filter=@acanthis-dec/linovelib run build
17
+ ```
18
+
19
+ Import from workspace source or the published ESM package:
20
+
21
+ ```ts
22
+ import { LinovelibClient, novelIdToCoverUrl } from "@acanthis-dec/linovelib";
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ ```ts
28
+ import { LinovelibClient } from "@acanthis-dec/linovelib";
29
+ import { StorageService } from "@acanthis-dec/storage";
30
+
31
+ const storage = new StorageService({
32
+ db: { path: "data/data.db", migrations: { directory: "migrations" } },
33
+ dataDir: "data",
34
+ });
35
+
36
+ const client = new LinovelibClient(
37
+ {
38
+ session: { enabled: false },
39
+ flareSolverr: {
40
+ enabled: true,
41
+ host: "http://localhost:8191",
42
+ timeoutMs: 60_000,
43
+ sessionId: "acanthis-linovelib-client",
44
+ },
45
+ impersonate: { enabled: true, profile: "chrome149-linux" },
46
+ cookies: { type: "database" },
47
+ },
48
+ storage,
49
+ );
50
+
51
+ const results = await client.searchNovels("keyword");
52
+ const novel = await client.getNovelInfo("example-id");
53
+ const chapterHtml = await client.getChapter("example-novel-id", "example-chapter-id");
54
+ ```
55
+
56
+ ## API
57
+
58
+ ### `LinovelibClient`
59
+
60
+ - `new LinovelibClient(options?, storage?, logger?)` creates the adapter client.
61
+ - `getNovelInfo(id)` returns normalized novel metadata.
62
+ - `getNovelUpdateInfo(id)` returns lightweight update metadata used for cache freshness checks.
63
+ - `searchNovels(keyword)` returns normalized search results.
64
+ - `getNovelCover(novelId)` resolves and fetches a cover by novel id.
65
+ - `getCover(url)` fetches binary cover data from a direct cover URL.
66
+ - `getChapter(novelId, chapterId)` returns restored chapter HTML and caches restoration parameters when storage is available.
67
+
68
+ ### Options
69
+
70
+ - `session`: disabled by default; when enabled, provide username and password for flows that need a known session.
71
+ - `flareSolverr`: enabled by default with `http://localhost:8191`.
72
+ - `impersonate`: enabled by default with `chrome149-linux`.
73
+ - `cookies`: `memory`, `file`, or `database`; database cookies require `StorageService`.
74
+ - `proxy`: optional HTTP(S) proxy URL.
75
+
76
+ ### Helpers
77
+
78
+ - `novelIdToCoverUrl(novelId)` builds a source cover URL from a novel id.
@@ -0,0 +1,78 @@
1
+ # @acanthis-dec/linovelib
2
+
3
+ [English README](./README.md) | [工作区 README](../../README.zh-CN.md)
4
+
5
+ Acanthis 面向某个具名阅读来源的适配器。它把来源侧的导航、会话、解析、队列和内容还原细节收在 `LinovelibClient` 后面,再向系统其他部分返回统一的作品元数据、搜索结果、封面与章节 HTML。
6
+
7
+ 这里刻意把它描述为适配器,而不是来源地图。它的职责是让项目更自由、更好,同时让喧闹的细节保持安静。
8
+
9
+ ## 安装
10
+
11
+ 工作区内使用:
12
+
13
+ ```powershell
14
+ pnpm install --frozen-lockfile
15
+ pnpm --filter=@acanthis-dec/linovelib run check-types
16
+ pnpm --filter=@acanthis-dec/linovelib run build
17
+ ```
18
+
19
+ 从 workspace 源码或发布后的 ESM 包导入:
20
+
21
+ ```ts
22
+ import { LinovelibClient, novelIdToCoverUrl } from "@acanthis-dec/linovelib";
23
+ ```
24
+
25
+ ## 用法
26
+
27
+ ```ts
28
+ import { LinovelibClient } from "@acanthis-dec/linovelib";
29
+ import { StorageService } from "@acanthis-dec/storage";
30
+
31
+ const storage = new StorageService({
32
+ db: { path: "data/data.db", migrations: { directory: "migrations" } },
33
+ dataDir: "data",
34
+ });
35
+
36
+ const client = new LinovelibClient(
37
+ {
38
+ session: { enabled: false },
39
+ flareSolverr: {
40
+ enabled: true,
41
+ host: "http://localhost:8191",
42
+ timeoutMs: 60_000,
43
+ sessionId: "acanthis-linovelib-client",
44
+ },
45
+ impersonate: { enabled: true, profile: "chrome149-linux" },
46
+ cookies: { type: "database" },
47
+ },
48
+ storage,
49
+ );
50
+
51
+ const results = await client.searchNovels("keyword");
52
+ const novel = await client.getNovelInfo("example-id");
53
+ const chapterHtml = await client.getChapter("example-novel-id", "example-chapter-id");
54
+ ```
55
+
56
+ ## API
57
+
58
+ ### `LinovelibClient`
59
+
60
+ - `new LinovelibClient(options?, storage?, logger?)` 创建适配器客户端。
61
+ - `getNovelInfo(id)` 返回统一作品元数据。
62
+ - `getNovelUpdateInfo(id)` 返回轻量更新信息,用于缓存新鲜度判断。
63
+ - `searchNovels(keyword)` 返回统一搜索结果。
64
+ - `getNovelCover(novelId)` 根据作品 id 解析并获取封面。
65
+ - `getCover(url)` 根据封面 URL 获取二进制封面数据。
66
+ - `getChapter(novelId, chapterId)` 返回还原后的章节 HTML;存在 storage 时缓存还原参数。
67
+
68
+ ### 选项
69
+
70
+ - `session`:默认关闭;启用时提供用户名与密码,用于需要已知会话的流程。
71
+ - `flareSolverr`:默认启用,默认地址为 `http://localhost:8191`。
72
+ - `impersonate`:默认启用,默认画像为 `chrome149-linux`。
73
+ - `cookies`:支持 `memory`、`file`、`database`;database Cookie 需要 `StorageService`。
74
+ - `proxy`:可选 HTTP(S) 代理地址。
75
+
76
+ ### 辅助方法
77
+
78
+ - `novelIdToCoverUrl(novelId)` 根据作品 id 构造来源封面 URL。
@@ -0,0 +1,61 @@
1
+ import { BinaryResponse, BrowserFetchClient, BrowserProfileName, FlareSolverrOptions } from "@acanthis-dec/browser-fetch";
2
+ import { Novel, NovelSearchResult } from "@acanthis-dec/core";
3
+ import { StorageService } from "@acanthis-dec/storage";
4
+ import { Logger } from "winston";
5
+
6
+ //#region src/novel.d.ts
7
+ interface NovelUpdateInfo {
8
+ coverUrl: string;
9
+ chapterCount: number;
10
+ }
11
+ //#endregion
12
+ //#region src/client.d.ts
13
+ type SessionOptions = {
14
+ enabled: false;
15
+ } | {
16
+ enabled: true;
17
+ username: string;
18
+ password: string;
19
+ };
20
+ type ImpersonateOptions = {
21
+ enabled: true;
22
+ profile: BrowserProfileName;
23
+ } | {
24
+ enabled: false;
25
+ };
26
+ type CookieStoreOptions = {
27
+ type: "memory" | "database";
28
+ } | {
29
+ type: "file";
30
+ path: string;
31
+ };
32
+ type LinovelibClientOptions = {
33
+ session: SessionOptions;
34
+ flareSolverr: FlareSolverrOptions;
35
+ impersonate: ImpersonateOptions;
36
+ cookies: CookieStoreOptions;
37
+ proxy?: string | undefined;
38
+ };
39
+ declare class LinovelibClient {
40
+ private storage?;
41
+ private fetchClient;
42
+ private novelChapterQueue;
43
+ private novelInfoQueue;
44
+ private searchQueue;
45
+ private options?;
46
+ private logger?;
47
+ private isSessionValid?;
48
+ constructor(options?: LinovelibClientOptions, storage?: StorageService, logger?: Logger);
49
+ getNovelInfo(id: string): Promise<Novel | undefined>;
50
+ getNovelUpdateInfo(id: string): Promise<NovelUpdateInfo | null>;
51
+ searchNovels(keyword: string): Promise<NovelSearchResult[]>;
52
+ getNovelCover(novelId: string): Promise<BinaryResponse>;
53
+ getCover(url: string): Promise<BinaryResponse>;
54
+ getChapter(novelId: string, chapterId: string): Promise<string | undefined>;
55
+ }
56
+ //#endregion
57
+ //#region src/cover.d.ts
58
+ declare function novelIdToCoverUrl(novelId: string): string;
59
+ //#endregion
60
+ export { LinovelibClient, type LinovelibClientOptions, type SessionOptions, novelIdToCoverUrl };
61
+ //# sourceMappingURL=index.d.mts.map
package/dist/index.mjs ADDED
@@ -0,0 +1,865 @@
1
+ import { BrowserFetchClient, CloudflareBlockError, defaultRetryPolicy } from "@acanthis-dec/browser-fetch";
2
+ import { deepmerge } from "deepmerge-ts";
3
+ import z$1, { z } from "zod";
4
+ import { buildDescrambleMapping } from "@acanthis-dec/core";
5
+ import * as cheerio from "cheerio";
6
+ import { deobfuscate } from "@acanthis-dec/deobfuscator";
7
+ import { parse } from "@babel/parser";
8
+ import traverseModule from "@babel/traverse";
9
+ import * as t from "@babel/types";
10
+ import PQueue from "p-queue";
11
+ import { webcrypto } from "node:crypto";
12
+ //#region src/coefficients.ts
13
+ const traverse = traverseModule.default ?? traverseModule;
14
+ const descrambleCoefficientsSchema = z.object({
15
+ modulus: z.number().int(),
16
+ increment: z.number().int(),
17
+ multiplier: z.number().int(),
18
+ seedOffset: z.number().int(),
19
+ seedMultiplier: z.number().int()
20
+ });
21
+ function getObfuscatedPart(fullCode) {
22
+ return fullCode.split(/\r?\n/).map((line) => line.trim()).filter((line) => line !== "").slice(-2).join("\n");
23
+ }
24
+ async function extractCoefficients(script) {
25
+ const ast = parse(await deobfuscate(getObfuscatedPart(script)), {
26
+ sourceType: "module",
27
+ plugins: ["jsx"]
28
+ });
29
+ const coefficients = {};
30
+ traverse(ast, { BinaryExpression(path) {
31
+ const { node } = path;
32
+ if (node.operator === "%" && t.isNumericLiteral(node.right) && t.isBinaryExpression(node.left) && node.left.operator === "+" && t.isNumericLiteral(node.left.right) && t.isBinaryExpression(node.left.left) && node.left.left.operator === "*" && t.isNumericLiteral(node.left.left.right)) {
33
+ coefficients.modulus = node.right.value;
34
+ const leftSide = node.left;
35
+ if (t.isBinaryExpression(leftSide) && leftSide.operator === "+") {
36
+ if (t.isNumericLiteral(leftSide.right)) coefficients.increment = leftSide.right.value;
37
+ if (t.isBinaryExpression(leftSide.left) && leftSide.left.operator === "*") {
38
+ if (t.isNumericLiteral(leftSide.left.right)) coefficients.multiplier = leftSide.left.right.value;
39
+ }
40
+ }
41
+ }
42
+ if (node.operator === "+" && t.isNumericLiteral(node.right) && t.isBinaryExpression(node.left) && node.left.operator === "*" && t.isNumericLiteral(node.left.right)) {
43
+ const potentialOffset = node.right.value;
44
+ const potentialMultiplier = node.left.right.value;
45
+ const numberTransformed = node.left.left;
46
+ if (t.isCallExpression(numberTransformed) && t.isIdentifier(numberTransformed.callee) && (numberTransformed.callee.name === "Number" || numberTransformed.callee.name === "parseInt")) {
47
+ coefficients.seedOffset = potentialOffset;
48
+ coefficients.seedMultiplier = potentialMultiplier;
49
+ }
50
+ }
51
+ } });
52
+ if (coefficients.modulus === void 0 || coefficients.increment === void 0 || coefficients.multiplier === void 0 || coefficients.seedOffset === void 0 || coefficients.seedMultiplier === void 0) throw new Error("Failed to extract all coefficients");
53
+ return coefficients;
54
+ }
55
+ function extractChapterLogScriptUrl(html) {
56
+ const $ = cheerio.load(html);
57
+ const chapterLogScriptUrl = $($("script").toArray().find((el) => {
58
+ const scriptContent = $(el).attr("src") || "";
59
+ return /chapterlog\.js/.test(scriptContent);
60
+ })).attr("src") || "";
61
+ return chapterLogScriptUrl.startsWith("http") ? chapterLogScriptUrl : `https://www.linovelib.com${chapterLogScriptUrl}`;
62
+ }
63
+ async function getCoefficientsFromPage(html, fetchClient, cachedVersion) {
64
+ const scriptUrl = extractChapterLogScriptUrl(html);
65
+ if (!scriptUrl) throw new Error("Chapter log script URL not found");
66
+ const version = scriptUrl.match(/chapterlog\.js\?(v.*)/)?.[1] || "";
67
+ if (version === cachedVersion) return;
68
+ const scriptContent = await fetchClient.text(scriptUrl);
69
+ if (!scriptContent.mimeType.includes("javascript")) throw new Error("Fetched content is not JavaScript");
70
+ return {
71
+ coefficients: await extractCoefficients(scriptContent.data),
72
+ version
73
+ };
74
+ }
75
+ //#endregion
76
+ //#region src/utils.ts
77
+ function extractNovelIdFromUrl(url) {
78
+ const match = url.match(/\/novel\/(\d+)\.html/);
79
+ return match ? match[1] : void 0;
80
+ }
81
+ function transformContent(content) {
82
+ const contentTransDict = {
83
+ "“": "「",
84
+ "”": "」",
85
+ "‘": "『",
86
+ "’": "』",
87
+ "": "的",
88
+ "": "一",
89
+ "": "是",
90
+ "": "了",
91
+ "": "我",
92
+ "": "不",
93
+ "": "人",
94
+ "": "在",
95
+ "": "他",
96
+ "": "有",
97
+ "": "这",
98
+ "": "个",
99
+ "": "上",
100
+ "": "们",
101
+ "": "来",
102
+ "": "到",
103
+ "": "时",
104
+ "": "大",
105
+ "": "地",
106
+ "": "为",
107
+ "": "子",
108
+ "": "中",
109
+ "": "你",
110
+ "": "说",
111
+ "": "生",
112
+ "": "国",
113
+ "": "年",
114
+ "": "着",
115
+ "": "就",
116
+ "": "那",
117
+ "": "和",
118
+ "": "要",
119
+ "": "她",
120
+ "": "出",
121
+ "": "也",
122
+ "": "得",
123
+ "": "里",
124
+ "": "后",
125
+ "": "自",
126
+ "": "以",
127
+ "": "会",
128
+ "": "家",
129
+ "": "可",
130
+ "": "下",
131
+ "": "而",
132
+ "": "过",
133
+ "": "天",
134
+ "": "去",
135
+ "": "能",
136
+ "": "对",
137
+ "": "小",
138
+ "": "多",
139
+ "": "然",
140
+ "": "于",
141
+ "": "心",
142
+ "": "学",
143
+ "": "么",
144
+ "": "之",
145
+ "": "都",
146
+ "": "好",
147
+ "": "看",
148
+ "": "起",
149
+ "": "发",
150
+ "": "当",
151
+ "": "没",
152
+ "": "成",
153
+ "": "只",
154
+ "": "如",
155
+ "": "事",
156
+ "": "把",
157
+ "": "还",
158
+ "": "用",
159
+ "": "第",
160
+ "": "样",
161
+ "": "道",
162
+ "": "想",
163
+ "": "作",
164
+ "": "种",
165
+ "": "开",
166
+ "": "美",
167
+ "": "乳",
168
+ "": "阴",
169
+ "": "液",
170
+ "": "茎",
171
+ "": "欲",
172
+ "": "呻",
173
+ "": "肉",
174
+ "": "交",
175
+ "": "性",
176
+ "": "胸",
177
+ "": "私",
178
+ "": "穴",
179
+ "": "淫",
180
+ "": "臀",
181
+ "": "舔",
182
+ "": "射",
183
+ "": "脱",
184
+ "": "裸",
185
+ "": "骚",
186
+ "": "唇"
187
+ };
188
+ return content.replace(/./g, (char) => contentTransDict[char] || char);
189
+ }
190
+ //#endregion
191
+ //#region src/chapter.ts
192
+ function extractChapterId($) {
193
+ const scriptTags = $("script");
194
+ let chapterId = "";
195
+ scriptTags.each((_, el) => {
196
+ const scriptContent = $(el).html();
197
+ if (scriptContent) {
198
+ const match = scriptContent.match(/chapterid\s*:\s*'(\d+)'/);
199
+ if (match?.[1]) {
200
+ chapterId = match[1];
201
+ return false;
202
+ }
203
+ }
204
+ });
205
+ return chapterId;
206
+ }
207
+ async function decrypt(html, fetchClient, cachedJsVersion, cachedCoefficients) {
208
+ const $ = cheerio.load(html);
209
+ const coefficientResult = await getCoefficientsFromPage(html, fetchClient, cachedJsVersion);
210
+ const version = coefficientResult?.version || cachedJsVersion;
211
+ const coefficients = coefficientResult?.coefficients || cachedCoefficients;
212
+ if (!version) throw new Error("Failed to determine chapterlog.js version");
213
+ if (!coefficients) throw new Error("Failed to obtain descrambling coefficients");
214
+ const chapterId = extractChapterId($);
215
+ const container = $("#TextContent, #acontent");
216
+ if (!container.length) return {
217
+ content: "",
218
+ version,
219
+ coefficients
220
+ };
221
+ container.find("p").each((_, el) => {
222
+ const $el = $(el);
223
+ const innerHtml = $el.html();
224
+ if (innerHtml) {
225
+ const cleanedHtml = innerHtml.replace(/^\s+|(?<=>)\s+/g, "");
226
+ $el.html(cleanedHtml);
227
+ }
228
+ });
229
+ container.find("img.imagecontent").each((_, el) => {
230
+ const imgSrc = $(el).attr("data-src") || $(el).attr("src");
231
+ if (imgSrc) $(el).attr("src", imgSrc).removeAttr("data-src");
232
+ });
233
+ container.find("div.dag").remove();
234
+ container.find("script").remove();
235
+ const allChildren = container.contents().toArray().filter((node) => !(node.type === "tag" && node.tagName === "div"));
236
+ const sortableEntries = [];
237
+ allChildren.forEach((node, index) => {
238
+ if (node.type === "tag" && node.tagName === "p") {
239
+ if ($(node).text().trim().length > 0) sortableEntries.push({
240
+ element: node,
241
+ originalPos: index
242
+ });
243
+ }
244
+ });
245
+ const seed = parseInt(chapterId, 10) * coefficients?.seedMultiplier + coefficients?.seedOffset;
246
+ const mapping = buildDescrambleMapping(sortableEntries.length, seed, coefficients, 20);
247
+ const restoredChildren = [...allChildren];
248
+ sortableEntries.forEach((entry, i) => {
249
+ const actualSlot = sortableEntries[mapping[i] ?? i]?.originalPos ?? 0;
250
+ restoredChildren[actualSlot] = entry.element;
251
+ });
252
+ const newContainer = $("<div></div>");
253
+ restoredChildren.forEach((node) => {
254
+ if (node && node.type === "tag") {
255
+ newContainer.append(node);
256
+ newContainer.append("\n");
257
+ }
258
+ });
259
+ return {
260
+ content: newContainer.html() || "",
261
+ version,
262
+ coefficients
263
+ };
264
+ }
265
+ async function getChapter(id, novelId, chapterQueue, fetchClient, cachedJsVersion, cachedCoefficients) {
266
+ const firstPageHtml = await chapterQueue.fetchChapterPart(`https://www.linovelib.com/novel/${novelId}/${id}.html`);
267
+ let $ = cheerio.load(firstPageHtml);
268
+ const chapterName = $("h1").text().trim();
269
+ let nextPageId = $("div.mlfy_page a:last").attr("href")?.match(/\/novel\/(\d+)\/([\d_]+)\.html/)?.[2] || firstPageHtml.match(/url_next:'\/novel\/(\d+)\/([\d_]+)\.html'/)?.[2] || "";
270
+ let content = await decrypt(firstPageHtml, fetchClient, cachedJsVersion, cachedCoefficients);
271
+ cachedCoefficients = content.coefficients;
272
+ cachedJsVersion = content.version;
273
+ while (nextPageId?.includes(id)) {
274
+ const nextPageHtml = await chapterQueue.fetchChapterPart(`https://www.linovelib.com/novel/${novelId}/${nextPageId}.html`);
275
+ const nextContent = await decrypt(nextPageHtml, fetchClient, cachedJsVersion, cachedCoefficients);
276
+ content = {
277
+ ...content,
278
+ content: content.content + nextContent.content
279
+ };
280
+ $ = cheerio.load(nextPageHtml);
281
+ nextPageId = $("div.mlfy_page a:last").attr("href")?.match(/\/novel\/(\d+)\/([\d_]+)\.html/)?.[2] || nextPageHtml.match(/url_next:'\/novel\/(\d+)\/([\d_]+)\.html/)?.[2] || "";
282
+ }
283
+ content = {
284
+ ...content,
285
+ content: `<h2>${chapterName}</h2>\n${transformContent(content.content)}`
286
+ };
287
+ return content;
288
+ }
289
+ //#endregion
290
+ //#region src/cover.ts
291
+ function novelIdToCoverUrl(novelId) {
292
+ return `https://www.linovelib.com/files/article/image/${novelId.length > 3 ? novelId[0] : "0"}/${novelId}/${novelId}s.jpg`;
293
+ }
294
+ async function getCover(novelId, fetchClient) {
295
+ const url = novelIdToCoverUrl(novelId);
296
+ return await fetchClient.binary(url);
297
+ }
298
+ //#endregion
299
+ //#region src/novel.ts
300
+ function extractVolumesArray(catalog) {
301
+ const $ = cheerio.load(catalog);
302
+ const results = [];
303
+ $("#volume-list div.volume").each((_, elem) => {
304
+ $(elem).remove("div.volume");
305
+ results.push(elem);
306
+ });
307
+ return results;
308
+ }
309
+ function processVolumeName(novelTitle, volumeName) {
310
+ if (volumeName.startsWith(novelTitle)) return volumeName.slice(novelTitle.length).trim();
311
+ if (!Number.isNaN(Number(volumeName))) return `第 ${volumeName} 卷`;
312
+ return volumeName.trim();
313
+ }
314
+ function parseVolumeOrChapterId(url) {
315
+ if (url.includes("javascript:cid(0)")) return "TOBEDETERMINED";
316
+ const match = url.match(/\/novel\/\d+\/(\d+|vol_\d+)\.html/);
317
+ return match ? match[1] ?? "" : "";
318
+ }
319
+ async function parseChapterIdFromNextChapter(nextChapterEl, chapterQueue) {
320
+ const nextChapterPath = nextChapterEl.attribs.href ?? "";
321
+ const nextChapterContent = await chapterQueue.fetchChapterPart(`https://www.linovelib.com${nextChapterPath}`);
322
+ return parseVolumeOrChapterId(cheerio.load(nextChapterContent)("div.mlfy_page a:first").attr("href") ?? nextChapterContent.match(/url_previous:'(\/novel\/\d+\/[\d_]+\.html)'/)?.[1] ?? "");
323
+ }
324
+ async function getNovelVolumes(title, url, fetchClient, retry, chapterQueue) {
325
+ const volumeEls = extractVolumesArray((await fetchClient.text(url, { retry })).data);
326
+ const volumes = [];
327
+ const chapterElements = [];
328
+ for (const volumeEl of volumeEls) {
329
+ const volumeEl$ = cheerio.load(volumeEl);
330
+ const volumeName = processVolumeName(title, volumeEl$("h2").text());
331
+ const volumeId = parseVolumeOrChapterId(volumeEl$("h2 a").attr("href") ?? "");
332
+ const volumeCover = volumeEl$("a.volume-cover img").attr("data-original") ?? "";
333
+ const chapterEls = volumeEl$("ul.chapter-list li a").toArray();
334
+ const chapters = [];
335
+ for (const [index, chapterEl] of chapterEls.entries()) {
336
+ chapterElements.push(chapterEl);
337
+ const chapterName = cheerio.load(chapterEl).text().trim();
338
+ let chapterId = parseVolumeOrChapterId(chapterEl.attribs.href ?? "");
339
+ if (chapterId === "TOBEDETERMINED" && chapterQueue) {
340
+ const nextChapterEl = chapterEls[index + 1];
341
+ if (nextChapterEl) chapterId = await parseChapterIdFromNextChapter(nextChapterEl, chapterQueue);
342
+ }
343
+ chapters.push({
344
+ id: chapterId,
345
+ platform: "linovelib",
346
+ title: chapterName,
347
+ volumeId
348
+ });
349
+ }
350
+ volumes.push({
351
+ id: volumeId,
352
+ platform: "linovelib",
353
+ title: volumeName,
354
+ coverUrl: volumeCover,
355
+ chapters
356
+ });
357
+ }
358
+ return volumes;
359
+ }
360
+ async function getNovelInfo(id, fetchClient, retry, chapterQueue) {
361
+ const url = `https://www.linovelib.com/novel/${id}.html`;
362
+ const html = (await fetchClient.text(url, { retry })).data;
363
+ const $ = cheerio.load(html);
364
+ const title = $("h1.book-name").text().trim();
365
+ const novel = {
366
+ id,
367
+ platform: "linovelib",
368
+ title,
369
+ coverUrl: $("div.book-img img").attr("src") || novelIdToCoverUrl(id),
370
+ summary: (() => {
371
+ const $container = $(".book-dec.Jbook-dec").clone();
372
+ $container.find(".notice").remove();
373
+ const paragraphs = [];
374
+ $container.find("p").not(".backupname").each((_, el) => {
375
+ paragraphs.push($(el).text().trim());
376
+ });
377
+ return paragraphs.join("\n");
378
+ })(),
379
+ author: $("div.au-name a:first").text().trim(),
380
+ status: $("div.book-label a.state").text().includes("完结") ? "completed" : "ongoing",
381
+ genres: $("div.book-label span").children("a").map((_, el) => $(el).text()).toArray().join(",").split(",").map((g) => g.trim()),
382
+ volumes: []
383
+ };
384
+ novel.volumes = (await getNovelVolumes(title, `https://www.linovelib.com${$("a.read-btn").attr("href")}`, fetchClient, retry, chapterQueue)).map((v) => {
385
+ v.novelId = novel.id;
386
+ return v;
387
+ });
388
+ return novel;
389
+ }
390
+ async function getUpdateInfo(id, fetchClient, retry) {
391
+ const url = `https://www.linovelib.com/novel/${id}.html`;
392
+ const html = (await fetchClient.text(url, { retry })).data;
393
+ const $ = cheerio.load(html);
394
+ if ($("h1.book-name").length === 0) return null;
395
+ const catalogUrl = `https://www.linovelib.com${$("a.read-btn").attr("href")}`;
396
+ const catalogHtml = (await fetchClient.text(catalogUrl, { retry })).data;
397
+ const chapterCount = cheerio.load(catalogHtml)("#volume-list div.volume ul.chapter-list li a").length;
398
+ return {
399
+ coverUrl: $("div.book-img img").attr("src") || novelIdToCoverUrl(id),
400
+ chapterCount
401
+ };
402
+ }
403
+ //#endregion
404
+ //#region src/search.ts
405
+ function k(e) {
406
+ const t = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
407
+ const n = e.replace(/[^A-Za-z0-9+/]/g, "");
408
+ const r = n.length;
409
+ const buf = new Uint8Array(Math.floor(r * .75));
410
+ let i = 0, a = 0, s = 0, c = 0;
411
+ for (let l = 0; l < r; l++) {
412
+ c = t.indexOf(n[l] || "");
413
+ if (c === -1) continue;
414
+ a = a << 6 | c;
415
+ s += 6;
416
+ if (s >= 8) {
417
+ s -= 8;
418
+ buf[i++] = a >> s & 255;
419
+ }
420
+ }
421
+ return new Uint8Array(buf.buffer.slice(0, i));
422
+ }
423
+ async function solveSearchChallenge(a, b, c) {
424
+ const subtle = webcrypto.subtle;
425
+ const keyData = k(a);
426
+ const counterData = k(b);
427
+ const encryptedData = k(c);
428
+ try {
429
+ const cryptoKey = await subtle.importKey("raw", keyData, { name: "AES-CTR" }, false, ["decrypt"]);
430
+ const decryptedBuffer = await subtle.decrypt({
431
+ name: "AES-CTR",
432
+ counter: counterData,
433
+ length: 64
434
+ }, cryptoKey, encryptedData);
435
+ const plainText = new TextDecoder().decode(new Uint8Array(decryptedBuffer));
436
+ return encodeURIComponent(plainText);
437
+ } catch (error) {
438
+ throw new Error(`解密失败: ${error}`);
439
+ }
440
+ }
441
+ async function searchNovels(keyword, fetchClient) {
442
+ let response = await fetchClient.text("https://www.linovelib.com/S6/", {
443
+ method: "POST",
444
+ body: new URLSearchParams({ searchkey: keyword }),
445
+ headers: {
446
+ origin: "https://www.linovelib.com",
447
+ referer: "https://www.linovelib.com/"
448
+ }
449
+ });
450
+ if (response.mimeType !== "text/html") throw new Error(`Unexpected response type: ${response.mimeType}`);
451
+ let $ = cheerio.load(response.data);
452
+ if ($("#challenge-running").length > 0) {
453
+ let a = "", b = "", c = "";
454
+ $("script").each((_, el) => {
455
+ const scriptContent = $(el).html() || "";
456
+ if (/window\.a\s*=\s*'([^']+)'/.test(scriptContent)) {
457
+ a = scriptContent.match(/window\.a\s*=\s*'([^']+)'/)?.[1] || "";
458
+ b = scriptContent.match(/window\.b\s*=\s*'([^']+)'/)?.[1] || "";
459
+ c = scriptContent.match(/window\.c\s*=\s*'([^']+)'/)?.[1] || "";
460
+ }
461
+ });
462
+ const haha = await solveSearchChallenge(a, b, c);
463
+ await fetchClient.setCookies([{
464
+ domain: "www.linovelib.com",
465
+ path: "/",
466
+ name: "haha",
467
+ value: haha,
468
+ maxAge: 900
469
+ }]);
470
+ await new Promise((r) => setTimeout(r, 3e3));
471
+ response = await fetchClient.text("https://www.linovelib.com/S6/", {
472
+ method: "POST",
473
+ body: new URLSearchParams({ searchkey: keyword }),
474
+ headers: { referer: "https://www.linovelib.com/S6/" }
475
+ });
476
+ $ = cheerio.load(response.data);
477
+ }
478
+ if ($("#challenge-running").length !== 0) throw new Error("Failed to solve search challenge");
479
+ if ($("div.book-html-box").length > 0) return [{
480
+ title: $("h1.book-name").text().trim(),
481
+ platform: "linovelib",
482
+ id: extractNovelIdFromUrl($("meta[name=url]").attr("content") ?? "") || "",
483
+ coverUrl: $("div.book-img img").attr("src") || ""
484
+ }];
485
+ if (!response.data.includes("有关")) throw new Error("Unexpected search result format, keyword not found");
486
+ const pages = $("em#pagestats").text().match(/1\/(\d+)/)?.[1] || "1";
487
+ const results = [];
488
+ $("div.search-html-box div.search-result-list").each((_, el) => {
489
+ const $el = $(el);
490
+ const title = $el.find("h2").text().trim();
491
+ const id = extractNovelIdFromUrl($el.find("h2 a").attr("href") || "") ?? "";
492
+ const coverUrl = $el.find("img").attr("src") || "";
493
+ results.push({
494
+ title,
495
+ platform: "linovelib",
496
+ id,
497
+ coverUrl
498
+ });
499
+ });
500
+ if (Number(pages) > 1) {
501
+ let currentPageHtml = response.data;
502
+ while (true) {
503
+ const $2 = cheerio.load(currentPageHtml);
504
+ if ($2("a.next").length > 0) currentPageHtml = (await fetchClient.text(`https://www.linovelib.com${$2("a.next").attr("href")}`, { headers: {
505
+ host: "www.linovelib.com",
506
+ referer: "https://www.linovelib.com/S6/"
507
+ } })).data;
508
+ const $3 = cheerio.load(currentPageHtml);
509
+ $3("div.search-html-box div.search-result-list").each((_, el) => {
510
+ const $el = $3(el);
511
+ const title = $el.find("h2").text().trim();
512
+ const id = extractNovelIdFromUrl($el.find("h2 a").attr("href") || "") ?? "";
513
+ const coverUrl = $el.find("img").attr("src") || "";
514
+ results.push({
515
+ title,
516
+ platform: "linovelib",
517
+ id,
518
+ coverUrl
519
+ });
520
+ });
521
+ if ($3("a.next").length === 0) break;
522
+ }
523
+ }
524
+ return results;
525
+ }
526
+ //#endregion
527
+ //#region src/queue.ts
528
+ /**
529
+ * Simple backoff strategy for request rate limiting
530
+ * - Normal desktop delay: 500-1000ms random
531
+ * - Normal mobile delay: 2000-5000ms random
532
+ * - Failure delay: 8000ms (8 seconds)
533
+ */
534
+ var SimpleBackoff = class {
535
+ NORMAL_DELAY_MIN = 500;
536
+ NORMAL_DELAY_MAX = 1e3;
537
+ NORMAL_MOBILE_DELAY_MIN = 2e3;
538
+ NORMAL_MOBILE_DELAY_MAX = 5e3;
539
+ FAILURE_DELAY = 15e3;
540
+ /**
541
+ * Get delay for normal (successful) operation
542
+ * @returns Random delay in range [500, 1000]ms. If isMobile is true, returns random delay in range [2000, 5000]ms
543
+ */
544
+ getDelayForSuccess(isMobile = false) {
545
+ if (isMobile) return this.NORMAL_MOBILE_DELAY_MIN + Math.random() * (this.NORMAL_MOBILE_DELAY_MAX - this.NORMAL_MOBILE_DELAY_MIN);
546
+ return this.NORMAL_DELAY_MIN + Math.random() * (this.NORMAL_DELAY_MAX - this.NORMAL_DELAY_MIN);
547
+ }
548
+ };
549
+ var SearchQueue = class {
550
+ queue;
551
+ client;
552
+ logger;
553
+ COOLDOWN_MS = 5e3;
554
+ lastSearchTime = 0;
555
+ constructor(client, logger) {
556
+ this.queue = new PQueue({ concurrency: 1 });
557
+ this.client = client;
558
+ this.logger = logger;
559
+ this.queue.on("add", () => {
560
+ this.logger?.debug(`[SearchQueue] 任务已添加,当前排队数: ${this.queue.size} (等待中任务数: ${this.queue.pending})`);
561
+ });
562
+ this.queue.on("next", () => {
563
+ this.logger?.debug(`[SearchQueue] 任务完成或超时,开始下一个任务。剩余:${this.queue.size} `);
564
+ });
565
+ }
566
+ async searchNovels(keyword) {
567
+ return await this.queue.add(async () => {
568
+ if (Date.now() - this.lastSearchTime < this.COOLDOWN_MS) {
569
+ const waitTime = this.COOLDOWN_MS - (Date.now() - this.lastSearchTime);
570
+ this.logger?.debug(`[SearchQueue] 搜索请求过快,等待 ${waitTime}ms 后重试`);
571
+ await new Promise((resolve) => setTimeout(resolve, waitTime));
572
+ }
573
+ this.logger?.debug(`[SearchQueue] 开始搜索关键词 "${keyword}"`);
574
+ const results = await searchNovels(keyword, this.client);
575
+ this.logger?.debug(`[SearchQueue] 搜索完成,关键词 "${keyword}" 共找到 ${results.length} 条结果`);
576
+ this.lastSearchTime = Date.now();
577
+ return results;
578
+ });
579
+ }
580
+ };
581
+ var NovelChapterQueue = class {
582
+ queue;
583
+ client;
584
+ backoff;
585
+ logger;
586
+ constructor(client, logger) {
587
+ this.queue = new PQueue({ concurrency: 1 });
588
+ this.client = client;
589
+ this.backoff = new SimpleBackoff();
590
+ this.logger = logger;
591
+ this.queue.on("add", () => {
592
+ this.logger?.debug(`[NovelChapterQueue] 任务已添加,当前排队数: ${this.queue.size} (等待中任务数: ${this.queue.pending})`);
593
+ });
594
+ this.queue.on("next", () => {
595
+ this.logger?.debug(`[NovelChapterQueue] 任务完成或超时,开始下一个任务。剩余:${this.queue.size} `);
596
+ });
597
+ }
598
+ async _sleep(ms) {
599
+ return new Promise((resolve) => setTimeout(resolve, ms));
600
+ }
601
+ async fetchChapterPart(url) {
602
+ return await this.queue.add(async () => {
603
+ const match = url.match(/\/novel\/(\d+)\/(\d+)(?:_(\d+))?\.html/);
604
+ if (!match) throw new Error(`Invalid chapter URL: ${url}`);
605
+ const novelId = match[1];
606
+ const chapterId = match[2];
607
+ const partId = match[3] || "1";
608
+ this.logger?.debug(`[NovelChapterQueue] 开始获取小说${novelId}章节${chapterId}的第${partId}部分内容`);
609
+ const retry = {
610
+ retries: 10,
611
+ factor: 2,
612
+ minRetryDelayMs: 0,
613
+ maxRetryDelayMs: 0,
614
+ randomize: false,
615
+ onFailedAttempt: async (ctx) => {
616
+ if (ctx.error instanceof CloudflareBlockError) {
617
+ this.logger?.warn(`[NovelChapterQueue] 请求被 Cloudflare 阻挡,错误信息: ${ctx.error.message}。正在等待 ${this.backoff.FAILURE_DELAY / 1e3}s 后重试...`);
618
+ await this._sleep(this.backoff.FAILURE_DELAY);
619
+ }
620
+ if (ctx.attemptNumber >= (retry.retries ?? 3)) this.logger?.error(`[NovelChapterQueue] 请求重试次数已达上限 (${ctx.attemptNumber} 次),错误信息: ${ctx.error.message}`);
621
+ },
622
+ shouldRetry: async (ctx) => {
623
+ return defaultRetryPolicy(ctx) || ctx.error instanceof CloudflareBlockError;
624
+ }
625
+ };
626
+ let content = (await this.client.text(url, { retry })).data ?? "";
627
+ if (content.match(/沒有可閱讀的章節|没有可阅读的章节/i)) {
628
+ content = (await this.client.text(url, {
629
+ profile: "chrome149-android",
630
+ retry: {
631
+ ...retry,
632
+ minRetryDelayMs: this.backoff.NORMAL_MOBILE_DELAY_MIN,
633
+ maxRetryDelayMs: this.backoff.NORMAL_MOBILE_DELAY_MAX
634
+ }
635
+ })).data;
636
+ const delay = this.backoff.getDelayForSuccess(true);
637
+ this.logger?.debug(`[NovelChapterQueue] 小说${novelId}-章节${chapterId}_${partId} 获取成功。下一次请求将在 ${delay.toFixed(0)}ms 后进行`);
638
+ await this._sleep(delay);
639
+ return content;
640
+ }
641
+ const delay = this.backoff.getDelayForSuccess();
642
+ this.logger?.debug(`[NovelChapterQueue] 小说${novelId}-章节${chapterId}_${partId} 获取成功。下一次请求将在 ${delay.toFixed(0)}ms 后进行`);
643
+ await this._sleep(delay);
644
+ return content;
645
+ });
646
+ }
647
+ };
648
+ var NovelInfoQueue = class {
649
+ queue;
650
+ client;
651
+ backoff;
652
+ chapterQueue;
653
+ logger;
654
+ constructor(client, chapterQueue, logger) {
655
+ this.queue = new PQueue({ concurrency: 1 });
656
+ this.client = client;
657
+ this.backoff = new SimpleBackoff();
658
+ this.chapterQueue = chapterQueue;
659
+ this.logger = logger;
660
+ this.queue.on("add", () => {
661
+ this.logger?.debug(`[NovelInfoQueue] 任务已添加,当前排队数: ${this.queue.size} (等待中任务数: ${this.queue.pending})`);
662
+ });
663
+ this.queue.on("next", () => {
664
+ this.logger?.debug(`[NovelInfoQueue] 任务完成或超时,开始下一个任务。剩余:${this.queue.size} `);
665
+ });
666
+ }
667
+ async _sleep(ms) {
668
+ return new Promise((resolve) => setTimeout(resolve, ms));
669
+ }
670
+ async fetchNovelInfo(id) {
671
+ return await this.queue.add(async () => {
672
+ this.logger?.debug(`[NovelInfoQueue] 开始获取小说${id}的信息`);
673
+ const retry = {
674
+ retries: 10,
675
+ factor: 2,
676
+ minRetryDelayMs: 0,
677
+ maxRetryDelayMs: 0,
678
+ randomize: false,
679
+ onFailedAttempt: async (ctx) => {
680
+ if (ctx.error instanceof CloudflareBlockError) {
681
+ this.logger?.warn(`[NovelInfoQueue] 请求被 Cloudflare 阻挡,错误信息: ${ctx.error.message}。正在等待 ${this.backoff.FAILURE_DELAY / 1e3}s 后重试...`);
682
+ await this._sleep(this.backoff.FAILURE_DELAY);
683
+ }
684
+ if (ctx.attemptNumber >= (retry.retries ?? 3)) this.logger?.error(`[NovelInfoQueue] 请求重试次数已达上限 (${ctx.attemptNumber} 次),错误信息: ${ctx.error.message}`);
685
+ },
686
+ shouldRetry: async (ctx) => {
687
+ return defaultRetryPolicy(ctx) || ctx.error instanceof CloudflareBlockError;
688
+ }
689
+ };
690
+ const novel = await getNovelInfo(id, this.client, retry, this.chapterQueue);
691
+ if (!novel) throw new Error(`无法获取小说信息: ${id}`);
692
+ const delay = this.backoff.getDelayForSuccess();
693
+ this.logger?.debug(`[NovelInfoQueue] 小说${id} 信息获取成功。下一次请求将在 ${delay.toFixed(0)}ms 后进行`);
694
+ await this._sleep(delay);
695
+ return novel;
696
+ });
697
+ }
698
+ async fetchNovelUpdateInfo(id) {
699
+ return await this.queue.add(async () => {
700
+ this.logger?.debug(`[NovelInfoQueue] 开始获取小说${id}的更新信息(封面和章节数)`);
701
+ const retry = {
702
+ retries: 10,
703
+ factor: 2,
704
+ minRetryDelayMs: 0,
705
+ maxRetryDelayMs: 0,
706
+ randomize: false,
707
+ onFailedAttempt: async (ctx) => {
708
+ if (ctx.error instanceof CloudflareBlockError) {
709
+ this.logger?.warn(`[NovelInfoQueue] 请求被 Cloudflare 阻挡,错误信息: ${ctx.error.message}。正在等待 ${this.backoff.FAILURE_DELAY / 1e3}s 后重试...`);
710
+ await this._sleep(this.backoff.FAILURE_DELAY);
711
+ }
712
+ if (ctx.attemptNumber >= (retry.retries ?? 3)) this.logger?.error(`[NovelInfoQueue] 请求重试次数已达上限 (${ctx.attemptNumber} 次),错误信息: ${ctx.error.message}`);
713
+ },
714
+ shouldRetry: async (ctx) => {
715
+ return defaultRetryPolicy(ctx) || ctx.error instanceof CloudflareBlockError;
716
+ }
717
+ };
718
+ const updateInfo = await getUpdateInfo(id, this.client, retry);
719
+ if (!updateInfo) this.logger?.warn(`[NovelInfoQueue] 无法获取小说${id}的更新信息,可能是因为小说不存在或已被删除`);
720
+ else this.logger?.debug(`[NovelInfoQueue] 小说${id} 更新信息获取成功。下一次请求将在 ${this.backoff.getDelayForSuccess().toFixed(0)}ms 后进行`);
721
+ await this._sleep(this.backoff.getDelayForSuccess());
722
+ return updateInfo;
723
+ });
724
+ }
725
+ };
726
+ //#endregion
727
+ //#region src/session.ts
728
+ async function refreshSessionId(fetchClient, loginConfig) {
729
+ await fetchClient.request({
730
+ url: "https://www.linovelib.com/login.php",
731
+ method: "GET",
732
+ headers: { referer: "https://www.linovelib.com/" }
733
+ });
734
+ return (await fetchClient.request({
735
+ url: "https://www.linovelib.com/login.php?do=submit&jumpurl=https%3A%2F%2Fwww.linovelib.com%2F",
736
+ method: "POST",
737
+ body: new URLSearchParams({
738
+ username: loginConfig.username,
739
+ password: loginConfig.password,
740
+ usecookie: "3153600000",
741
+ submit: "登录",
742
+ action: "login"
743
+ }),
744
+ followRedirects: false
745
+ })).cookies.findIndex((cookie) => cookie.name === "PHPSESSID") !== -1;
746
+ }
747
+ async function hasValidSession(fetchClient) {
748
+ if ((await fetchClient.text("https://www.linovelib.com")).data.includes("用户中心")) return true;
749
+ else return false;
750
+ }
751
+ async function ensureValidSession(fetchClient, loginConfig) {
752
+ if (!await hasValidSession(fetchClient)) {
753
+ if (!(await refreshSessionId(fetchClient, loginConfig) && await hasValidSession(fetchClient))) return false;
754
+ }
755
+ return true;
756
+ }
757
+ //#endregion
758
+ //#region src/client.ts
759
+ var LinovelibClient = class {
760
+ storage;
761
+ fetchClient;
762
+ novelChapterQueue;
763
+ novelInfoQueue;
764
+ searchQueue;
765
+ options;
766
+ logger;
767
+ isSessionValid = void 0;
768
+ constructor(options, storage, logger) {
769
+ const defaultOptions = {
770
+ session: { enabled: false },
771
+ flareSolverr: {
772
+ enabled: true,
773
+ host: "http://localhost:8191",
774
+ timeoutMs: 6e4,
775
+ sessionId: "acanthis-linovelib-client"
776
+ },
777
+ impersonate: {
778
+ enabled: true,
779
+ profile: "chrome149-linux"
780
+ },
781
+ cookies: { type: "memory" }
782
+ };
783
+ this.options = deepmerge(defaultOptions, options ?? {});
784
+ this.storage = storage;
785
+ this.logger = logger;
786
+ const browserFetchOptions = {};
787
+ if (this.options?.flareSolverr.enabled) browserFetchOptions.flareSolverr = {
788
+ enabled: true,
789
+ host: this.options.flareSolverr.host,
790
+ timeoutMs: this.options.flareSolverr.timeoutMs ?? 6e4,
791
+ sessionId: this.options.flareSolverr.sessionId ?? "acanthis-linovelib-client"
792
+ };
793
+ else browserFetchOptions.flareSolverr = { enabled: false };
794
+ if (this.options?.proxy) browserFetchOptions.proxy = this.options.proxy;
795
+ if (this.options?.impersonate.enabled) browserFetchOptions.profile = this.options.impersonate.profile;
796
+ switch (this.options?.cookies.type) {
797
+ case "memory":
798
+ browserFetchOptions.cookieStore = { type: "memory" };
799
+ break;
800
+ case "file":
801
+ browserFetchOptions.cookieStore = {
802
+ type: "file",
803
+ path: this.options.cookies.path
804
+ };
805
+ break;
806
+ case "database":
807
+ if (!this.storage) throw new Error("StorageService is required for database cookie store");
808
+ browserFetchOptions.cookieStore = {
809
+ type: "custom",
810
+ store: this.storage.getCookieStore()
811
+ };
812
+ break;
813
+ default: browserFetchOptions.cookieStore = { type: "memory" };
814
+ }
815
+ this.fetchClient = new BrowserFetchClient(browserFetchOptions);
816
+ this.novelChapterQueue = new NovelChapterQueue(this.fetchClient, this.logger);
817
+ this.novelInfoQueue = new NovelInfoQueue(this.fetchClient, this.novelChapterQueue, this.logger);
818
+ this.searchQueue = new SearchQueue(this.fetchClient, this.logger);
819
+ }
820
+ async getNovelInfo(id) {
821
+ if (this.options?.session.enabled && !this.isSessionValid) this.isSessionValid = await ensureValidSession(this.fetchClient, {
822
+ username: this.options.session.username,
823
+ password: this.options.session.password
824
+ });
825
+ return await this.novelInfoQueue.fetchNovelInfo(id);
826
+ }
827
+ async getNovelUpdateInfo(id) {
828
+ if (this.options?.session.enabled && !this.isSessionValid) this.isSessionValid = await ensureValidSession(this.fetchClient, {
829
+ username: this.options.session.username,
830
+ password: this.options.session.password
831
+ });
832
+ return await this.novelInfoQueue.fetchNovelUpdateInfo(id);
833
+ }
834
+ async searchNovels(keyword) {
835
+ if (this.options?.session.enabled && !this.isSessionValid) this.isSessionValid = await ensureValidSession(this.fetchClient, {
836
+ username: this.options.session.username,
837
+ password: this.options.session.password
838
+ });
839
+ return await this.searchQueue.searchNovels(keyword);
840
+ }
841
+ async getNovelCover(novelId) {
842
+ return await getCover(novelId, this.fetchClient);
843
+ }
844
+ async getCover(url) {
845
+ return await this.fetchClient.binary(url, { headers: { Referer: "https://www.linovelib.com/" } });
846
+ }
847
+ async getChapter(novelId, chapterId) {
848
+ if (this.options?.session.enabled && !this.isSessionValid) this.isSessionValid = await ensureValidSession(this.fetchClient, {
849
+ username: this.options.session.username,
850
+ password: this.options.session.password
851
+ });
852
+ const cachedJsVersion = this.storage ? await this.storage.getCache("chapterlog_js_version", z$1.string()) ?? void 0 : void 0;
853
+ const cachedCoefficients = this.storage ? await this.storage.getCache("coefficients", descrambleCoefficientsSchema) ?? void 0 : void 0;
854
+ const result = await getChapter(chapterId, novelId, this.novelChapterQueue, this.fetchClient, cachedJsVersion, cachedCoefficients);
855
+ if (this.storage && result) {
856
+ await this.storage.setCache("chapterlog_js_version", result.version);
857
+ await this.storage.setCache("coefficients", result.coefficients);
858
+ }
859
+ return result?.content;
860
+ }
861
+ };
862
+ //#endregion
863
+ export { LinovelibClient, novelIdToCoverUrl };
864
+
865
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":["z"],"sources":["../src/coefficients.ts","../src/utils.ts","../src/chapter.ts","../src/cover.ts","../src/novel.ts","../src/search.ts","../src/queue.ts","../src/session.ts","../src/client.ts"],"sourcesContent":["import type { BrowserFetchClient } from \"@acanthis-dec/browser-fetch\";\nimport type { DescrambleCoefficients } from \"@acanthis-dec/core\";\nimport { deobfuscate } from \"@acanthis-dec/deobfuscator\";\nimport { parse } from \"@babel/parser\";\nimport traverseModule from \"@babel/traverse\";\nimport * as t from \"@babel/types\";\nimport * as cheerio from \"cheerio\";\nimport { z } from \"zod\";\n\ntype TraverseFunction = typeof traverseModule;\n\nconst traverse =\n\t(traverseModule as unknown as { default?: TraverseFunction }).default ??\n\ttraverseModule;\n\nexport const descrambleCoefficientsSchema = z.object({\n\tmodulus: z.number().int(),\n\tincrement: z.number().int(),\n\tmultiplier: z.number().int(),\n\tseedOffset: z.number().int(),\n\tseedMultiplier: z.number().int(),\n});\n\nfunction getObfuscatedPart(fullCode: string): string {\n\treturn fullCode\n\t\t.split(/\\r?\\n/)\n\t\t.map((line) => line.trim())\n\t\t.filter((line) => line !== \"\")\n\t\t.slice(-2)\n\t\t.join(\"\\n\");\n}\n\nexport async function extractCoefficients(\n\tscript: string,\n): Promise<DescrambleCoefficients> {\n\tconst obfuscatedPart = getObfuscatedPart(script);\n\tconst deObfCode = await deobfuscate(obfuscatedPart);\n\tconst ast = parse(deObfCode, { sourceType: \"module\", plugins: [\"jsx\"] });\n\tconst coefficients: Partial<DescrambleCoefficients> = {};\n\ttraverse(ast, {\n\t\tBinaryExpression(path) {\n\t\t\tconst { node } = path;\n\t\t\tif (\n\t\t\t\tnode.operator === \"%\" &&\n\t\t\t\tt.isNumericLiteral(node.right) &&\n\t\t\t\tt.isBinaryExpression(node.left) &&\n\t\t\t\tnode.left.operator === \"+\" &&\n\t\t\t\tt.isNumericLiteral(node.left.right) &&\n\t\t\t\tt.isBinaryExpression(node.left.left) &&\n\t\t\t\tnode.left.left.operator === \"*\" &&\n\t\t\t\tt.isNumericLiteral(node.left.left.right)\n\t\t\t) {\n\t\t\t\tcoefficients.modulus = node.right.value;\n\t\t\t\tconst leftSide = node.left;\n\t\t\t\tif (t.isBinaryExpression(leftSide) && leftSide.operator === \"+\") {\n\t\t\t\t\tif (t.isNumericLiteral(leftSide.right)) {\n\t\t\t\t\t\tcoefficients.increment = leftSide.right.value;\n\t\t\t\t\t}\n\t\t\t\t\tif (\n\t\t\t\t\t\tt.isBinaryExpression(leftSide.left) &&\n\t\t\t\t\t\tleftSide.left.operator === \"*\"\n\t\t\t\t\t) {\n\t\t\t\t\t\tif (t.isNumericLiteral(leftSide.left.right)) {\n\t\t\t\t\t\t\tcoefficients.multiplier = leftSide.left.right.value;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (\n\t\t\t\tnode.operator === \"+\" &&\n\t\t\t\tt.isNumericLiteral(node.right) &&\n\t\t\t\tt.isBinaryExpression(node.left) &&\n\t\t\t\tnode.left.operator === \"*\" &&\n\t\t\t\tt.isNumericLiteral(node.left.right)\n\t\t\t) {\n\t\t\t\tconst potentialOffset = node.right.value;\n\t\t\t\tconst potentialMultiplier = node.left.right.value;\n\t\t\t\tconst numberTransformed = node.left.left;\n\t\t\t\tif (\n\t\t\t\t\tt.isCallExpression(numberTransformed) &&\n\t\t\t\t\tt.isIdentifier(numberTransformed.callee) &&\n\t\t\t\t\t(numberTransformed.callee.name === \"Number\" ||\n\t\t\t\t\t\tnumberTransformed.callee.name === \"parseInt\")\n\t\t\t\t) {\n\t\t\t\t\tcoefficients.seedOffset = potentialOffset;\n\t\t\t\t\tcoefficients.seedMultiplier = potentialMultiplier;\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t});\n\tif (\n\t\tcoefficients.modulus === undefined ||\n\t\tcoefficients.increment === undefined ||\n\t\tcoefficients.multiplier === undefined ||\n\t\tcoefficients.seedOffset === undefined ||\n\t\tcoefficients.seedMultiplier === undefined\n\t) {\n\t\tthrow new Error(\"Failed to extract all coefficients\");\n\t}\n\treturn coefficients as DescrambleCoefficients;\n}\n\nexport function extractChapterLogScriptUrl(html: string): string {\n\tconst $ = cheerio.load(html);\n\tconst chapterLogScriptUrl =\n\t\t$(\n\t\t\t$(\"script\")\n\t\t\t\t.toArray()\n\t\t\t\t.find((el) => {\n\t\t\t\t\tconst scriptContent = $(el).attr(\"src\") || \"\";\n\t\t\t\t\treturn /chapterlog\\.js/.test(scriptContent);\n\t\t\t\t}),\n\t\t).attr(\"src\") || \"\";\n\treturn chapterLogScriptUrl.startsWith(\"http\")\n\t\t? chapterLogScriptUrl\n\t\t: `https://www.linovelib.com${chapterLogScriptUrl}`;\n}\n\nexport interface CoefficientResult {\n\tcoefficients: DescrambleCoefficients;\n\tversion: string;\n}\n\nexport async function getCoefficientsFromPage(\n\thtml: string,\n\tfetchClient: BrowserFetchClient,\n\tcachedVersion?: string,\n): Promise<CoefficientResult | undefined> {\n\tconst scriptUrl = extractChapterLogScriptUrl(html);\n\tif (!scriptUrl) {\n\t\tthrow new Error(\"Chapter log script URL not found\");\n\t}\n\tconst version = scriptUrl.match(/chapterlog\\.js\\?(v.*)/)?.[1] || \"\";\n\tif (version === cachedVersion) {\n\t\treturn undefined; // No need to fetch and extract again\n\t}\n\tconst scriptContent = await fetchClient.text(scriptUrl);\n\tif (!scriptContent.mimeType.includes(\"javascript\")) {\n\t\tthrow new Error(\"Fetched content is not JavaScript\");\n\t}\n\tconst coefficients = await extractCoefficients(scriptContent.data);\n\treturn {\n\t\tcoefficients,\n\t\tversion: version,\n\t};\n}\n","export function extractNovelIdFromUrl(url: string): string | undefined {\n\tconst match = url.match(/\\/novel\\/(\\d+)\\.html/);\n\treturn match ? match[1] : undefined;\n}\n\nexport interface NovelAndChapterIds {\n\tnovelId: string | undefined;\n\tchapterId: string | undefined;\n}\n\nexport function extractChapterIdFromUrl(\n\turl: string,\n): NovelAndChapterIds | undefined {\n\tconst match = url.match(/\\/novel\\/(\\d+)\\/(\\d+)\\.html/);\n\tif (match) {\n\t\treturn {\n\t\t\tnovelId: match[1],\n\t\t\tchapterId: match[2],\n\t\t};\n\t}\n\treturn undefined;\n}\n\nexport function transformChapterName(name: string): string {\n\tconst chapNameTransDict: Record<string, string> = {\n\t\t\"\\u004e\": \"\\u5973\",\n\t};\n\treturn name.replace(/./g, (char) => chapNameTransDict[char] || char);\n}\n\nexport function transformContent(content: string): string {\n\tconst contentTransDict: Record<string, string> = {\n\t\t\"\\u201c\": \"\\u300c\",\n\t\t\"\\u201d\": \"\\u300d\",\n\t\t\"\\u2018\": \"\\u300e\",\n\t\t\"\\u2019\": \"\\u300f\",\n\t\t\"\\ue82c\": \"\\u7684\",\n\t\t\"\\ue852\": \"\\u4e00\",\n\t\t\"\\ue82d\": \"\\u662f\",\n\t\t\"\\ue819\": \"\\u4e86\",\n\t\t\"\\ue856\": \"\\u6211\",\n\t\t\"\\ue857\": \"\\u4e0d\",\n\t\t\"\\ue816\": \"\\u4eba\",\n\t\t\"\\ue83c\": \"\\u5728\",\n\t\t\"\\ue830\": \"\\u4ed6\",\n\t\t\"\\ue82e\": \"\\u6709\",\n\t\t\"\\ue836\": \"\\u8fd9\",\n\t\t\"\\ue859\": \"\\u4e2a\",\n\t\t\"\\ue80a\": \"\\u4e0a\",\n\t\t\"\\ue855\": \"\\u4eec\",\n\t\t\"\\ue842\": \"\\u6765\",\n\t\t\"\\ue858\": \"\\u5230\",\n\t\t\"\\ue80b\": \"\\u65f6\",\n\t\t\"\\ue81f\": \"\\u5927\",\n\t\t\"\\ue84a\": \"\\u5730\",\n\t\t\"\\ue853\": \"\\u4e3a\",\n\t\t\"\\ue81e\": \"\\u5b50\",\n\t\t\"\\ue822\": \"\\u4e2d\",\n\t\t\"\\ue813\": \"\\u4f60\",\n\t\t\"\\ue85b\": \"\\u8bf4\",\n\t\t\"\\ue807\": \"\\u751f\",\n\t\t\"\\ue818\": \"\\u56fd\",\n\t\t\"\\ue810\": \"\\u5e74\",\n\t\t\"\\ue812\": \"\\u7740\",\n\t\t\"\\ue851\": \"\\u5c31\",\n\t\t\"\\ue801\": \"\\u90a3\",\n\t\t\"\\ue80c\": \"\\u548c\",\n\t\t\"\\ue815\": \"\\u8981\",\n\t\t\"\\ue84c\": \"\\u5979\",\n\t\t\"\\ue840\": \"\\u51fa\",\n\t\t\"\\ue848\": \"\\u4e5f\",\n\t\t\"\\ue835\": \"\\u5f97\",\n\t\t\"\\ue800\": \"\\u91cc\",\n\t\t\"\\ue826\": \"\\u540e\",\n\t\t\"\\ue863\": \"\\u81ea\",\n\t\t\"\\ue861\": \"\\u4ee5\",\n\t\t\"\\ue854\": \"\\u4f1a\",\n\t\t\"\\ue827\": \"\\u5bb6\",\n\t\t\"\\ue83b\": \"\\u53ef\",\n\t\t\"\\ue85d\": \"\\u4e0b\",\n\t\t\"\\ue84d\": \"\\u800c\",\n\t\t\"\\ue862\": \"\\u8fc7\",\n\t\t\"\\ue81c\": \"\\u5929\",\n\t\t\"\\ue81d\": \"\\u53bb\",\n\t\t\"\\ue860\": \"\\u80fd\",\n\t\t\"\\ue843\": \"\\u5bf9\",\n\t\t\"\\ue82f\": \"\\u5c0f\",\n\t\t\"\\ue802\": \"\\u591a\",\n\t\t\"\\ue831\": \"\\u7136\",\n\t\t\"\\ue84b\": \"\\u4e8e\",\n\t\t\"\\ue837\": \"\\u5fc3\",\n\t\t\"\\ue829\": \"\\u5b66\",\n\t\t\"\\ue85e\": \"\\u4e48\",\n\t\t\"\\ue83a\": \"\\u4e4b\",\n\t\t\"\\ue832\": \"\\u90fd\",\n\t\t\"\\ue808\": \"\\u597d\",\n\t\t\"\\ue841\": \"\\u770b\",\n\t\t\"\\ue821\": \"\\u8d77\",\n\t\t\"\\ue845\": \"\\u53d1\",\n\t\t\"\\ue803\": \"\\u5f53\",\n\t\t\"\\ue828\": \"\\u6ca1\",\n\t\t\"\\ue81b\": \"\\u6210\",\n\t\t\"\\ue83e\": \"\\u53ea\",\n\t\t\"\\ue820\": \"\\u5982\",\n\t\t\"\\ue84e\": \"\\u4e8b\",\n\t\t\"\\ue85a\": \"\\u628a\",\n\t\t\"\\ue806\": \"\\u8fd8\",\n\t\t\"\\ue83f\": \"\\u7528\",\n\t\t\"\\ue833\": \"\\u7b2c\",\n\t\t\"\\ue811\": \"\\u6837\",\n\t\t\"\\ue804\": \"\\u9053\",\n\t\t\"\\ue814\": \"\\u60f3\",\n\t\t\"\\ue80f\": \"\\u4f5c\",\n\t\t\"\\ue84f\": \"\\u79cd\",\n\t\t\"\\ue80e\": \"\\u5f00\",\n\t\t\"\\ue823\": \"\\u7f8e\",\n\t\t\"\\ue849\": \"\\u4e73\",\n\t\t\"\\ue805\": \"\\u9634\",\n\t\t\"\\ue809\": \"\\u6db2\",\n\t\t\"\\ue81a\": \"\\u830e\",\n\t\t\"\\ue844\": \"\\u6b32\",\n\t\t\"\\ue847\": \"\\u547b\",\n\t\t\"\\ue850\": \"\\u8089\",\n\t\t\"\\ue824\": \"\\u4ea4\",\n\t\t\"\\ue85f\": \"\\u6027\",\n\t\t\"\\ue817\": \"\\u80f8\",\n\t\t\"\\ue85c\": \"\\u79c1\",\n\t\t\"\\ue838\": \"\\u7a74\",\n\t\t\"\\ue82a\": \"\\u6deb\",\n\t\t\"\\ue83d\": \"\\u81c0\",\n\t\t\"\\ue82b\": \"\\u8214\",\n\t\t\"\\ue80d\": \"\\u5c04\",\n\t\t\"\\ue839\": \"\\u8131\",\n\t\t\"\\ue834\": \"\\u88f8\",\n\t\t\"\\ue846\": \"\\u9a9a\",\n\t\t\"\\ue825\": \"\\u5507\",\n\t};\n\treturn content.replace(/./g, (char) => contentTransDict[char] || char);\n}\n","import type { BrowserFetchClient } from \"@acanthis-dec/browser-fetch\";\nimport {\n\tbuildDescrambleMapping,\n\ttype DescrambleCoefficients,\n} from \"@acanthis-dec/core\";\nimport * as cheerio from \"cheerio\";\nimport type { AnyNode, Element } from \"domhandler\";\nimport { getCoefficientsFromPage } from \"./coefficients\";\nimport type { NovelChapterQueue } from \"./queue\";\nimport { transformContent } from \"./utils\";\n\nfunction extractChapterId($: cheerio.CheerioAPI): string {\n\tconst scriptTags = $(\"script\");\n\tlet chapterId = \"\";\n\tscriptTags.each((_, el) => {\n\t\tconst scriptContent = $(el).html();\n\t\tif (scriptContent) {\n\t\t\tconst match = scriptContent.match(/chapterid\\s*:\\s*'(\\d+)'/);\n\t\t\tif (match?.[1]) {\n\t\t\t\tchapterId = match[1];\n\t\t\t\treturn false; // Break the loop\n\t\t\t}\n\t\t}\n\t});\n\treturn chapterId;\n}\n\nexport interface DecryptResult {\n\tcontent: string;\n\tversion: string;\n\tcoefficients: DescrambleCoefficients;\n}\n\nasync function decrypt(\n\thtml: string,\n\tfetchClient: BrowserFetchClient,\n\tcachedJsVersion?: string,\n\tcachedCoefficients?: DescrambleCoefficients,\n): Promise<DecryptResult> {\n\tconst $ = cheerio.load(html);\n\tconst coefficientResult = await getCoefficientsFromPage(\n\t\thtml,\n\t\tfetchClient,\n\t\tcachedJsVersion,\n\t);\n\tconst version = coefficientResult?.version || cachedJsVersion;\n\tconst coefficients = coefficientResult?.coefficients || cachedCoefficients;\n\tif (!version) {\n\t\tthrow new Error(\"Failed to determine chapterlog.js version\");\n\t}\n\tif (!coefficients) {\n\t\tthrow new Error(\"Failed to obtain descrambling coefficients\");\n\t}\n\tconst chapterId = extractChapterId($);\n\tconst container = $(\"#TextContent, #acontent\");\n\tif (!container.length) {\n\t\treturn {\n\t\t\tcontent: \"\",\n\t\t\tversion,\n\t\t\tcoefficients: coefficients,\n\t\t};\n\t}\n\n\tcontainer.find(\"p\").each((_, el) => {\n\t\tconst $el = $(el);\n\t\tconst innerHtml = $el.html();\n\t\tif (innerHtml) {\n\t\t\tconst cleanedHtml = innerHtml.replace(/^\\s+|(?<=>)\\s+/g, \"\");\n\t\t\t$el.html(cleanedHtml);\n\t\t}\n\t});\n\n\tcontainer.find(\"img.imagecontent\").each((_, el) => {\n\t\tconst imgSrc = $(el).attr(\"data-src\") || $(el).attr(\"src\");\n\t\tif (imgSrc) {\n\t\t\t$(el).attr(\"src\", imgSrc).removeAttr(\"data-src\");\n\t\t}\n\t});\n\n\tcontainer.find(\"div.dag\").remove();\n\tcontainer.find(\"script\").remove();\n\n\tconst allChildren = container\n\t\t.contents()\n\t\t.toArray()\n\t\t.filter((node) => !(node.type === \"tag\" && node.tagName === \"div\"));\n\tconst sortableEntries: { element: Element; originalPos: number }[] = [];\n\tallChildren.forEach((node, index) => {\n\t\tif (node.type === \"tag\" && node.tagName === \"p\") {\n\t\t\tconst text = $(node).text().trim();\n\t\t\tif (text.length > 0) {\n\t\t\t\tsortableEntries.push({ element: node, originalPos: index });\n\t\t\t}\n\t\t}\n\t});\n\n\tconst seed =\n\t\tparseInt(chapterId, 10) * coefficients?.seedMultiplier +\n\t\tcoefficients?.seedOffset;\n\n\tconst mapping = buildDescrambleMapping(\n\t\tsortableEntries.length,\n\t\tseed,\n\t\tcoefficients,\n\t\t20,\n\t);\n\n\tconst restoredChildren: (AnyNode | null)[] = [...allChildren];\n\n\tsortableEntries.forEach((entry, i) => {\n\t\tconst targetIndex = mapping[i] ?? i;\n\t\tconst actualSlot = sortableEntries[targetIndex]?.originalPos ?? 0;\n\t\trestoredChildren[actualSlot] = entry.element;\n\t});\n\n\tconst newContainer = $(\"<div></div>\");\n\trestoredChildren.forEach((node) => {\n\t\tif (node && node.type === \"tag\") {\n\t\t\tnewContainer.append(node);\n\t\t\tnewContainer.append(\"\\n\");\n\t\t}\n\t});\n\n\treturn {\n\t\tcontent: newContainer.html() || \"\",\n\t\tversion,\n\t\tcoefficients: coefficients,\n\t};\n}\n\nexport async function getChapter(\n\tid: string,\n\tnovelId: string,\n\tchapterQueue: NovelChapterQueue,\n\tfetchClient: BrowserFetchClient,\n\tcachedJsVersion?: string,\n\tcachedCoefficients?: DescrambleCoefficients,\n): Promise<DecryptResult | undefined> {\n\tconst firstPageHtml = await chapterQueue.fetchChapterPart(\n\t\t`https://www.linovelib.com/novel/${novelId}/${id}.html`,\n\t);\n\tlet $ = cheerio.load(firstPageHtml);\n\tconst chapterName = $(\"h1\").text().trim();\n\tlet nextPageId =\n\t\t$(\"div.mlfy_page a:last\")\n\t\t\t.attr(\"href\")\n\t\t\t?.match(/\\/novel\\/(\\d+)\\/([\\d_]+)\\.html/)?.[2] ||\n\t\tfirstPageHtml.match(/url_next:'\\/novel\\/(\\d+)\\/([\\d_]+)\\.html'/)?.[2] ||\n\t\t\"\";\n\tlet content = await decrypt(\n\t\tfirstPageHtml,\n\t\tfetchClient,\n\t\tcachedJsVersion,\n\t\tcachedCoefficients,\n\t);\n\tcachedCoefficients = content.coefficients;\n\tcachedJsVersion = content.version;\n\twhile (nextPageId?.includes(id)) {\n\t\tconst nextPageHtml = await chapterQueue.fetchChapterPart(\n\t\t\t`https://www.linovelib.com/novel/${novelId}/${nextPageId}.html`,\n\t\t);\n\t\tconst nextContent = await decrypt(\n\t\t\tnextPageHtml,\n\t\t\tfetchClient,\n\t\t\tcachedJsVersion,\n\t\t\tcachedCoefficients,\n\t\t);\n\t\tcontent = {\n\t\t\t...content,\n\t\t\tcontent: content.content + nextContent.content,\n\t\t};\n\t\t$ = cheerio.load(nextPageHtml);\n\t\tnextPageId =\n\t\t\t$(\"div.mlfy_page a:last\")\n\t\t\t\t.attr(\"href\")\n\t\t\t\t?.match(/\\/novel\\/(\\d+)\\/([\\d_]+)\\.html/)?.[2] ||\n\t\t\tnextPageHtml.match(/url_next:'\\/novel\\/(\\d+)\\/([\\d_]+)\\.html/)?.[2] ||\n\t\t\t\"\";\n\t}\n\t// content = `<h2>${chapterName}</h2>\\n${transformContent(content)}`;\n\tcontent = {\n\t\t...content,\n\t\tcontent: `<h2>${chapterName}</h2>\\n${transformContent(content.content)}`,\n\t};\n\treturn content;\n}\n","import type {\n\tBinaryResponse,\n\tBrowserFetchClient,\n} from \"@acanthis-dec/browser-fetch\";\n\nexport function novelIdToCoverUrl(novelId: string): string {\n\tconst prefix = novelId.length > 3 ? novelId[0] : \"0\";\n\treturn `https://www.linovelib.com/files/article/image/${prefix}/${novelId}/${novelId}s.jpg`;\n}\n\nexport async function getCover(\n\tnovelId: string,\n\tfetchClient: BrowserFetchClient,\n): Promise<BinaryResponse> {\n\tconst url = novelIdToCoverUrl(novelId);\n\tconst response = await fetchClient.binary(url);\n\treturn response;\n}\n","import type {\n\tBrowserFetchClient,\n\tRetryOptions,\n} from \"@acanthis-dec/browser-fetch\";\nimport type { Chapter, Novel, NovelStatus, Volume } from \"@acanthis-dec/core\";\nimport * as cheerio from \"cheerio\";\nimport type { Element } from \"domhandler\";\nimport { novelIdToCoverUrl } from \"./cover\";\nimport type { NovelChapterQueue } from \"./queue\";\n\nfunction extractVolumesArray(catalog: string): Element[] {\n\tconst $ = cheerio.load(catalog);\n\tconst results: Element[] = [];\n\t$(\"#volume-list div.volume\").each((_, elem) => {\n\t\t$(elem).remove(\"div.volume\");\n\t\tresults.push(elem);\n\t});\n\treturn results;\n}\n\nfunction processVolumeName(novelTitle: string, volumeName: string): string {\n\t// Remove novel title from volume name if present\n\tif (volumeName.startsWith(novelTitle)) {\n\t\treturn volumeName.slice(novelTitle.length).trim();\n\t}\n\tif (!Number.isNaN(Number(volumeName))) {\n\t\treturn `第 ${volumeName} 卷`;\n\t}\n\treturn volumeName.trim();\n}\n\nfunction parseVolumeOrChapterId(url: string): string {\n\tif (url.includes(\"javascript:cid(0)\")) {\n\t\treturn \"TOBEDETERMINED\";\n\t}\n\tconst match = url.match(/\\/novel\\/\\d+\\/(\\d+|vol_\\d+)\\.html/);\n\treturn match ? (match[1] ?? \"\") : \"\";\n}\n\nasync function parseChapterIdFromNextChapter(\n\tnextChapterEl: Element,\n\tchapterQueue: NovelChapterQueue,\n): Promise<string> {\n\tconst nextChapterPath = nextChapterEl.attribs.href ?? \"\";\n\tconst nextChapterContent = await chapterQueue.fetchChapterPart(\n\t\t`https://www.linovelib.com${nextChapterPath}`,\n\t);\n\tconst $temp = cheerio.load(nextChapterContent);\n\tconst chapterPath =\n\t\t$temp(\"div.mlfy_page a:first\").attr(\"href\") ??\n\t\tnextChapterContent.match(\n\t\t\t/url_previous:'(\\/novel\\/\\d+\\/[\\d_]+\\.html)'/,\n\t\t)?.[1] ??\n\t\t\"\";\n\treturn parseVolumeOrChapterId(chapterPath);\n}\n\nasync function getNovelVolumes(\n\ttitle: string,\n\turl: string,\n\tfetchClient: BrowserFetchClient,\n\tretry: RetryOptions,\n\tchapterQueue?: NovelChapterQueue,\n): Promise<Volume[]> {\n\tconst catalogHtml = await fetchClient.text(url, { retry });\n\tconst volumeEls = extractVolumesArray(catalogHtml.data);\n\tconst volumes: Volume[] = [];\n\tconst chapterElements: Element[] = [];\n\tfor (const volumeEl of volumeEls) {\n\t\tconst volumeEl$ = cheerio.load(volumeEl);\n\t\tconst volumeName = processVolumeName(title, volumeEl$(\"h2\").text());\n\t\tconst volumeId = parseVolumeOrChapterId(\n\t\t\tvolumeEl$(\"h2 a\").attr(\"href\") ?? \"\",\n\t\t);\n\t\tconst volumeCover: string =\n\t\t\tvolumeEl$(\"a.volume-cover img\").attr(\"data-original\") ?? \"\";\n\t\tconst chapterEls = volumeEl$(\"ul.chapter-list li a\").toArray();\n\t\tconst chapters: Chapter[] = [];\n\t\tfor (const [index, chapterEl] of chapterEls.entries()) {\n\t\t\tchapterElements.push(chapterEl);\n\t\t\tconst chapterEl$ = cheerio.load(chapterEl);\n\t\t\tconst chapterName = chapterEl$.text().trim();\n\t\t\tconst chapterPath = chapterEl.attribs.href ?? \"\";\n\t\t\tlet chapterId = parseVolumeOrChapterId(chapterPath);\n\t\t\tif (chapterId === \"TOBEDETERMINED\" && chapterQueue) {\n\t\t\t\tconst nextChapterEl = chapterEls[index + 1];\n\t\t\t\tif (nextChapterEl) {\n\t\t\t\t\tchapterId = await parseChapterIdFromNextChapter(\n\t\t\t\t\t\tnextChapterEl,\n\t\t\t\t\t\tchapterQueue,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\tchapters.push({\n\t\t\t\tid: chapterId,\n\t\t\t\tplatform: \"linovelib\",\n\t\t\t\ttitle: chapterName,\n\t\t\t\tvolumeId,\n\t\t\t});\n\t\t}\n\t\tvolumes.push({\n\t\t\tid: volumeId,\n\t\t\tplatform: \"linovelib\",\n\t\t\ttitle: volumeName,\n\t\t\tcoverUrl: volumeCover,\n\t\t\tchapters: chapters,\n\t\t});\n\t}\n\treturn volumes;\n}\n\nexport async function getNovelInfo(\n\tid: string,\n\tfetchClient: BrowserFetchClient,\n\tretry: RetryOptions,\n\tchapterQueue?: NovelChapterQueue,\n): Promise<Novel | undefined> {\n\tconst url = `https://www.linovelib.com/novel/${id}.html`;\n\tconst html = (\n\t\tawait fetchClient.text(url, {\n\t\t\tretry,\n\t\t})\n\t).data;\n\tconst $ = cheerio.load(html);\n\tconst title = $(\"h1.book-name\").text().trim();\n\tconst coverUrl = $(\"div.book-img img\").attr(\"src\") || novelIdToCoverUrl(id);\n\tconst summary = (() => {\n\t\tconst $container = $(\".book-dec.Jbook-dec\").clone();\n\t\t$container.find(\".notice\").remove();\n\t\tconst paragraphs: string[] = [];\n\t\t$container\n\t\t\t.find(\"p\")\n\t\t\t.not(\".backupname\")\n\t\t\t.each((_, el) => {\n\t\t\t\tparagraphs.push($(el).text().trim());\n\t\t\t});\n\t\treturn paragraphs.join(\"\\n\");\n\t})();\n\tconst author = $(\"div.au-name a:first\").text().trim();\n\tconst status: NovelStatus = $(\"div.book-label a.state\")\n\t\t.text()\n\t\t.includes(\"完结\")\n\t\t? \"completed\"\n\t\t: \"ongoing\";\n\tconst genres = $(\"div.book-label span\")\n\t\t.children(\"a\")\n\t\t.map((_, el) => $(el).text())\n\t\t.toArray()\n\t\t.join(\",\");\n\tconst novel: Novel = {\n\t\tid,\n\t\tplatform: \"linovelib\",\n\t\ttitle,\n\t\tcoverUrl,\n\t\tsummary,\n\t\tauthor,\n\t\tstatus,\n\t\tgenres: genres.split(\",\").map((g) => g.trim()),\n\t\tvolumes: [], // Volumes and chapters will be fetched separately\n\t};\n\tnovel.volumes = (\n\t\tawait getNovelVolumes(\n\t\t\ttitle,\n\t\t\t`https://www.linovelib.com${$(\"a.read-btn\").attr(\"href\")}`,\n\t\t\tfetchClient,\n\t\t\tretry,\n\t\t\tchapterQueue,\n\t\t)\n\t).map((v) => {\n\t\tv.novelId = novel.id;\n\t\treturn v;\n\t});\n\treturn novel;\n}\n\nexport interface NovelUpdateInfo {\n\tcoverUrl: string;\n\tchapterCount: number;\n}\n\nexport async function getUpdateInfo(\n\tid: string,\n\tfetchClient: BrowserFetchClient,\n\tretry: RetryOptions,\n): Promise<NovelUpdateInfo | null> {\n\tconst url = `https://www.linovelib.com/novel/${id}.html`;\n\tconst html = (\n\t\tawait fetchClient.text(url, {\n\t\t\tretry,\n\t\t})\n\t).data;\n\tconst $ = cheerio.load(html);\n\tif ($(\"h1.book-name\").length === 0) {\n\t\treturn null;\n\t}\n\tconst catalogUrl = `https://www.linovelib.com${$(\"a.read-btn\").attr(\"href\")}`;\n\tconst catalogHtml = (\n\t\tawait fetchClient.text(catalogUrl, {\n\t\t\tretry,\n\t\t})\n\t).data;\n\tconst $catalog = cheerio.load(catalogHtml);\n\tconst chapterCount = $catalog(\n\t\t\"#volume-list div.volume ul.chapter-list li a\",\n\t).length;\n\tconst coverUrl = $(\"div.book-img img\").attr(\"src\") || novelIdToCoverUrl(id);\n\treturn {\n\t\tcoverUrl,\n\t\tchapterCount,\n\t};\n}\n","import { webcrypto } from \"node:crypto\";\nimport type { BrowserFetchClient } from \"@acanthis-dec/browser-fetch\";\nimport type { NovelSearchResult } from \"@acanthis-dec/core\";\nimport * as cheerio from \"cheerio\";\nimport { extractNovelIdFromUrl } from \"./utils\";\n\nfunction k(e: string): Uint8Array<ArrayBuffer> {\n\t// 标准 Base64 映射表\n\tconst t = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\";\n\n\t// 1. 过滤掉所有不在映射表中的字符 (对应原代码的正则)\n\tconst n = e.replace(/[^A-Za-z0-9+/]/g, \"\");\n\tconst r = n.length;\n\n\t// 2. 计算输出长度:每 4 个字符转为 3 个字节\n\t// 注意:原代码通常不处理末尾填充,直接通过位移计算\n\tconst buf = new Uint8Array(Math.floor(r * 0.75));\n\tlet i = 0, // buf 指针\n\t\ta = 0, // 累加器\n\t\ts = 0, // 当前位深\n\t\tc = 0; // 临时索引\n\tfor (let l = 0; l < r; l++) {\n\t\tc = t.indexOf(n[l] || \"\");\n\t\tif (c === -1) continue; // 安全检查\n\t\ta = (a << 6) | c; // 每个 Base64 字符携带 6 位信息\n\t\ts += 6;\n\t\tif (s >= 8) {\n\t\t\ts -= 8;\n\t\t\t// 提取高 8 位存入字节数组\n\t\t\tbuf[i++] = (a >> s) & 255;\n\t\t}\n\t}\n\t// 关键:必须截取到实际写入的长度\n\t// 并强制转换为 Uint8Array<ArrayBuffer>\n\treturn new Uint8Array(buf.buffer.slice(0, i)) as Uint8Array<ArrayBuffer>;\n}\n\nasync function solveSearchChallenge(\n\ta: string,\n\tb: string,\n\tc: string,\n): Promise<string> {\n\tconst subtle = webcrypto.subtle;\n\t// 使用 as Uint8Array 明确告诉 TS 这是它需要的 BufferSource\n\tconst keyData = k(a);\n\tconst counterData = k(b);\n\tconst encryptedData = k(c);\n\ttry {\n\t\tconst cryptoKey = await subtle.importKey(\n\t\t\t\"raw\",\n\t\t\tkeyData,\n\t\t\t{ name: \"AES-CTR\" },\n\t\t\tfalse,\n\t\t\t[\"decrypt\"],\n\t\t);\n\t\tconst decryptedBuffer = await subtle.decrypt(\n\t\t\t{\n\t\t\t\tname: \"AES-CTR\",\n\t\t\t\tcounter: counterData,\n\t\t\t\tlength: 64,\n\t\t\t},\n\t\t\tcryptoKey,\n\t\t\tencryptedData,\n\t\t);\n\t\t// decryptedBuffer 得到的是 ArrayBuffer,需要转回 Uint8Array 供 TextDecoder 使用\n\t\tconst decoder = new TextDecoder();\n\t\tconst plainText = decoder.decode(new Uint8Array(decryptedBuffer));\n\t\treturn encodeURIComponent(plainText);\n\t} catch (error) {\n\t\tthrow new Error(`解密失败: ${error}`);\n\t}\n}\n\nexport async function searchNovels(\n\tkeyword: string,\n\tfetchClient: BrowserFetchClient,\n): Promise<NovelSearchResult[]> {\n\tlet response = await fetchClient.text(\"https://www.linovelib.com/S6/\", {\n\t\tmethod: \"POST\",\n\t\tbody: new URLSearchParams({\n\t\t\tsearchkey: keyword,\n\t\t}),\n\t\theaders: {\n\t\t\torigin: \"https://www.linovelib.com\",\n\t\t\treferer: \"https://www.linovelib.com/\",\n\t\t},\n\t});\n\tif (response.mimeType !== \"text/html\") {\n\t\tthrow new Error(`Unexpected response type: ${response.mimeType}`);\n\t}\n\tlet $ = cheerio.load(response.data);\n\tif ($(\"#challenge-running\").length > 0) {\n\t\tlet a = \"\",\n\t\t\tb = \"\",\n\t\t\tc = \"\";\n\t\t$(\"script\").each((_, el) => {\n\t\t\tconst scriptContent = $(el).html() || \"\";\n\t\t\tif (/window\\.a\\s*=\\s*'([^']+)'/.test(scriptContent)) {\n\t\t\t\ta = scriptContent.match(/window\\.a\\s*=\\s*'([^']+)'/)?.[1] || \"\";\n\t\t\t\tb = scriptContent.match(/window\\.b\\s*=\\s*'([^']+)'/)?.[1] || \"\";\n\t\t\t\tc = scriptContent.match(/window\\.c\\s*=\\s*'([^']+)'/)?.[1] || \"\";\n\t\t\t}\n\t\t});\n\t\tconst haha = await solveSearchChallenge(a, b, c);\n\t\tawait fetchClient.setCookies([\n\t\t\t{\n\t\t\t\tdomain: \"www.linovelib.com\",\n\t\t\t\tpath: \"/\",\n\t\t\t\tname: \"haha\",\n\t\t\t\tvalue: haha,\n\t\t\t\tmaxAge: 900,\n\t\t\t},\n\t\t]);\n\t\tawait new Promise((r) => setTimeout(r, 3000));\n\t\tresponse = await fetchClient.text(\"https://www.linovelib.com/S6/\", {\n\t\t\tmethod: \"POST\",\n\t\t\tbody: new URLSearchParams({\n\t\t\t\tsearchkey: keyword,\n\t\t\t}),\n\t\t\theaders: {\n\t\t\t\treferer: \"https://www.linovelib.com/S6/\",\n\t\t\t},\n\t\t});\n\t\t$ = cheerio.load(response.data);\n\t}\n\tif ($(\"#challenge-running\").length !== 0) {\n\t\tthrow new Error(\"Failed to solve search challenge\");\n\t}\n\tif ($(\"div.book-html-box\").length > 0) {\n\t\treturn [\n\t\t\t{\n\t\t\t\ttitle: $(\"h1.book-name\").text().trim(),\n\t\t\t\tplatform: \"linovelib\",\n\t\t\t\tid:\n\t\t\t\t\textractNovelIdFromUrl($(\"meta[name=url]\").attr(\"content\") ?? \"\") ||\n\t\t\t\t\t\"\",\n\t\t\t\tcoverUrl: $(\"div.book-img img\").attr(\"src\") || \"\",\n\t\t\t},\n\t\t];\n\t}\n\tif (!response.data.includes(\"有关\")) {\n\t\tthrow new Error(\"Unexpected search result format, keyword not found\");\n\t}\n\tconst pages =\n\t\t$(\"em#pagestats\")\n\t\t\t.text()\n\t\t\t.match(/1\\/(\\d+)/)?.[1] || \"1\";\n\tconst results: NovelSearchResult[] = [];\n\t$(\"div.search-html-box div.search-result-list\").each((_, el) => {\n\t\tconst $el = $(el);\n\t\tconst title = $el.find(\"h2\").text().trim();\n\t\tconst url = $el.find(\"h2 a\").attr(\"href\") || \"\";\n\t\tconst id = extractNovelIdFromUrl(url) ?? \"\";\n\t\tconst coverUrl = $el.find(\"img\").attr(\"src\") || \"\";\n\t\tresults.push({\n\t\t\ttitle,\n\t\t\tplatform: \"linovelib\",\n\t\t\tid,\n\t\t\tcoverUrl,\n\t\t});\n\t});\n\tif (Number(pages) > 1) {\n\t\tlet currentPageHtml = response.data;\n\t\twhile (true) {\n\t\t\tconst $2 = cheerio.load(currentPageHtml);\n\t\t\tif ($2(\"a.next\").length > 0) {\n\t\t\t\tcurrentPageHtml = (\n\t\t\t\t\tawait fetchClient.text(\n\t\t\t\t\t\t`https://www.linovelib.com${$2(\"a.next\").attr(\"href\")}`,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\theaders: {\n\t\t\t\t\t\t\t\thost: \"www.linovelib.com\",\n\t\t\t\t\t\t\t\treferer: \"https://www.linovelib.com/S6/\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t)\n\t\t\t\t).data;\n\t\t\t}\n\t\t\tconst $3 = cheerio.load(currentPageHtml);\n\t\t\t$3(\"div.search-html-box div.search-result-list\").each((_, el) => {\n\t\t\t\tconst $el = $3(el);\n\t\t\t\tconst title = $el.find(\"h2\").text().trim();\n\t\t\t\tconst url = $el.find(\"h2 a\").attr(\"href\") || \"\";\n\t\t\t\tconst id = extractNovelIdFromUrl(url) ?? \"\";\n\t\t\t\tconst coverUrl = $el.find(\"img\").attr(\"src\") || \"\";\n\t\t\t\tresults.push({\n\t\t\t\t\ttitle,\n\t\t\t\t\tplatform: \"linovelib\",\n\t\t\t\t\tid,\n\t\t\t\t\tcoverUrl,\n\t\t\t\t});\n\t\t\t});\n\t\t\tif ($3(\"a.next\").length === 0) break;\n\t\t}\n\t}\n\treturn results;\n}\n","import {\n\ttype BrowserFetchClient,\n\tCloudflareBlockError,\n\tdefaultRetryPolicy,\n\ttype RetryOptions,\n} from \"@acanthis-dec/browser-fetch\";\nimport type { Novel, NovelSearchResult } from \"@acanthis-dec/core\";\nimport PQueue from \"p-queue\";\nimport type { Logger } from \"winston\";\nimport { getNovelInfo, getUpdateInfo, type NovelUpdateInfo } from \"./novel\";\nimport { searchNovels } from \"./search\";\n\n/**\n * Simple backoff strategy for request rate limiting\n * - Normal desktop delay: 500-1000ms random\n * - Normal mobile delay: 2000-5000ms random\n * - Failure delay: 8000ms (8 seconds)\n */\nclass SimpleBackoff {\n\treadonly NORMAL_DELAY_MIN = 500;\n\treadonly NORMAL_DELAY_MAX = 1000;\n\treadonly NORMAL_MOBILE_DELAY_MIN = 2000;\n\treadonly NORMAL_MOBILE_DELAY_MAX = 5000;\n\treadonly FAILURE_DELAY = 15000;\n\n\t/**\n\t * Get delay for normal (successful) operation\n\t * @returns Random delay in range [500, 1000]ms. If isMobile is true, returns random delay in range [2000, 5000]ms\n\t */\n\tgetDelayForSuccess(isMobile: boolean = false): number {\n\t\tif (isMobile) {\n\t\t\treturn (\n\t\t\t\tthis.NORMAL_MOBILE_DELAY_MIN +\n\t\t\t\tMath.random() *\n\t\t\t\t\t(this.NORMAL_MOBILE_DELAY_MAX - this.NORMAL_MOBILE_DELAY_MIN)\n\t\t\t);\n\t\t}\n\t\treturn (\n\t\t\tthis.NORMAL_DELAY_MIN +\n\t\t\tMath.random() * (this.NORMAL_DELAY_MAX - this.NORMAL_DELAY_MIN)\n\t\t);\n\t}\n}\n\nexport class SearchQueue {\n\tprivate queue: PQueue;\n\tprivate client: BrowserFetchClient;\n\tprivate logger?: Logger | undefined;\n\tprivate readonly COOLDOWN_MS = 5000;\n\tprivate lastSearchTime = 0;\n\n\tconstructor(client: BrowserFetchClient, logger?: Logger) {\n\t\tthis.queue = new PQueue({ concurrency: 1 });\n\t\tthis.client = client;\n\t\tthis.logger = logger;\n\t\tthis.queue.on(\"add\", () => {\n\t\t\tthis.logger?.debug(\n\t\t\t\t`[SearchQueue] 任务已添加,当前排队数: ${this.queue.size} (等待中任务数: ${this.queue.pending})`,\n\t\t\t);\n\t\t});\n\t\tthis.queue.on(\"next\", () => {\n\t\t\tthis.logger?.debug(\n\t\t\t\t`[SearchQueue] 任务完成或超时,开始下一个任务。剩余:${this.queue.size} `,\n\t\t\t);\n\t\t});\n\t}\n\n\tasync searchNovels(keyword: string): Promise<NovelSearchResult[]> {\n\t\treturn await this.queue.add(async () => {\n\t\t\tif (Date.now() - this.lastSearchTime < this.COOLDOWN_MS) {\n\t\t\t\tconst waitTime = this.COOLDOWN_MS - (Date.now() - this.lastSearchTime);\n\t\t\t\tthis.logger?.debug(\n\t\t\t\t\t`[SearchQueue] 搜索请求过快,等待 ${waitTime}ms 后重试`,\n\t\t\t\t);\n\t\t\t\tawait new Promise((resolve) => setTimeout(resolve, waitTime));\n\t\t\t}\n\t\t\tthis.logger?.debug(`[SearchQueue] 开始搜索关键词 \"${keyword}\"`);\n\t\t\tconst results = await searchNovels(keyword, this.client);\n\t\t\tthis.logger?.debug(\n\t\t\t\t`[SearchQueue] 搜索完成,关键词 \"${keyword}\" 共找到 ${results.length} 条结果`,\n\t\t\t);\n\t\t\tthis.lastSearchTime = Date.now();\n\t\t\treturn results;\n\t\t});\n\t}\n}\n\nexport class NovelChapterQueue {\n\tprivate queue: PQueue;\n\tprivate client: BrowserFetchClient;\n\tprivate backoff: SimpleBackoff;\n\tprivate logger?: Logger | undefined;\n\n\tconstructor(client: BrowserFetchClient, logger?: Logger) {\n\t\tthis.queue = new PQueue({ concurrency: 1 });\n\t\tthis.client = client;\n\t\tthis.backoff = new SimpleBackoff();\n\t\tthis.logger = logger;\n\t\tthis.queue.on(\"add\", () => {\n\t\t\tthis.logger?.debug(\n\t\t\t\t`[NovelChapterQueue] 任务已添加,当前排队数: ${this.queue.size} (等待中任务数: ${this.queue.pending})`,\n\t\t\t);\n\t\t});\n\t\tthis.queue.on(\"next\", () => {\n\t\t\tthis.logger?.debug(\n\t\t\t\t`[NovelChapterQueue] 任务完成或超时,开始下一个任务。剩余:${this.queue.size} `,\n\t\t\t);\n\t\t});\n\t}\n\n\tprivate async _sleep(ms: number) {\n\t\treturn new Promise((resolve) => setTimeout(resolve, ms));\n\t}\n\n\tasync fetchChapterPart(url: string): Promise<string> {\n\t\treturn await this.queue.add(async () => {\n\t\t\tconst match = url.match(/\\/novel\\/(\\d+)\\/(\\d+)(?:_(\\d+))?\\.html/);\n\t\t\tif (!match) {\n\t\t\t\tthrow new Error(`Invalid chapter URL: ${url}`);\n\t\t\t}\n\t\t\tconst novelId = match[1];\n\t\t\tconst chapterId = match[2];\n\t\t\tconst partId = match[3] || \"1\";\n\t\t\tthis.logger?.debug(\n\t\t\t\t`[NovelChapterQueue] 开始获取小说${novelId}章节${chapterId}的第${partId}部分内容`,\n\t\t\t);\n\n\t\t\tconst retry: RetryOptions = {\n\t\t\t\tretries: 10,\n\t\t\t\tfactor: 2,\n\t\t\t\tminRetryDelayMs: 0,\n\t\t\t\tmaxRetryDelayMs: 0,\n\t\t\t\trandomize: false,\n\t\t\t\tonFailedAttempt: async (ctx) => {\n\t\t\t\t\tif (ctx.error instanceof CloudflareBlockError) {\n\t\t\t\t\t\tthis.logger?.warn(\n\t\t\t\t\t\t\t`[NovelChapterQueue] 请求被 Cloudflare 阻挡,错误信息: ${ctx.error.message}。正在等待 ${this.backoff.FAILURE_DELAY / 1000}s 后重试...`,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tawait this._sleep(this.backoff.FAILURE_DELAY);\n\t\t\t\t\t}\n\t\t\t\t\tif (ctx.attemptNumber >= (retry.retries ?? 3)) {\n\t\t\t\t\t\tthis.logger?.error(\n\t\t\t\t\t\t\t`[NovelChapterQueue] 请求重试次数已达上限 (${ctx.attemptNumber} 次),错误信息: ${ctx.error.message}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tshouldRetry: async (ctx) => {\n\t\t\t\t\treturn (\n\t\t\t\t\t\tdefaultRetryPolicy(ctx) || ctx.error instanceof CloudflareBlockError\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t};\n\n\t\t\tlet content = (await this.client.text(url, { retry })).data ?? \"\";\n\t\t\tif (content.match(/沒有可閱讀的章節|没有可阅读的章节/i)) {\n\t\t\t\tcontent = (\n\t\t\t\t\tawait this.client.text(url, {\n\t\t\t\t\t\tprofile: \"chrome149-android\",\n\t\t\t\t\t\tretry: {\n\t\t\t\t\t\t\t...retry,\n\t\t\t\t\t\t\tminRetryDelayMs: this.backoff.NORMAL_MOBILE_DELAY_MIN,\n\t\t\t\t\t\t\tmaxRetryDelayMs: this.backoff.NORMAL_MOBILE_DELAY_MAX,\n\t\t\t\t\t\t},\n\t\t\t\t\t})\n\t\t\t\t).data;\n\t\t\t\tconst delay = this.backoff.getDelayForSuccess(true);\n\t\t\t\tthis.logger?.debug(\n\t\t\t\t\t`[NovelChapterQueue] 小说${novelId}-章节${chapterId}_${partId} 获取成功。下一次请求将在 ${delay.toFixed(0)}ms 后进行`,\n\t\t\t\t);\n\t\t\t\tawait this._sleep(delay);\n\t\t\t\treturn content;\n\t\t\t}\n\t\t\tconst delay = this.backoff.getDelayForSuccess();\n\t\t\tthis.logger?.debug(\n\t\t\t\t`[NovelChapterQueue] 小说${novelId}-章节${chapterId}_${partId} 获取成功。下一次请求将在 ${delay.toFixed(0)}ms 后进行`,\n\t\t\t);\n\t\t\tawait this._sleep(delay);\n\t\t\treturn content;\n\t\t});\n\t}\n}\n\nexport class NovelInfoQueue {\n\tprivate queue: PQueue;\n\tprivate client: BrowserFetchClient;\n\tprivate backoff: SimpleBackoff;\n\tprivate chapterQueue: NovelChapterQueue;\n\tprivate logger?: Logger | undefined;\n\n\tconstructor(\n\t\tclient: BrowserFetchClient,\n\t\tchapterQueue: NovelChapterQueue,\n\t\tlogger?: Logger,\n\t) {\n\t\tthis.queue = new PQueue({ concurrency: 1 });\n\t\tthis.client = client;\n\t\tthis.backoff = new SimpleBackoff();\n\t\tthis.chapterQueue = chapterQueue;\n\t\tthis.logger = logger;\n\t\tthis.queue.on(\"add\", () => {\n\t\t\tthis.logger?.debug(\n\t\t\t\t`[NovelInfoQueue] 任务已添加,当前排队数: ${this.queue.size} (等待中任务数: ${this.queue.pending})`,\n\t\t\t);\n\t\t});\n\t\tthis.queue.on(\"next\", () => {\n\t\t\tthis.logger?.debug(\n\t\t\t\t`[NovelInfoQueue] 任务完成或超时,开始下一个任务。剩余:${this.queue.size} `,\n\t\t\t);\n\t\t});\n\t}\n\n\tprivate async _sleep(ms: number) {\n\t\treturn new Promise((resolve) => setTimeout(resolve, ms));\n\t}\n\n\tasync fetchNovelInfo(id: string): Promise<Novel> {\n\t\treturn await this.queue.add(async () => {\n\t\t\tthis.logger?.debug(`[NovelInfoQueue] 开始获取小说${id}的信息`);\n\t\t\tconst retry: RetryOptions = {\n\t\t\t\tretries: 10,\n\t\t\t\tfactor: 2,\n\t\t\t\tminRetryDelayMs: 0,\n\t\t\t\tmaxRetryDelayMs: 0,\n\t\t\t\trandomize: false,\n\t\t\t\tonFailedAttempt: async (ctx) => {\n\t\t\t\t\tif (ctx.error instanceof CloudflareBlockError) {\n\t\t\t\t\t\tthis.logger?.warn(\n\t\t\t\t\t\t\t`[NovelInfoQueue] 请求被 Cloudflare 阻挡,错误信息: ${ctx.error.message}。正在等待 ${this.backoff.FAILURE_DELAY / 1000}s 后重试...`,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tawait this._sleep(this.backoff.FAILURE_DELAY);\n\t\t\t\t\t}\n\t\t\t\t\tif (ctx.attemptNumber >= (retry.retries ?? 3)) {\n\t\t\t\t\t\tthis.logger?.error(\n\t\t\t\t\t\t\t`[NovelInfoQueue] 请求重试次数已达上限 (${ctx.attemptNumber} 次),错误信息: ${ctx.error.message}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tshouldRetry: async (ctx) => {\n\t\t\t\t\treturn (\n\t\t\t\t\t\tdefaultRetryPolicy(ctx) || ctx.error instanceof CloudflareBlockError\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t};\n\n\t\t\tconst novel = await getNovelInfo(\n\t\t\t\tid,\n\t\t\t\tthis.client,\n\t\t\t\tretry,\n\t\t\t\tthis.chapterQueue,\n\t\t\t);\n\t\t\tif (!novel) {\n\t\t\t\tthrow new Error(`无法获取小说信息: ${id}`);\n\t\t\t}\n\t\t\tconst delay = this.backoff.getDelayForSuccess();\n\t\t\tthis.logger?.debug(\n\t\t\t\t`[NovelInfoQueue] 小说${id} 信息获取成功。下一次请求将在 ${delay.toFixed(0)}ms 后进行`,\n\t\t\t);\n\t\t\tawait this._sleep(delay);\n\t\t\treturn novel;\n\t\t});\n\t}\n\n\tasync fetchNovelUpdateInfo(id: string): Promise<NovelUpdateInfo | null> {\n\t\treturn await this.queue.add(async () => {\n\t\t\tthis.logger?.debug(\n\t\t\t\t`[NovelInfoQueue] 开始获取小说${id}的更新信息(封面和章节数)`,\n\t\t\t);\n\t\t\tconst retry: RetryOptions = {\n\t\t\t\tretries: 10,\n\t\t\t\tfactor: 2,\n\t\t\t\tminRetryDelayMs: 0,\n\t\t\t\tmaxRetryDelayMs: 0,\n\t\t\t\trandomize: false,\n\t\t\t\tonFailedAttempt: async (ctx) => {\n\t\t\t\t\tif (ctx.error instanceof CloudflareBlockError) {\n\t\t\t\t\t\tthis.logger?.warn(\n\t\t\t\t\t\t\t`[NovelInfoQueue] 请求被 Cloudflare 阻挡,错误信息: ${ctx.error.message}。正在等待 ${this.backoff.FAILURE_DELAY / 1000}s 后重试...`,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tawait this._sleep(this.backoff.FAILURE_DELAY);\n\t\t\t\t\t}\n\t\t\t\t\tif (ctx.attemptNumber >= (retry.retries ?? 3)) {\n\t\t\t\t\t\tthis.logger?.error(\n\t\t\t\t\t\t\t`[NovelInfoQueue] 请求重试次数已达上限 (${ctx.attemptNumber} 次),错误信息: ${ctx.error.message}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tshouldRetry: async (ctx) => {\n\t\t\t\t\treturn (\n\t\t\t\t\t\tdefaultRetryPolicy(ctx) || ctx.error instanceof CloudflareBlockError\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t};\n\n\t\t\tconst updateInfo = await getUpdateInfo(id, this.client, retry);\n\t\t\tif (!updateInfo) {\n\t\t\t\tthis.logger?.warn(\n\t\t\t\t\t`[NovelInfoQueue] 无法获取小说${id}的更新信息,可能是因为小说不存在或已被删除`,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tthis.logger?.debug(\n\t\t\t\t\t`[NovelInfoQueue] 小说${id} 更新信息获取成功。下一次请求将在 ${this.backoff.getDelayForSuccess().toFixed(0)}ms 后进行`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tawait this._sleep(this.backoff.getDelayForSuccess());\n\t\t\treturn updateInfo;\n\t\t});\n\t}\n}\n","import type { BrowserFetchClient } from \"@acanthis-dec/browser-fetch\";\n\nexport interface LoginConfig {\n\tusername: string;\n\tpassword: string;\n}\n\nexport async function refreshSessionId(\n\tfetchClient: BrowserFetchClient,\n\tloginConfig: LoginConfig,\n): Promise<boolean> {\n\tawait fetchClient.request({\n\t\turl: \"https://www.linovelib.com/login.php\",\n\t\tmethod: \"GET\",\n\t\theaders: {\n\t\t\treferer: \"https://www.linovelib.com/\",\n\t\t},\n\t});\n\tconst response = await fetchClient.request({\n\t\turl: \"https://www.linovelib.com/login.php?do=submit&jumpurl=https%3A%2F%2Fwww.linovelib.com%2F\",\n\t\tmethod: \"POST\",\n\t\tbody: new URLSearchParams({\n\t\t\tusername: loginConfig.username,\n\t\t\tpassword: loginConfig.password,\n\t\t\tusecookie: \"3153600000\",\n\t\t\tsubmit: \"登录\",\n\t\t\taction: \"login\",\n\t\t}),\n\t\tfollowRedirects: false,\n\t});\n\treturn (\n\t\tresponse.cookies.findIndex((cookie) => cookie.name === \"PHPSESSID\") !== -1\n\t);\n}\n\nexport async function hasValidSession(\n\tfetchClient: BrowserFetchClient,\n): Promise<boolean> {\n\tconst response = await fetchClient.text(\"https://www.linovelib.com\");\n\tif (response.data.includes(\"用户中心\")) return true;\n\telse return false;\n}\n\nexport async function ensureValidSession(\n\tfetchClient: BrowserFetchClient,\n\tloginConfig: LoginConfig,\n): Promise<boolean> {\n\tif (!(await hasValidSession(fetchClient))) {\n\t\tconst isValid =\n\t\t\t(await refreshSessionId(fetchClient, loginConfig)) &&\n\t\t\t(await hasValidSession(fetchClient));\n\t\tif (!isValid) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n","import {\n\ttype BinaryResponse,\n\tBrowserFetchClient,\n\ttype BrowserFetchClientOptions,\n\ttype BrowserProfileName,\n\ttype FlareSolverrOptions,\n} from \"@acanthis-dec/browser-fetch\";\nimport type {\n\tDescrambleCoefficients,\n\tNovel,\n\tNovelSearchResult,\n} from \"@acanthis-dec/core\";\nimport type { StorageService } from \"@acanthis-dec/storage\";\nimport { deepmerge } from \"deepmerge-ts\";\nimport type { Logger } from \"winston\";\nimport z from \"zod\";\nimport { getChapter } from \"./chapter\";\nimport { descrambleCoefficientsSchema } from \"./coefficients\";\nimport { getCover } from \"./cover\";\nimport type { NovelUpdateInfo } from \"./novel\";\nimport { NovelChapterQueue, NovelInfoQueue, SearchQueue } from \"./queue\";\nimport { ensureValidSession } from \"./session\";\n\nexport type SessionOptions =\n\t| {\n\t\t\tenabled: false;\n\t }\n\t| {\n\t\t\tenabled: true;\n\t\t\tusername: string;\n\t\t\tpassword: string;\n\t };\n\nexport type ImpersonateOptions =\n\t| {\n\t\t\tenabled: true;\n\t\t\tprofile: BrowserProfileName;\n\t }\n\t| {\n\t\t\tenabled: false;\n\t };\n\nexport type CookieStoreOptions =\n\t| {\n\t\t\ttype: \"memory\" | \"database\";\n\t }\n\t| {\n\t\t\ttype: \"file\";\n\t\t\tpath: string;\n\t };\n\nexport type LinovelibClientOptions = {\n\tsession: SessionOptions;\n\tflareSolverr: FlareSolverrOptions;\n\timpersonate: ImpersonateOptions;\n\tcookies: CookieStoreOptions;\n\tproxy?: string | undefined;\n};\n\nexport class LinovelibClient {\n\tprivate storage?: StorageService | undefined;\n\tprivate fetchClient: BrowserFetchClient;\n\tprivate novelChapterQueue: NovelChapterQueue;\n\tprivate novelInfoQueue: NovelInfoQueue;\n\tprivate searchQueue: SearchQueue;\n\tprivate options?: LinovelibClientOptions;\n\tprivate logger?: Logger | undefined;\n\tprivate isSessionValid?: boolean = undefined;\n\n\tconstructor(\n\t\toptions?: LinovelibClientOptions,\n\t\tstorage?: StorageService,\n\t\tlogger?: Logger,\n\t) {\n\t\tconst defaultOptions: LinovelibClientOptions = {\n\t\t\tsession: {\n\t\t\t\tenabled: false,\n\t\t\t},\n\t\t\tflareSolverr: {\n\t\t\t\tenabled: true,\n\t\t\t\thost: \"http://localhost:8191\",\n\t\t\t\ttimeoutMs: 60000,\n\t\t\t\tsessionId: \"acanthis-linovelib-client\",\n\t\t\t},\n\t\t\timpersonate: {\n\t\t\t\tenabled: true,\n\t\t\t\tprofile: \"chrome149-linux\",\n\t\t\t},\n\t\t\tcookies: {\n\t\t\t\ttype: \"memory\",\n\t\t\t},\n\t\t};\n\t\tthis.options = deepmerge(\n\t\t\tdefaultOptions,\n\t\t\toptions ?? {},\n\t\t) as LinovelibClientOptions;\n\t\tthis.storage = storage;\n\t\tthis.logger = logger;\n\t\tconst browserFetchOptions: BrowserFetchClientOptions = {};\n\t\tif (this.options?.flareSolverr.enabled) {\n\t\t\tbrowserFetchOptions.flareSolverr = {\n\t\t\t\tenabled: true,\n\t\t\t\thost: this.options.flareSolverr.host,\n\t\t\t\ttimeoutMs: this.options.flareSolverr.timeoutMs ?? 60000,\n\t\t\t\tsessionId:\n\t\t\t\t\tthis.options.flareSolverr.sessionId ?? \"acanthis-linovelib-client\",\n\t\t\t};\n\t\t} else {\n\t\t\tbrowserFetchOptions.flareSolverr = {\n\t\t\t\tenabled: false,\n\t\t\t};\n\t\t}\n\t\tif (this.options?.proxy) {\n\t\t\tbrowserFetchOptions.proxy = this.options.proxy;\n\t\t}\n\t\tif (this.options?.impersonate.enabled) {\n\t\t\tbrowserFetchOptions.profile = this.options.impersonate.profile;\n\t\t}\n\t\tswitch (this.options?.cookies.type) {\n\t\t\tcase \"memory\":\n\t\t\t\tbrowserFetchOptions.cookieStore = {\n\t\t\t\t\ttype: \"memory\",\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\tcase \"file\":\n\t\t\t\tbrowserFetchOptions.cookieStore = {\n\t\t\t\t\ttype: \"file\",\n\t\t\t\t\tpath: this.options.cookies.path,\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\tcase \"database\":\n\t\t\t\tif (!this.storage) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\"StorageService is required for database cookie store\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tbrowserFetchOptions.cookieStore = {\n\t\t\t\t\ttype: \"custom\",\n\t\t\t\t\tstore: this.storage.getCookieStore(),\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tbrowserFetchOptions.cookieStore = {\n\t\t\t\t\ttype: \"memory\",\n\t\t\t\t};\n\t\t}\n\t\tthis.fetchClient = new BrowserFetchClient(browserFetchOptions);\n\t\tthis.novelChapterQueue = new NovelChapterQueue(\n\t\t\tthis.fetchClient,\n\t\t\tthis.logger,\n\t\t);\n\t\tthis.novelInfoQueue = new NovelInfoQueue(\n\t\t\tthis.fetchClient,\n\t\t\tthis.novelChapterQueue,\n\t\t\tthis.logger,\n\t\t);\n\t\tthis.searchQueue = new SearchQueue(this.fetchClient, this.logger);\n\t}\n\n\tasync getNovelInfo(id: string): Promise<Novel | undefined> {\n\t\tif (this.options?.session.enabled && !this.isSessionValid) {\n\t\t\tthis.isSessionValid = await ensureValidSession(this.fetchClient, {\n\t\t\t\tusername: this.options.session.username,\n\t\t\t\tpassword: this.options.session.password,\n\t\t\t});\n\t\t}\n\t\treturn await this.novelInfoQueue.fetchNovelInfo(id);\n\t}\n\n\tasync getNovelUpdateInfo(id: string): Promise<NovelUpdateInfo | null> {\n\t\tif (this.options?.session.enabled && !this.isSessionValid) {\n\t\t\tthis.isSessionValid = await ensureValidSession(this.fetchClient, {\n\t\t\t\tusername: this.options.session.username,\n\t\t\t\tpassword: this.options.session.password,\n\t\t\t});\n\t\t}\n\t\treturn await this.novelInfoQueue.fetchNovelUpdateInfo(id);\n\t}\n\n\tasync searchNovels(keyword: string): Promise<NovelSearchResult[]> {\n\t\tif (this.options?.session.enabled && !this.isSessionValid) {\n\t\t\tthis.isSessionValid = await ensureValidSession(this.fetchClient, {\n\t\t\t\tusername: this.options.session.username,\n\t\t\t\tpassword: this.options.session.password,\n\t\t\t});\n\t\t}\n\t\treturn await this.searchQueue.searchNovels(keyword);\n\t}\n\n\tasync getNovelCover(novelId: string) {\n\t\treturn await getCover(novelId, this.fetchClient);\n\t}\n\n\tasync getCover(url: string): Promise<BinaryResponse> {\n\t\treturn await this.fetchClient.binary(url, {\n\t\t\theaders: {\n\t\t\t\tReferer: \"https://www.linovelib.com/\",\n\t\t\t},\n\t\t});\n\t}\n\n\tasync getChapter(\n\t\tnovelId: string,\n\t\tchapterId: string,\n\t): Promise<string | undefined> {\n\t\tif (this.options?.session.enabled && !this.isSessionValid) {\n\t\t\tthis.isSessionValid = await ensureValidSession(this.fetchClient, {\n\t\t\t\tusername: this.options.session.username,\n\t\t\t\tpassword: this.options.session.password,\n\t\t\t});\n\t\t}\n\t\tconst cachedJsVersion = this.storage\n\t\t\t? ((await this.storage.getCache(\"chapterlog_js_version\", z.string())) ??\n\t\t\t\tundefined)\n\t\t\t: undefined;\n\t\tconst cachedCoefficients = this.storage\n\t\t\t? ((await this.storage.getCache<DescrambleCoefficients>(\n\t\t\t\t\t\"coefficients\",\n\t\t\t\t\tdescrambleCoefficientsSchema,\n\t\t\t\t)) ?? undefined)\n\t\t\t: undefined;\n\t\tconst result = await getChapter(\n\t\t\tchapterId,\n\t\t\tnovelId,\n\t\t\tthis.novelChapterQueue,\n\t\t\tthis.fetchClient,\n\t\t\tcachedJsVersion,\n\t\t\tcachedCoefficients,\n\t\t);\n\t\tif (this.storage && result) {\n\t\t\tawait this.storage.setCache(\"chapterlog_js_version\", result.version);\n\t\t\tawait this.storage.setCache(\"coefficients\", result.coefficients);\n\t\t}\n\t\treturn result?.content;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;AAWA,MAAM,WACJ,eAA6D,WAC9D;AAED,MAAa,+BAA+B,EAAE,OAAO;CACpD,SAAS,EAAE,OAAO,CAAC,CAAC,IAAI;CACxB,WAAW,EAAE,OAAO,CAAC,CAAC,IAAI;CAC1B,YAAY,EAAE,OAAO,CAAC,CAAC,IAAI;CAC3B,YAAY,EAAE,OAAO,CAAC,CAAC,IAAI;CAC3B,gBAAgB,EAAE,OAAO,CAAC,CAAC,IAAI;AAChC,CAAC;AAED,SAAS,kBAAkB,UAA0B;CACpD,OAAO,SACL,MAAM,OAAO,CAAC,CACd,KAAK,SAAS,KAAK,KAAK,CAAC,CAAC,CAC1B,QAAQ,SAAS,SAAS,EAAE,CAAC,CAC7B,MAAM,EAAE,CAAC,CACT,KAAK,IAAI;AACZ;AAEA,eAAsB,oBACrB,QACkC;CAGlC,MAAM,MAAM,MAAM,MADM,YADD,kBAAkB,MACQ,CAAC,GACrB;EAAE,YAAY;EAAU,SAAS,CAAC,KAAK;CAAE,CAAC;CACvE,MAAM,eAAgD,CAAC;CACvD,SAAS,KAAK,EACb,iBAAiB,MAAM;EACtB,MAAM,EAAE,SAAS;EACjB,IACC,KAAK,aAAa,OAClB,EAAE,iBAAiB,KAAK,KAAK,KAC7B,EAAE,mBAAmB,KAAK,IAAI,KAC9B,KAAK,KAAK,aAAa,OACvB,EAAE,iBAAiB,KAAK,KA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SAAS,QAAQ,WAAW,CAAC,KAAK,gBAC1C,KAAK,iBAAiB,MAAM,mBAAmB,KAAK,aAAa;GAChE,UAAU,KAAK,QAAQ,QAAQ;GAC/B,UAAU,KAAK,QAAQ,QAAQ;EAChC,CAAC;EAEF,OAAO,MAAM,KAAK,YAAY,aAAa,OAAO;CACnD;CAEA,MAAM,cAAc,SAAiB;EACpC,OAAO,MAAM,SAAS,SAAS,KAAK,WAAW;CAChD;CAEA,MAAM,SAAS,KAAsC;EACpD,OAAO,MAAM,KAAK,YAAY,OAAO,KAAK,EACzC,SAAS,EACR,SAAS,6BACV,EACD,CAAC;CACF;CAEA,MAAM,WACL,SACA,WAC8B;EAC9B,IAAI,KAAK,SAAS,QAAQ,WAAW,CAAC,KAAK,gBAC1C,KAAK,iBAAiB,MAAM,mBAAmB,KAAK,aAAa;GAChE,UAAU,KAAK,QAAQ,QAAQ;GAC/B,UAAU,KAAK,QAAQ,QAAQ;EAChC,CAAC;EAEF,MAAM,kBAAkB,KAAK,UACxB,MAAM,KAAK,QAAQ,SAAS,yBAAyBA,IAAE,OAAO,CAAC,KAClE,KAAA,IACC,KAAA;EACH,MAAM,qBAAqB,KAAK,UAC3B,MAAM,KAAK,QAAQ,SACrB,gBACA,4BACD,KAAM,KAAA,IACL,KAAA;EACH,MAAM,SAAS,MAAM,WACpB,WACA,SACA,KAAK,mBACL,KAAK,aACL,iBACA,kBACD;EACA,IAAI,KAAK,WAAW,QAAQ;GAC3B,MAAM,KAAK,QAAQ,SAAS,yBAAyB,OAAO,OAAO;GACnE,MAAM,KAAK,QAAQ,SAAS,gBAAgB,OAAO,YAAY;EAChE;EACA,OAAO,QAAQ;CAChB;AACD"}
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@acanthis-dec/linovelib",
3
+ "version": "1.0.0",
4
+ "description": "An Acanthis adapter for Linovelib site.",
5
+ "author": "ConstasJ <constasj@qq.com>",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.mjs",
11
+ "types": "./dist/index.d.mts"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "package.json",
17
+ "README.md",
18
+ "README.zh-CN.md"
19
+ ],
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/ConstasJ/Acanthis.git"
23
+ },
24
+ "homepage": "https://github.com/ConstasJ/Acanthis#readme",
25
+ "bugs": {
26
+ "url": "https://github.com/ConstasJ/Acanthis/issues"
27
+ },
28
+ "dependencies": {
29
+ "@babel/parser": "^7.29.7",
30
+ "@babel/traverse": "^7.29.7",
31
+ "@babel/types": "^7.29.7",
32
+ "cheerio": "^1.2.0",
33
+ "deepmerge-ts": "^7.1.5",
34
+ "p-queue": "^9.3.0",
35
+ "zod": "^4.4.3",
36
+ "winston": "^3.19.0",
37
+ "@acanthis-dec/deobfuscator": "1.0.0",
38
+ "@acanthis-dec/browser-fetch": "1.0.0",
39
+ "@acanthis-dec/storage": "1.0.0",
40
+ "@acanthis-dec/core": "1.0.0"
41
+ },
42
+ "devDependencies": {
43
+ "@types/babel__traverse": "^7.28.0",
44
+ "@types/node": "25.9.2",
45
+ "domhandler": "^6.0.1",
46
+ "tsdown": "0.22.2",
47
+ "tsx": "4.22.4",
48
+ "typescript": "6.0.3",
49
+ "@acanthis-dec/config-tsdown": "1.0.0",
50
+ "@acanthis-dec/config-typescript": "1.0.0"
51
+ },
52
+ "scripts": {
53
+ "build": "tsdown",
54
+ "check-types": "tsc --noEmit"
55
+ }
56
+ }