|
|
@@ -42,24 +42,19 @@ export async function GetReaderBooksChapter(ctx) {
|
|
42
|
42
|
};
|
|
43
|
43
|
|
|
44
|
44
|
let result = [];
|
|
45
|
|
-
|
|
46
|
45
|
const { readdir, readFile, writeFile } = fs.promises;
|
|
47
|
|
- let sourceDir = path.join(__dirname, '../../web_crawler/'+ param.Title + '/' + param.Title + '_contents');
|
|
48
|
|
- const files = (await readdir(sourceDir))
|
|
49
|
|
- .filter(file => file.endsWith('.html'))
|
|
50
|
|
- .sort((a, b) => parseInt(a.split('_')[0]) - parseInt(b.split('_')[0]));
|
|
51
|
|
-
|
|
52
|
|
- for (const file of files) {
|
|
53
|
|
- // 提取章节标题
|
|
54
|
|
- const titleMatch = file.match(/_([^\.]+)\.html$/);
|
|
55
|
|
- const title = titleMatch ? titleMatch[1] : file;
|
|
56
|
|
- result.push(title);
|
|
|
46
|
+ let filePath = path.join(__dirname, '../../web_crawler/'+ param.Title + '/' + param.Title + '_chapters.json');
|
|
|
47
|
+ let content = await fs.promises.readFile(filePath, 'utf-8');
|
|
|
48
|
+ content=JSON.parse(content);
|
|
|
49
|
+ for(const item of content) {
|
|
|
50
|
+ result.push(item.title);
|
|
57
|
51
|
}
|
|
58
|
52
|
|
|
59
|
|
- if (param.Title === "Strange-Life-of-a-Cat") {
|
|
60
|
|
- for(let i=0;i<5;i++)
|
|
61
|
|
- result = result.slice(1); // 去掉第一个章节
|
|
62
|
|
- }
|
|
|
53
|
+ // 处理Strange-Life-of-a-Cat的章节,去掉前5个章节
|
|
|
54
|
+ // if (param.Title === "Strange-Life-of-a-Cat") {
|
|
|
55
|
+ // for(let i=0;i<5;i++)
|
|
|
56
|
+ // result = result.slice(1); // 去掉第一个章节
|
|
|
57
|
+ // }
|
|
63
|
58
|
|
|
64
|
59
|
ctx.body = { "errcode": 10000, result: result };
|
|
65
|
60
|
}
|
|
|
@@ -74,7 +69,7 @@ export async function GetReaderBooksChapterContent(ctx) {
|
|
74
|
69
|
|
|
75
|
70
|
const {readFile} = fs.promises;
|
|
76
|
71
|
// 读取文本文件
|
|
77
|
|
- let filePath = path.join(__dirname, '../../web_crawler/' + param.Title + '.html');
|
|
|
72
|
+ let filePath = path.join(__dirname, '../../web_crawler/'+ param.Title + '/' + param.Title + '.html');
|
|
78
|
73
|
|
|
79
|
74
|
const content = await fs.promises.readFile(filePath, 'utf-8');
|
|
80
|
75
|
console.log(`已读取文件: ${filePath}`);
|