feat(route): NGA帖子只看作者 (#10239)

* feat(route): NGA帖子只看作者

* fix code style

* fix

* remove old router

* correct regex in getLastPageId

* fix

* change title

* refactor: parseDate utils

* fix: old radar rules
This commit is contained in:
syrinka 2022-07-18 21:29:35 +08:00 committed by GitHub
parent 1b1f3626b1
commit 4be123c139
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 78 additions and 52 deletions

View File

@ -215,13 +215,6 @@
},
'wineyun.com': { _name: '酒云网', www: [{ title: '最新商品', docs: 'https://docs.rsshub.app/other.html#jiu-yun-wang', source: ['/:category'], target: '/wineyun/:category' }] },
'epicgames.com': { _name: 'Epic Games', www: [{ title: '每周免费游戏', docs: 'https://docs.rsshub.app/game.html#epicgames-freegame', source: '/store/zh-CN/free-games', target: '/epicgames/freegames' }] },
'nga.cn': {
_name: 'NGA',
bbs: [
{ title: '分区帖子', docs: 'https://docs.rsshub.app/bbs.html#nga', source: '/thread.php', target: (params, url) => new URL(url).searchParams.get('fid') && `/nga/forum/${new URL(url).searchParams.get('fid')}` },
{ title: '帖子', docs: 'https://docs.rsshub.app/bbs.html#nga', source: '/read.php', target: (params, url) => new URL(url).searchParams.get('tid') && `/nga/post/${new URL(url).searchParams.get('tid')}` },
],
},
'playstation.com': {
_name: 'PlayStation',
store: [

View File

@ -284,7 +284,7 @@ pageClass: routes
### 帖子
<Route author="xyqfer" example="/nga/post/18449558" path="/nga/post/:tid" :paramsDesc="['帖子 id, 可在帖子 URL 找到']" radar="1" rssbud="1"/>
<Route author="xyqfer syrinka" example="/nga/post/18449558" path="/nga/post/:tid/:authorId?" :paramsDesc="['帖子 id, 可在帖子 URL 找到', '作者 id']" radar="1" rssbud="1"/>
## PLAYNO.1 玩樂達人

View File

@ -369,23 +369,6 @@ module.exports = {
},
],
},
'nga.cn': {
_name: 'NGA',
bbs: [
{
title: '分区帖子',
docs: 'https://docs.rsshub.app/bbs.html#nga',
source: '/thread.php',
target: (params, url) => new URL(url).searchParams.get('fid') && `/nga/forum/${new URL(url).searchParams.get('fid')}`,
},
{
title: '帖子',
docs: 'https://docs.rsshub.app/bbs.html#nga',
source: '/read.php',
target: (params, url) => new URL(url).searchParams.get('tid') && `/nga/post/${new URL(url).searchParams.get('tid')}`,
},
],
},
'playstation.com': {
_name: 'PlayStation',
store: [

View File

@ -1060,9 +1060,9 @@ router.get('/coolbuy/newest', lazyloadRouteHandler('./routes/coolbuy/newest'));
router.get('/miniflux/subscription/:parameters?', lazyloadRouteHandler('./routes/miniflux/get_feeds'));
router.get('/miniflux/:feeds/:parameters?', lazyloadRouteHandler('./routes/miniflux/get_entries'));
// NGA
router.get('/nga/forum/:fid/:recommend?', lazyloadRouteHandler('./routes/nga/forum'));
router.get('/nga/post/:tid', lazyloadRouteHandler('./routes/nga/post'));
// NGA migrated to v2
// router.get('/nga/forum/:fid/:recommend?', lazyloadRouteHandler('./routes/nga/forum'));
// router.get('/nga/post/:tid', lazyloadRouteHandler('./routes/nga/post'));
// Nautilus
router.get('/nautilus/topic/:tid', lazyloadRouteHandler('./routes/nautilus/topics'));

View File

@ -1,5 +1,8 @@
const got = require('@/utils/got');
const config = require('@/config').value;
const { parseDate } = require('@/utils/parse-date');
const X_UA = 'NGA_skull/6.0.5(iPhone10,3;iOS 12.0.1)';
module.exports = async (ctx) => {
const { fid, recommend } = ctx.params;
@ -15,11 +18,9 @@ module.exports = async (ctx) => {
return `<img src="${src}" />`;
})
.replace(/\[url\](.+?)\[\/url\]/g, `<a href="$1">$1</a>`);
const homePage = await got({
method: 'post',
url: 'https://ngabbs.com/app_api.php?__lib=subject&__act=list',
const homePage = await got.post('https://ngabbs.com/app_api.php?__lib=subject&__act=list', {
headers: {
'X-User-Agent': 'NGA_skull/6.0.5(iPhone10,3;iOS 12.0.1)',
'X-User-Agent': X_UA,
Cookie: cookieString,
},
form: {
@ -39,15 +40,13 @@ module.exports = async (ctx) => {
title: subject,
description: '',
link,
pubDate: new Date(postdate * 1000).toUTCString(),
pubDate: parseDate(postdate, 'X'),
};
const description = await ctx.cache.tryGet(`nga-forum: ${link}`, async () => {
const response = await got({
method: 'post',
url: 'https://ngabbs.com/app_api.php?__lib=post&__act=list',
const response = await got.post('https://ngabbs.com/app_api.php?__lib=post&__act=list', {
headers: {
'X-User-Agent': 'NGA_skull/6.0.5(iPhone10,3;iOS 12.0.1)',
'X-User-Agent': X_UA,
Cookie: cookieString,
},
form: {

4
lib/v2/nga/maintainer.js Normal file
View File

@ -0,0 +1,4 @@
module.exports = {
'/forum/:fid/:recommend?': ['xyqfer'],
'/post/:tid/:authorId?': ['xyqfer', 'syrinka'],
};

View File

@ -1,20 +1,20 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const iconv = require('iconv-lite');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
const config = require('@/config').value;
module.exports = async (ctx) => {
const getPageUrl = (tid, page = 1, hash = '') => `https://nga.178.com/read.php?tid=${tid}&page=${page}&rand=${Math.random() * 1000}#${hash}`;
const getPage = async (tid, pageId = 1) => {
const link = getPageUrl(tid, pageId);
const getPageUrl = (tid, authorId, page = 1, hash = '') => `https://nga.178.com/read.php?tid=${tid}&page=${page}&authorid=${authorId}&rand=${Math.random() * 1000}#${hash}`;
const getPage = async (tid, authorId, pageId = 1) => {
const link = getPageUrl(tid, authorId, pageId);
const timestamp = Math.floor(Date.now() / 1000);
let cookieString = `guestJs=${timestamp};`;
if (config.nga.uid && config.nga.cid) {
cookieString = `ngaPassportUid=${config.nga.uid}; ngaPassportCid=${config.nga.cid};`;
}
const response = await got({
method: 'get',
url: link,
const response = await got(link, {
responseType: 'buffer',
headers: {
Cookie: cookieString,
@ -25,10 +25,10 @@ module.exports = async (ctx) => {
return cheerio.load(htmlString);
};
const getLastPageId = async (tid) => {
const $ = await getPage(tid);
const getLastPageId = async (tid, authorId) => {
const $ = await getPage(tid, authorId);
const nav = $('#pagebtop');
const match = nav.html().match(/\{0:'\/read.php\?tid=(\d+)',1:(\d+).*?\}/);
const match = nav.html().match(/\{0:'\/read\.php\?tid=(\d+).*?',1:(\d+),.*?\}/);
return match ? match[2] : 1;
};
@ -37,9 +37,10 @@ module.exports = async (ctx) => {
const pipeImg = (str) => str.replace(/\[img\](.+?)\[\/img\]/g, (m, src) => `<img src='${src[0] === '.' ? 'https://img.nga.178.com/attachments' + src.substr(1) : src}'></img>`);
const tid = ctx.params.tid;
const pageId = await getLastPageId(tid);
const authorId = ctx.params.authorId;
const pageId = await getLastPageId(tid, authorId);
const $ = await getPage(tid, pageId);
const $ = await getPage(tid, authorId, pageId);
const title = $('title').text() || '';
const items = $('#m_posts_c')
@ -51,8 +52,8 @@ module.exports = async (ctx) => {
const title = eraseTag(content.text());
const description = eraseTag(pipeImg(eraseQuote(content.html() || '')));
const postId = content.attr('id');
const link = getPageUrl(tid, pageId, postId);
const pubDate = new Date(post.find('.postInfo > span').first().text()).toUTCString();
const link = getPageUrl(tid, authorId, pageId, postId);
const pubDate = timezone(parseDate(post.find('.postInfo > span').first().text(), 'YYYY-MM-DD HH:mm'), +8);
return {
title,
@ -64,8 +65,8 @@ module.exports = async (ctx) => {
});
ctx.state.data = {
title: `nga-${title}`,
link: getPageUrl(tid, pageId),
title: authorId ? `nga-${title}-${authorId}` : `nga-${title}`,
link: getPageUrl(tid, authorId, pageId),
item: items.get(),
};
};

42
lib/v2/nga/radar.js Normal file
View File

@ -0,0 +1,42 @@
module.exports = {
'nga.cn': {
_name: 'NGA',
bbs: [
{
title: '分区帖子',
docs: 'https://docs.rsshub.app/bbs.html#nga',
source: '/thread.php',
target: (params, url) => new URL(url).searchParams.get('fid') && `/nga/forum/${new URL(url).searchParams.get('fid')}`,
},
{
title: '帖子',
docs: 'https://docs.rsshub.app/bbs.html#nga',
source: '/read.php',
target: (params, url) => new URL(url).searchParams.get('tid') && `/nga/post/${new URL(url).searchParams.get('tid')}`,
},
],
},
'178.com': {
_name: 'NGA',
nga: [
{
title: '分区帖子',
docs: 'https://docs.rsshub.app/bbs.html#nga-fen-qu-tie-zi',
source: ['/thread.php'],
target: (params, url) => {
const fid = new URL(url).searchParams.get('fid');
return `/nga/forum/${fid}`;
},
},
{
title: '帖子',
docs: 'https://docs.rsshub.app/bbs.html#nga-tie-zi',
source: ['/read.php'],
target: (params, url) => {
const tid = new URL(url).searchParams.get('tid');
return `/nga/post/${tid}`;
},
},
],
},
};

4
lib/v2/nga/router.js Normal file
View File

@ -0,0 +1,4 @@
module.exports = function (router) {
router.get('/forum/:fid/:recommend?', require('./forum'));
router.get('/post/:tid/:authorId?', require('./post'));
};