增加:轻小说文库 (#1515)

This commit is contained in:
沚水
2019-02-13 11:16:44 +08:00
committed by DIYgod
parent 16b59c9f79
commit 371021c211
3 changed files with 42 additions and 0 deletions

View File

@@ -2409,6 +2409,10 @@ Example: `https://store.steampowered.com/search/?specials=1&term=atelier` 中的
<route name="Poems" author="HenryQW" example="/allpoetry/newest" path="/allpoetry/:order?" :paramsDesc="['排序方式, `best``newest`, 缺省 `best`']"/>
### 轻小说文库
<route name="章节" author="zsakvo" example="/wenku8/chapter/74" path="/wenku8/chapter/:id" :paramsDesc="['小说 id, 可在对应小说页 URL 中找到']"/>
## 中国驻外使领馆
### 大使馆

View File

@@ -1019,4 +1019,7 @@ router.get('/jpmorganchase', require('./routes/jpmorganchase/research'));
// 美拍
router.get('/meipai/user/:uid', require('./routes/meipai/user'));
// 轻小说文库
router.get('/wenku8/chapter/:id', require('./routes/wenku8/chapter'));
module.exports = router;

View File

@@ -0,0 +1,35 @@
const axios = require('../../utils/axios');
const cheerio = require('cheerio');
const iconv = require('iconv-lite');
module.exports = async (ctx) => {
const id = ctx.params.id;
const index = parseInt(id / 1000);
const response = await axios({
method: 'get',
url: `https://www.wenku8.net/novel/${index}/${id}/index.htm`,
responseType: 'arraybuffer',
});
const responseHtml = iconv.decode(response.data, 'gbk');
const $ = cheerio.load(responseHtml);
const name = $('#title').text();
const chapter_item = [];
$('.ccss>a').each(function() {
chapter_item.push({
title: $(this).text(),
link: `https://www.wenku8.net/novel/${index}/${id}/` + $(this).attr('href'),
});
});
ctx.state.data = {
title: `轻小说文库 ${name}`,
link: `https://www.wenku8.net/book/${id}.htm`,
item: chapter_item,
};
};