diff --git a/docs/README.md b/docs/README.md index ab27e4d510..11e1bae258 100644 --- a/docs/README.md +++ b/docs/README.md @@ -575,6 +575,8 @@ RSSHub 提供下列 API 接口: + + ### Facebook diff --git a/lib/router.js b/lib/router.js index ea16999bb1..4c25a72e21 100644 --- a/lib/router.js +++ b/lib/router.js @@ -886,6 +886,7 @@ router.get('/coolbuy/newest', require('./routes/coolbuy/newest')); // NGA router.get('/nga/forum/:fid', require('./routes/nga/forum')); +router.get('/nga/post/:tid', require('./routes/nga/post')); // JavBus router.get('/javbus/home', require('./routes/javbus/home')); diff --git a/lib/routes/nga/post.js b/lib/routes/nga/post.js new file mode 100644 index 0000000000..8221a57797 --- /dev/null +++ b/lib/routes/nga/post.js @@ -0,0 +1,47 @@ +const axios = require('../../utils/axios'); +const cheerio = require('cheerio'); +const iconv = require('iconv-lite'); + +module.exports = async (ctx) => { + const { tid } = ctx.params; + const link = `https://nga.178.com/read.php?tid=${tid}&rand=${Math.random() * 1000}`; + const timestamp = Math.floor(Date.now() / 1000); + const response = await axios({ + method: 'get', + url: link, + responseType: 'arraybuffer', + headers: { + Cookie: `guestJs=${timestamp};`, + }, + }); + + const htmlString = iconv.decode(response.data, 'gbk'); + const $ = cheerio.load(htmlString); + const title = $('title').text() || ''; + const description = $('#postcontentandsubject0').html() || ''; + let pubDate = new Date($('#postdate0').text()).toUTCString(); + + if ($('#alertc0').length > 0) { + const matches = htmlString.match(/<\/span>