feat: add 模型网 (#4246)

This commit is contained in:
cc789461
2020-03-17 12:00:29 +08:00
committed by GitHub
parent 25b169d8b9
commit 14e634420d
3 changed files with 71 additions and 0 deletions

View File

@@ -347,6 +347,12 @@ type 为 all 时category 参数不支持 cost 和 free
</Route> </Route>
## 模型网
### 新闻
<Route author="cc798461" example="/moxingnet" path="/moxingnet"/>
## 且听风吟福利 ## 且听风吟福利
### 分类 ### 分类

View File

@@ -2362,6 +2362,9 @@ router.get('/moxingfans', require('./routes/moxingfans'));
// Chiphell // Chiphell
router.get('/chiphell/forum/:forumId?', require('./routes/chiphell/forum')); router.get('/chiphell/forum/:forumId?', require('./routes/chiphell/forum'));
// 模型网
router.get('/moxingnet', require('./routes/moxingnet'));
// Rockstar Games Social Club // Rockstar Games Social Club
router.get('/socialclub/events/:game?', require('./routes/socialclub/events')); router.get('/socialclub/events/:game?', require('./routes/socialclub/events'));

View File

@@ -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 };
};