diff --git a/docs/other.md b/docs/other.md index 26ec701bf8..3f39ebce37 100644 --- a/docs/other.md +++ b/docs/other.md @@ -347,6 +347,12 @@ type 为 all 时,category 参数不支持 cost 和 free +## 模型网 + +### 新闻 + + + ## 且听风吟福利 ### 分类 diff --git a/lib/router.js b/lib/router.js index de39315362..f3cfff031e 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2362,6 +2362,9 @@ router.get('/moxingfans', require('./routes/moxingfans')); // Chiphell router.get('/chiphell/forum/:forumId?', require('./routes/chiphell/forum')); +// 模型网 +router.get('/moxingnet', require('./routes/moxingnet')); + // Rockstar Games Social Club router.get('/socialclub/events/:game?', require('./routes/socialclub/events')); diff --git a/lib/routes/moxingnet/index.js b/lib/routes/moxingnet/index.js new file mode 100644 index 0000000000..e94ebdd9e3 --- /dev/null +++ b/lib/routes/moxingnet/index.js @@ -0,0 +1,62 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const iconv = require('iconv-lite'); + +module.exports = async (ctx) => { + const baseUrl = 'http://moxing.net/'; + const response = await got({ + method: 'get', + url: baseUrl, + responseType: 'buffer', + }); + const data = iconv.decode(response.data, 'gb2312'); + const $ = cheerio.load(data); + const list = $('ul.text_list.text_list_f14 li').get(); + + const ProcessLink = async (link) => { + const response = await got({ + method: 'get', + url: link, + responseType: 'buffer', + }); + const data = iconv.decode(response.data, 'gb2312'); + const $ = cheerio.load(data); + + let desc = $('#endtext').html(); + const next_page_link = $('#pages') + .children() + .last() + .attr('href'); + if (next_page_link !== undefined && baseUrl + next_page_link !== link) { + const next_page = await ProcessLink(baseUrl + next_page_link); + desc += next_page.desc; + } + return { + desc: desc, + }; + }; + + const out = await Promise.all( + list.map(async (item) => { + const $ = cheerio.load(item); + const $a = $('a'); + const link = baseUrl + $a.attr('href'); + const cache = await ctx.cache.get(link); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + + const feed = await ProcessLink(link); + const description = feed.desc; + + const single = { + title: $a.text(), + description, + link: link, + }; + ctx.cache.set(link, JSON.stringify(single)); + return Promise.resolve(single); + }) + ); + ctx.state.data = { title: '模型网', link: baseUrl, item: out }; +};