diff --git a/docs/README.md b/docs/README.md index 3d14dfc36..5910cec46 100644 --- a/docs/README.md +++ b/docs/README.md @@ -557,6 +557,10 @@ RSSHub 提供下列 API 接口: +### NGA + + + ## 编程 ### 掘金 diff --git a/router.js b/router.js index d6e9cade8..a9b15322a 100644 --- a/router.js +++ b/router.js @@ -833,4 +833,7 @@ router.get('/testerhome/newest', require('./routes/testerhome/newest')); router.get('/weseepro/newest', require('./routes/weseepro/newest')); router.get('/weseepro/circle', require('./routes/weseepro/circle')); +// NGA +router.get('/nga/forum/:fid', require('./routes/nga/forum')); + module.exports = router; diff --git a/routes/nga/forum.js b/routes/nga/forum.js new file mode 100644 index 000000000..1fb02e04a --- /dev/null +++ b/routes/nga/forum.js @@ -0,0 +1,60 @@ +const axios = require('../../utils/axios'); +const qs = require('querystring'); + +module.exports = async (ctx) => { + const { fid } = ctx.params; + const axiosInstance = axios.create({ + baseURL: 'https://ngabbs.com/app_api.php', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + 'X-User-Agent': 'NGA_skull/6.0.5(iPhone10,3;iOS 12.0.1)', + }, + }); + const homePage = await axiosInstance.request({ + method: 'post', + url: '?__lib=subject&__act=list', + data: qs.stringify({ + fid, + }), + }); + + const list = homePage.data.result.data.filter(({ tid }) => tid); + + const resultItem = await Promise.all( + list.map(async ({ subject, postdate, tid }) => { + const link = `https://nga.178.com/read.php?tid=${tid}`; + const item = { + title: subject, + description: '', + link, + pubDate: new Date(postdate * 1000).toUTCString(), + }; + + const description = await ctx.cache.tryGet( + `nga-forum: ${link}`, + async () => { + const response = await axiosInstance.request({ + method: 'post', + url: '?__lib=post&__act=list', + data: qs.stringify({ + tid, + }), + }); + + return response.data.result[0].content; + }, + 24 * 60 * 60 + ); + + item.description = description; + return Promise.resolve(item); + }) + ); + + ctx.state.data = { + title: `NGA-${fid}`, + link: `https://nga.178.com/thread.php?fid=${fid}`, + description: 'NGA是国内专业的游戏玩家社区,魔兽世界,英雄联盟,炉石传说,风暴英雄,暗黑破坏神3(D3)游戏攻略讨论,以及其他热门游戏玩家社区', + item: resultItem, + }; +};