mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-08 05:59:00 +08:00
@@ -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/post/15939161" path="/nga/post/:tid" :paramsDesc="['帖子 id, 可在帖子 URL 找到']"/>
|
||||
|
||||
### Facebook
|
||||
|
||||
<route name="粉絲專頁" author="maple3142" example="/facebook/page/SonetPCR" path="/facebook/page/:id" :paramsDesc="['專頁 id']"/>
|
||||
|
||||
@@ -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'));
|
||||
|
||||
47
lib/routes/nga/post.js
Normal file
47
lib/routes/nga/post.js
Normal 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,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user