Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(route): New route: MiYouShe - User Posts; Optimize the routing of MiYouShe | 新增路由:米游社 - 用户帖子;优化米游社路由 #14268

Merged
merged 38 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
83a7846
fix(route): 修复 米游社 公告栏 template 错误
CaoMeiYouRen Sep 5, 2023
7b65948
Merge branch 'DIYgod:master' into master
CaoMeiYouRen Dec 1, 2023
2ea08ff
feat(route): 新增 bing 搜索
CaoMeiYouRen Dec 1, 2023
de072b3
docs: Update other.mdx
CaoMeiYouRen Dec 1, 2023
98aee17
docs: fix docs
TonyRL Dec 1, 2023
13b91e1
feat(route): 新增 百度搜索
CaoMeiYouRen Dec 1, 2023
32d028a
Merge branch 'master' of github.com:CaoMeiYouRen/RSSHub
CaoMeiYouRen Dec 1, 2023
dd283a2
fix(route): 修复 pubDate 解析错误
CaoMeiYouRen Dec 1, 2023
288b606
Merge branch 'master' of github.com:DIYgod/RSSHub
CaoMeiYouRen Dec 1, 2023
b0b6b4d
fix(route): 优化 百度搜索的缓存,减轻反爬问题
CaoMeiYouRen Dec 1, 2023
e9afda3
feat(route): 新增 360 搜索
CaoMeiYouRen Dec 4, 2023
3171faa
Merge branch 'master' of github.com:DIYgod/RSSHub
CaoMeiYouRen Dec 5, 2023
7abe59c
feat(route): 迁移 搜狗特色LOGO 到 v2 规范;添加 搜狗搜索
CaoMeiYouRen Dec 5, 2023
4751557
Merge branch 'master' of github.com:DIYgod/RSSHub
CaoMeiYouRen Dec 10, 2023
7f68ac2
fix(route): 百度搜索增加图片
CaoMeiYouRen Dec 10, 2023
12d0477
feat(route): 新增 Google Search
CaoMeiYouRen Dec 10, 2023
f81821d
chore: merge branch 'master' of github.com:DIYgod/RSSHub
CaoMeiYouRen Dec 16, 2023
05ce45c
Merge branch 'master' of github.com:DIYgod/RSSHub
CaoMeiYouRen Dec 19, 2023
1185a64
fix(route): 修复 百度搜索相关问题
CaoMeiYouRen Dec 19, 2023
58c722d
fix(route): 修复 Google 相关问题
CaoMeiYouRen Dec 19, 2023
1b00eb6
fix(route): 修复 360 搜索
CaoMeiYouRen Dec 19, 2023
08dca4d
fix(route): 修复 搜狗搜索
CaoMeiYouRen Dec 19, 2023
90b1aa7
fix(route): 修复 await 问题
CaoMeiYouRen Dec 19, 2023
da49d03
Merge branch 'master' of github.com:DIYgod/RSSHub
CaoMeiYouRen Dec 19, 2023
931b769
fix: 移除 google sites
CaoMeiYouRen Dec 19, 2023
a997c01
Merge branch 'master' of github.com:DIYgod/RSSHub
CaoMeiYouRen Dec 23, 2023
22923a5
fix(route): 修复 缓存和过滤逻辑问题
CaoMeiYouRen Dec 23, 2023
90ebcd6
Merge branch 'master' of github.com:DIYgod/RSSHub
CaoMeiYouRen Dec 25, 2023
cd5d832
fix(route): 修复 360 搜索缺少 cookie 的问题
CaoMeiYouRen Dec 25, 2023
31118c2
fix(route): 修复 360 搜索 cookie 的问题
CaoMeiYouRen Dec 25, 2023
219f9d8
feat(route): 移除 so.com 路由
CaoMeiYouRen Dec 25, 2023
c548af5
fix: merge conflict
TonyRL Dec 25, 2023
fd464c1
Merge branch 'DIYgod:master' into master
CaoMeiYouRen Jan 17, 2024
cddabf8
feat(route): 新增路由:米游社 - 用户帖子;优化米游社路由
CaoMeiYouRen Jan 17, 2024
49aa866
fix(route): 修复 米游社用户帖子路由
CaoMeiYouRen Jan 17, 2024
3123b9a
feat(route): 新增 米游社 用户关注路由
CaoMeiYouRen Jan 17, 2024
895cf2e
fix(route): 修复 米游社帖子可能缺失封面的 bug;增加 点赞和评论数
CaoMeiYouRen Jan 18, 2024
4b5773e
fix(route): 修复 米游社路由的规范和 bug
CaoMeiYouRen Jan 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions lib/v2/mihoyo/bbs/cache.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const got = require('@/utils/got');

module.exports = {
getUserFullInfo: (ctx, uid) => {
const key = 'mihoyo:user-full-info-uid-' + uid;
return ctx.cache.tryGet(key, async () => {
const query = new URLSearchParams({
uid,
gids: 2,
}).toString();
const url = `https://bbs-api.miyoushe.com/user/wapi/getUserFullInfo?${query}`;
const response = await got({
method: 'get',
url,
headers: {
Referer: `https://www.miyoushe.com/ys/accountCenter/postList?id=${uid}`,
},
});
Comment on lines +7 to +18
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const userInfo = response?.data?.data?.user_info;
if (!userInfo) {
throw new Error('未获取到数据!');
}
const { nickname, introduce, gender, certification, avatar_url } = userInfo;
return {
nickname,
introduce,
gender,
certification,
avatar_url,
};
});
},
};
49 changes: 49 additions & 0 deletions lib/v2/mihoyo/bbs/follow-list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const got = require('@/utils/got');
const { art } = require('@/utils/render');
const path = require('path');
const cache = require('./cache');

const renderDescription = (description, images) => art(path.join(__dirname, '../templates/description.art'), { description, images });

module.exports = async (ctx) => {
const { uid } = ctx.params;
const page_size = ctx.query.limit || '20';
const query = new URLSearchParams({
gids: 2,
uid,
page_size,
}).toString();
const link = `https://www.miyoushe.com/ys/accountCenter/followList?id=${uid}`;
const url = `https://bbs-api.miyoushe.com/user/wapi/following?${query}`;
const response = await got({
method: 'get',
url,
headers: {
Origin: 'https://www.miyoushe.com',
Referer: link,
},
});
const list = response?.data?.data?.result;
if (!list) {
throw new Error('未获取到数据!');
}
const { nickname: username } = await cache.getUserFullInfo(ctx, uid);
const title = `米游社 - ${username} 的关注`;
const items = list.map((e) => {
const title = e.user.nickname;
const link = `https://www.miyoushe.com/ys/accountCenter/postList?id=${e.user.uid}`;
const description = renderDescription(`${e.user.certification.label || ''}\n${e.user.introduce || ''}`.trim(), [e.user.avatar_url]);
return {
title,
link,
description,
};
});

const data = {
title,
link,
item: items,
};
ctx.state.data = data;
};
8 changes: 6 additions & 2 deletions lib/v2/mihoyo/bbs/img-ranking.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
const items = list.map((e) => {
const author = e.user.nickname;
const title = e.post.subject;
const link = `https://bbs.mihoyo.com/ys/article/${e.post.post_id}`;
const link = `https://www.miyoushe.com/ys/article/${e.post.post_id}`;
let describe = e.post.content || '';
try {
describe = JSON.parse(e.post.content).describe;
Expand All @@ -87,14 +87,18 @@
throw error;
}
}
const description = renderDescription(describe || '', [e.post.cover, ...e.post.images]);
const description = renderDescription(describe || '', Array.from(new Set([e.post.cover, ...e.post.images])).filter(Boolean));
Fixed Show fixed Hide fixed
const pubDate = parseDate(e.post.created_at * 1000);
const upvotes = e.stat.like_num;
const comments = e.stat.reply_num;
return {
author,
title,
link,
description,
pubDate,
upvotes,
comments,
};
});
const data = {
Expand Down
4 changes: 2 additions & 2 deletions lib/v2/mihoyo/bbs/official.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports = async (ctx) => {
page_size,
last_id,
}).toString();
const url = `https://bbs-api.mihoyo.com/post/wapi/getNewsList?${query}`;
const url = `https://bbs-api.miyoushe.com/post/wapi/getNewsList?${query}`;
const response = await got({
method: 'get',
url,
Expand All @@ -42,7 +42,7 @@ module.exports = async (ctx) => {
const items = list.map((e) => {
const author = e.user.nickname;
const title = e.post.subject;
const link = `https://bbs.mihoyo.com/ys/article/${e.post.post_id}`;
const link = `https://www.miyoushe.com/ys/article/${e.post.post_id}`;
const description = renderDescription(e.post.content, e.post.images);
const pubDate = parseDate(e.post.created_at * 1000);
return {
Expand Down
60 changes: 60 additions & 0 deletions lib/v2/mihoyo/bbs/user-post.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const got = require('@/utils/got');
const { art } = require('@/utils/render');
const path = require('path');
const { parseDate } = require('@/utils/parse-date');

const renderDescription = (description, images) => art(path.join(__dirname, '../templates/description.art'), { description, images });

module.exports = async (ctx) => {
const { uid } = ctx.params;
const size = ctx.query.limit || '20';
const query = new URLSearchParams({
uid,
size,
}).toString();
const link = `https://www.miyoushe.com/ys/accountCenter/postList?id=${uid}`;
const url = `https://bbs-api.miyoushe.com/post/wapi/userPost?${query}`;
const response = await got({
method: 'get',
url,
});
const list = response?.data?.data?.list;
if (!list) {
throw new Error('未获取到数据!');
}
const username = list[0]?.user.nickname;
const title = `米游社 - ${username} 的发帖`;
const items = list.map((e) => {
const author = e.user.nickname;
const title = e.post.subject;
const link = `https://www.miyoushe.com/ys/article/${e.post.post_id}`;
let describe = e.post.content || '';
try {
describe = JSON.parse(e.post.content).describe;
} catch (error) {
if (!(error instanceof SyntaxError)) {
throw error;
}
}
const description = renderDescription(describe || '', Array.from(new Set([e.post.cover, ...e.post.images])).filter(Boolean));
Fixed Show fixed Hide fixed
const pubDate = parseDate(e.post.created_at * 1000);
const upvotes = e.stat.like_num;
const comments = e.stat.reply_num;
return {
author,
title,
link,
description,
pubDate,
upvotes,
comments,
};
});

const data = {
title,
link,
item: items,
};
ctx.state.data = data;
};
2 changes: 2 additions & 0 deletions lib/v2/mihoyo/maintainer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module.exports = {
'/bbs/follow-list/:uid': ['CaoMeiYouRen'],
'/bbs/img-ranking/:game/:routeParams?': ['CaoMeiYouRen'],
'/bbs/official/:gids/:type?/:page_size?/:last_id?': ['CaoMeiYouRen'],
'/bbs/user-post/:uid': ['CaoMeiYouRen'],
'/sr/:location?/:category?': ['shinanory'],
'/ys/:location?/:category?': ['nczitzk'],
};
87 changes: 55 additions & 32 deletions lib/v2/mihoyo/radar.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,53 @@
const bbs = [
{
title: '米游社 - 用户关注',
docs: 'https://docs.rsshub.app/routes/game#mi-ha-you',
source: '/:game/accountCenter/postList',
target: (params, url) => {
const uid = new URL(url).searchParams.get('id');
return `/mihoyo/bbs/follow-list/${uid}`;
},
},
{
title: '米游社 - 同人榜',
docs: 'https://docs.rsshub.app/routes/game#mi-ha-you',
source: '/:game/imgRanking/:forum_id/:ranking_id/:cate_id',
target: `/mihoyo/bbs/img-ranking/:game`,
},
{
title: '米游社 - 官方公告',
docs: 'https://docs.rsshub.app/routes/game#mi-ha-you',
source: ['/:game/home/28', '/:game/home/6', '/:game/home/31', '/:game/home/33', '/:game/home/53', '/:game/home/58'],
target: (params, url) => {
const GITS_MAP = {
bh3: 1, // '崩坏三',
ys: 2, // '原神',
bh2: 3, // '崩坏二',
wd: 4, // '未定事件簿',
sr: 6, // '崩坏:星穹铁道',
zzz: 8, // '绝区零'
};
const { game } = params;
const gids = GITS_MAP[game];
if (!gids) {
return '';
}
const type = new URL(url).searchParams.get('type') || '1';
const page_size = '20';
const last_id = '';
return `/mihoyo/bbs/official/${gids}/${type}/${page_size}/${last_id}`;
},
},
{
title: '米游社 - 用户帖子',
docs: 'https://docs.rsshub.app/routes/game#mi-ha-you',
source: '/:game/accountCenter/postList',
target: (params, url) => {
const uid = new URL(url).searchParams.get('id');
return `/mihoyo/bbs/user-post/${uid}`;
},
},
];
module.exports = {
'hoyoverse.com': {
_name: '米哈游',
Expand All @@ -20,38 +70,7 @@ module.exports = {
},
'mihoyo.com': {
_name: '米哈游',
bbs: [
{
title: '米游社 - 同人榜',
docs: 'https://docs.rsshub.app/routes/game#mi-ha-you',
source: '/:game/imgRanking/:forum_id/:ranking_id/:cate_id',
target: `/mihoyo/bbs/img-ranking/:game`,
},
{
title: '米游社 - 官方公告',
docs: 'https://docs.rsshub.app/routes/game#mi-ha-you',
source: ['/:game/home/28', '/:game/home/6', '/:game/home/31', '/:game/home/33', '/:game/home/53', '/:game/home/58'],
target: (params, url) => {
const GITS_MAP = {
bh3: 1, // '崩坏三',
ys: 2, // '原神',
bh2: 3, // '崩坏二',
wd: 4, // '未定事件簿',
sr: 6, // '崩坏:星穹铁道',
zzz: 8, // '绝区零'
};
const { game } = params;
const gids = GITS_MAP[game];
if (!gids) {
return '';
}
const type = new URL(url).searchParams.get('type') || '1';
const page_size = '20';
const last_id = '';
return `/mihoyo/bbs/official/${gids}/${type}/${page_size}/${last_id}`;
},
},
],
bbs,
sr: [
{
title: '崩坏:星穹铁道 - 新闻',
Expand All @@ -69,4 +88,8 @@ module.exports = {
},
],
},
'miyoushe.com': {
_name: '米游社',
'.': bbs,
},
};
2 changes: 2 additions & 0 deletions lib/v2/mihoyo/router.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module.exports = function (router) {
router.get('/bbs/follow-list/:uid', require('./bbs/follow-list'));
router.get('/bbs/img-ranking/:game/:routeParams?', require('./bbs/img-ranking'));
router.get('/bbs/official/:gids/:type?/:page_size?/:last_id?', require('./bbs/official'));
router.get('/bbs/user-post/:uid', require('./bbs/user-post'));
router.get('/sr/:location?/:category?', require('./sr/news'));
router.get('/ys/:location?/:category?', require('./ys/news'));
};
12 changes: 10 additions & 2 deletions website/docs/routes/game.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ Example:`https://www.iyingdi.com/tz/people/55547` ,id 是 `55547`

### 米游社 - 同人榜 {#mi-ha-you-mi-you-she-tong-ren-bang}

<Route author="CaoMeiYouRen" example="/mihoyo/bbs/img-ranking/ys/forumType=tongren&cateType=illustration&rankingType=daily" path="/bbs/img-ranking/:game/:routeParams?" paramsDesc={['游戏缩写','额外参数;请参阅以下说明和表格']} radar="1">
<Route author="CaoMeiYouRen" example="/mihoyo/bbs/img-ranking/ys/forumType=tongren&cateType=illustration&rankingType=daily" path="/mihoyo/bbs/img-ranking/:game/:routeParams?" paramsDesc={['游戏缩写','额外参数;请参阅以下说明和表格']} radar="1">
| 键 | 含义 | 接受的值 | 默认值 |
| ----------- | ------------------------------------- | -------------------------------------------------------------------- | ------------ |
| forumType | 主榜类型(仅原神、大别野有 cos 主榜) | tongren/cos | tongren |
Expand Down Expand Up @@ -701,7 +701,7 @@ Example:`https://www.iyingdi.com/tz/people/55547` ,id 是 `55547`

### 米游社 - 官方公告 {#mi-ha-you-mi-you-she-guan-fang-gong-gao}

<Route author="CaoMeiYouRen" example="/mihoyo/bbs/official/2/3/20/" path="/bbs/official/:gids/:type?/:page_size?/:last_id?" paramsDesc={['游戏id','公告类型,默认为 2(即 活动)','分页大小,默认为 20 ','跳过的公告数,例如指定为 40 就是从第 40 条公告开始,可用于分页']} radar="1">
<Route author="CaoMeiYouRen" example="/mihoyo/bbs/official/2/3/20/" path="/mihoyo/bbs/official/:gids/:type?/:page_size?/:last_id?" paramsDesc={['游戏id','公告类型,默认为 2(即 活动)','分页大小,默认为 20 ','跳过的公告数,例如指定为 40 就是从第 40 条公告开始,可用于分页']} radar="1">
游戏 id

| 崩坏三 | 原神 | 崩坏二 | 未定事件簿 | 星穹铁道 | 绝区零 |
Expand All @@ -715,6 +715,14 @@ Example:`https://www.iyingdi.com/tz/people/55547` ,id 是 `55547`
| 1 | 2 | 3 |
</Route>

### 米游社 - 用户关注 {#mi-ha-you-mi-you-she-yong-hu-guan-zhu}

<Route author="CaoMeiYouRen" example="/mihoyo/bbs/follow-list/77005350" path="/bbs/follow-list/:uid" paramsDesc={['用户uid']} radar="1" />
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<Route author="CaoMeiYouRen" example="/mihoyo/bbs/follow-list/77005350" path="/bbs/follow-list/:uid" paramsDesc={['用户uid']} radar="1" />
<Route author="CaoMeiYouRen" example="/mihoyo/bbs/follow-list/77005350" path="/mihoyo/bbs/follow-list/:uid" paramsDesc={['用户uid']} radar="1" />


### 米游社 - 用户帖子 {#mi-ha-you-mi-you-she-yong-hu-tie-zi}

<Route author="CaoMeiYouRen" example="/mihoyo/bbs/user-post/77005350" path="/bbs/user-post/:uid" paramsDesc={['用户uid']} radar="1" />
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<Route author="CaoMeiYouRen" example="/mihoyo/bbs/user-post/77005350" path="/bbs/user-post/:uid" paramsDesc={['用户uid']} radar="1" />
<Route author="CaoMeiYouRen" example="/mihoyo/bbs/user-post/77005350" path="/mihoyo/bbs/user-post/:uid" paramsDesc={['用户uid']} radar="1" />


### 原神 {#mi-ha-you-yuan-shen}

#### 新闻 {#mi-ha-you-yuan-shen-xin-wen}
Expand Down
Loading