增加: nga 帖子更新 (#1324)

Closes #1311
This commit is contained in:
凉凉
2018-12-31 01:01:00 +08:00
committed by DIYgod
parent 20b3b59b5a
commit 644a86962d
3 changed files with 50 additions and 0 deletions

View File

@@ -575,6 +575,8 @@ RSSHub 提供下列 API 接口:
<route name="分区帖子" author="xyqfer" example="/nga/forum/485" path="/nga/forum/:fid" :paramsDesc="['分区 id, 可在分区主页 URL 找到']"/> <route name="分区帖子" author="xyqfer" example="/nga/forum/485" path="/nga/forum/:fid" :paramsDesc="['分区 id, 可在分区主页 URL 找到']"/>
<route name="帖子" author="xyqfer" example="/nga/post/15939161" path="/nga/post/:tid" :paramsDesc="['帖子 id, 可在帖子 URL 找到']"/>
### Facebook ### Facebook
<route name="粉絲專頁" author="maple3142" example="/facebook/page/SonetPCR" path="/facebook/page/:id" :paramsDesc="['專頁 id']"/> <route name="粉絲專頁" author="maple3142" example="/facebook/page/SonetPCR" path="/facebook/page/:id" :paramsDesc="['專頁 id']"/>

View File

@@ -886,6 +886,7 @@ router.get('/coolbuy/newest', require('./routes/coolbuy/newest'));
// NGA // NGA
router.get('/nga/forum/:fid', require('./routes/nga/forum')); router.get('/nga/forum/:fid', require('./routes/nga/forum'));
router.get('/nga/post/:tid', require('./routes/nga/post'));
// JavBus // JavBus
router.get('/javbus/home', require('./routes/javbus/home')); router.get('/javbus/home', require('./routes/javbus/home'));

47
lib/routes/nga/post.js Normal file
View File

@@ -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 id='alertc0'><\/span><script>commonui\.loadAlertInfo\('\[E(\d+)[\s\S]+?\t|\n\]','alertc0'\)<\/script>/);
if (matches && matches[1]) {
pubDate = new Date(parseInt(matches[1]) * 1000).toUTCString();
}
}
const items = [
{
title,
link,
description,
guid: pubDate,
pubDate,
},
];
ctx.state.data = {
title: `nga-${title}`,
link,
item: items,
};
};