Skip to content

Commit

Permalink
fix(route): nga 匿名帖子获取失败 (DIYgod#10695)
Browse files Browse the repository at this point in the history
* fix

* add new domain

* list format

* fix
  • Loading branch information
syrinka authored Sep 4, 2022
1 parent cde7722 commit d0fcff9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 50 deletions.
7 changes: 5 additions & 2 deletions lib/v2/nga/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ module.exports = async (ctx) => {
.replace(/\[font=(.+?)\](.+?)\[\/font\]/g, '<span style="font-family:$1;">$2</span>')
.replace(/\[size=(.+?)\](.+?)\[\/size\]/g, '<span style="font-size:$1;">$2</span>')
.replace(/\[align=(.+?)\](.+?)\[\/align\]/g, '<span style="text-align:$1;">$2</span>');
// 列表
str = deepReplace(str, /\[\*\](.+?)(?=\[\*\]|\[\/list\])/g, '<li>$1</li>');
str = deepReplace(str, /\[list\](.+?)\[\/list\]/g, '<ul>$1</ul>');
// 图片
str = str.replace(/\[img\](.+?)\[\/img\]/g, (m, src) => `<img src='${src[0] === '.' ? 'https://img.nga.178.com/attachments' + src.substr(1) : src}'></img>`);
// 折叠
Expand All @@ -58,7 +61,7 @@ module.exports = async (ctx) => {
.replace(/\[@(.+?)\]/g, '<a href="https://nga.178.com/nuke.php?func=ucp&username=$1">@$1</a>')
.replace(/\[uid=(\d+)\](.+?)\[\/uid\]/g, '<a href="https://nga.178.com/nuke.php?func=ucp&uid=$1">@$2</a>')
.replace(/\[tid=(\d+)\](.+?)\[\/tid\]/g, '<a href="https://nga.178.com/read.php?tid=$1">$2</a>')
.replace(/\[pid=(\d+),(\d+),(\d+)\](.+?)\[\/pid\]/g, (m, tid, pid, page, str) => {
.replace(/\[pid=(\d+),(\d+),(\d+)\](.+?)\[\/pid\]/g, (m, pid, tid, page, str) => {
const url = `https://nga.178.com/read.php?tid=${tid}&page=${page}#pid${pid}Anchor`;
return `<a href="${url}">${str}</a>`;
});
Expand Down Expand Up @@ -91,7 +94,7 @@ module.exports = async (ctx) => {
.find('.posterinfo a')
.first()
.attr('href')
.match(/&uid=(\d+)/)[1];
.match(/&uid=(-?\d+)$/)[1];
const poster = authorName || posterMap[posterId].username;
const content = post.find('.postcontent').first();
const description = formatContent(content.html());
Expand Down
79 changes: 31 additions & 48 deletions lib/v2/nga/radar.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,39 @@
const rules = [
{
title: '分区帖子',
docs: 'https://docs.rsshub.app/bbs.html#nga-fen-qu-tie-zi',
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-tie-zi',
source: '/read.php',
target: (params, url) => new URL(url).searchParams.get('tid') && `/nga/post/${new URL(url).searchParams.get('tid')}`,
},
{
title: '帖子 - 只看作者',
docs: 'https://docs.rsshub.app/bbs.html#nga-tie-zi',
source: '/read.php',
target: (params, url, document) => {
const tid = new URL(url).searchParams.get('tid');
const authorId = document.documentElement.innerHTML.match(/commonui\.userInfo\.setAll\(\s{3}{"(\d+)"/)[1];
return `/nga/post/${tid}/${authorId}`;
},
},
];

module.exports = {
'nga.cn': {
_name: 'NGA',
bbs: [
{
title: '分区帖子',
docs: 'https://docs.rsshub.app/bbs.html#nga-fen-qu-tie-zi',
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-tie-zi',
source: '/read.php',
target: (params, url) => new URL(url).searchParams.get('tid') && `/nga/post/${new URL(url).searchParams.get('tid')}`,
},
{
title: '帖子 - 只看作者',
docs: 'https://docs.rsshub.app/bbs.html#nga-tie-zi',
source: '/read.php',
target: (params, url, document) => {
const tid = new URL(url).searchParams.get('tid');
const authorId = document.documentElement.innerHTML.match(/commonui\.userInfo\.setAll\(\s{3}{"(\d+)"/)[1];
return `/nga/post/${tid}/${authorId}`;
},
},
],
bbs: rules,
},
'178.com': {
_name: 'NGA',
nga: [
{
title: '分区帖子',
docs: 'https://docs.rsshub.app/bbs.html#nga-fen-qu-tie-zi',
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-tie-zi',
source: '/read.php',
target: (params, url) => new URL(url).searchParams.get('tid') && `/nga/post/${new URL(url).searchParams.get('tid')}`,
},
{
title: '帖子 - 只看作者',
docs: 'https://docs.rsshub.app/bbs.html#nga-tie-zi',
source: '/read.php',
target: (params, url, document) => {
const tid = new URL(url).searchParams.get('tid');
const authorId = document.documentElement.innerHTML.match(/commonui\.userInfo\.setAll\(\s{3}{"(\d+)"/)[1];
return `/nga/post/${tid}/${authorId}`;
},
},
],
nga: rules,
},
'ngabbs.com': {
_name: 'NGA',
'.': rules,
},
};

0 comments on commit d0fcff9

Please sign in to comment.