From b63690c64a22830a0b08d3e6426ae64b8fbc8f5b Mon Sep 17 00:00:00 2001
From: CaoMeiYouRen <40430746+CaoMeiYouRen@users.noreply.github.com>
Date: Thu, 8 Feb 2024 19:27:26 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20New=20Route=20Miyoushe=20-=20User=20Fol?=
=?UTF-8?q?low=20Dynamics=20|=20=E6=96=B0=E5=A2=9E=E8=B7=AF=E7=94=B1=20?=
=?UTF-8?q?=E7=B1=B3=E6=B8=B8=E7=A4=BE=20-=20=E7=94=A8=E6=88=B7=E5=85=B3?=
=?UTF-8?q?=E6=B3=A8=E5=8A=A8=E6=80=81=20(#14425)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* feat(route): 增加 米游社 - 用户关注动态 路由
* fix(route): 修复 路由、文档的风格问题
* docs: fix envs
---------
---
lib/config.js | 3 +
lib/v2/mihoyo/bbs/cache.js | 9 ++-
lib/v2/mihoyo/bbs/timeline.js | 70 +++++++++++++++++++
lib/v2/mihoyo/maintainer.js | 1 +
lib/v2/mihoyo/radar.js | 6 ++
lib/v2/mihoyo/router.js | 1 +
website/docs/install/config.md | 4 ++
website/docs/routes/game.mdx | 8 +++
website/docs/routes/government.mdx | 4 +-
website/docs/routes/other.mdx | 2 +-
.../current/install/config.md | 4 ++
11 files changed, 108 insertions(+), 4 deletions(-)
create mode 100644 lib/v2/mihoyo/bbs/timeline.js
diff --git a/lib/config.js b/lib/config.js
index fa051d5d9..00c978a8a 100644
--- a/lib/config.js
+++ b/lib/config.js
@@ -234,6 +234,9 @@ const calculateValue = () => {
cookies: medium_cookies,
articleCookie: envs.MEDIUM_ARTICLE_COOKIE || '',
},
+ mihoyo: {
+ cookie: envs.MIHOYO_COOKIE,
+ },
miniflux: {
instance: envs.MINIFLUX_INSTANCE || 'https://reader.miniflux.app',
token: envs.MINIFLUX_TOKEN || '',
diff --git a/lib/v2/mihoyo/bbs/cache.js b/lib/v2/mihoyo/bbs/cache.js
index 1d4000084..c0259a9ef 100644
--- a/lib/v2/mihoyo/bbs/cache.js
+++ b/lib/v2/mihoyo/bbs/cache.js
@@ -1,7 +1,12 @@
const got = require('@/utils/got');
+const config = require('@/config').value;
module.exports = {
getUserFullInfo: (ctx, uid) => {
+ if (!uid && !config.mihoyo.cookie) {
+ throw 'GetUserFullInfo is not available due to the absense of [Miyoushe Cookie]. Check relevant config tutorial';
+ }
+ uid ||= '';
const key = 'mihoyo:user-full-info-uid-' + uid;
return ctx.cache.tryGet(key, async () => {
const query = new URLSearchParams({
@@ -14,19 +19,21 @@ module.exports = {
url,
headers: {
Referer: `https://www.miyoushe.com/ys/accountCenter/postList?id=${uid}`,
+ Cookie: config.mihoyo.cookie,
},
});
const userInfo = response?.data?.data?.user_info;
if (!userInfo) {
throw new Error('未获取到数据!');
}
- const { nickname, introduce, gender, certification, avatar_url } = userInfo;
+ const { nickname, introduce, gender, certification, avatar_url, uid: userId } = userInfo;
return {
nickname,
introduce,
gender,
certification,
avatar_url,
+ uid: userId,
};
});
},
diff --git a/lib/v2/mihoyo/bbs/timeline.js b/lib/v2/mihoyo/bbs/timeline.js
new file mode 100644
index 000000000..6c2b508ce
--- /dev/null
+++ b/lib/v2/mihoyo/bbs/timeline.js
@@ -0,0 +1,70 @@
+const got = require('@/utils/got');
+const { art } = require('@/utils/render');
+const path = require('path');
+const { parseDate } = require('@/utils/parse-date');
+const cache = require('./cache');
+const config = require('@/config').value;
+
+const renderDescription = (description, images) => art(path.join(__dirname, '../templates/description.art'), { description, images });
+
+module.exports = async (ctx) => {
+ if (!config.mihoyo.cookie) {
+ throw 'Miyoushe Timeline is not available due to the absense of [Miyoushe Cookie]. Check relevant config tutorial';
+ }
+
+ const page_size = ctx.query.limit || '20';
+ const searchParams = {
+ gids: 2,
+ page_size,
+ };
+ const link = 'https://www.miyoushe.com/ys/timeline';
+ const url = 'https://bbs-api.miyoushe.com/post/wapi/timelines';
+ const response = await got({
+ method: 'get',
+ url,
+ searchParams,
+ headers: {
+ Referer: link,
+ Cookie: config.mihoyo.cookie,
+ },
+ });
+ const list = response?.data?.data?.list;
+ if (!list) {
+ throw new Error('未获取到数据!');
+ }
+ const { nickname: username } = await cache.getUserFullInfo(ctx, '');
+ 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 || '', [...new Set([e.post.cover, ...e.post.images])].filter(Boolean));
+ 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;
+};
diff --git a/lib/v2/mihoyo/maintainer.js b/lib/v2/mihoyo/maintainer.js
index 7eb64e1a8..4e9d199d5 100644
--- a/lib/v2/mihoyo/maintainer.js
+++ b/lib/v2/mihoyo/maintainer.js
@@ -2,6 +2,7 @@ module.exports = {
'/bbs/follow-list/:uid': ['CaoMeiYouRen'],
'/bbs/img-ranking/:game/:routeParams?': ['CaoMeiYouRen'],
'/bbs/official/:gids/:type?/:page_size?/:last_id?': ['CaoMeiYouRen'],
+ '/bbs/timeline': ['CaoMeiYouRen'],
'/bbs/user-post/:uid': ['CaoMeiYouRen'],
'/sr/:location?/:category?': ['shinanory'],
'/ys/:location?/:category?': ['nczitzk'],
diff --git a/lib/v2/mihoyo/radar.js b/lib/v2/mihoyo/radar.js
index e49873a68..1a3fd8cbb 100644
--- a/lib/v2/mihoyo/radar.js
+++ b/lib/v2/mihoyo/radar.js
@@ -47,6 +47,12 @@ const bbs = [
return `/mihoyo/bbs/user-post/${uid}`;
},
},
+ {
+ title: '米游社 - 用户关注动态',
+ docs: 'https://docs.rsshub.app/routes/game#mi-ha-you',
+ source: '/:game/timeline',
+ target: '/mihoyo/bbs/timeline',
+ },
];
module.exports = {
'hoyoverse.com': {
diff --git a/lib/v2/mihoyo/router.js b/lib/v2/mihoyo/router.js
index c45443e72..8ed6c498b 100644
--- a/lib/v2/mihoyo/router.js
+++ b/lib/v2/mihoyo/router.js
@@ -2,6 +2,7 @@ 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/timeline', require('./bbs/timeline'));
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'));
diff --git a/website/docs/install/config.md b/website/docs/install/config.md
index 2183c0025..e33d7cb87 100644
--- a/website/docs/install/config.md
+++ b/website/docs/install/config.md
@@ -570,6 +570,10 @@ Web 版认证 token 和 iOS 内购回执认证 token 只需选择其一填入即
- `HEFENG_KEY`:API key
+### 米游社
+
+- `MIHOYO_COOKIE`:登录米游社后的 cookie,用于获取用户关注动态时间线。
+
### 南方周末
用于付费全文
diff --git a/website/docs/routes/game.mdx b/website/docs/routes/game.mdx
index c0e37c9ad..fb4fa34fa 100644
--- a/website/docs/routes/game.mdx
+++ b/website/docs/routes/game.mdx
@@ -735,6 +735,14 @@ Example:`https://www.iyingdi.com/tz/people/55547` ,id 是 `55547`
+### 米游社 - 用户关注动态 {#mi-ha-you-mi-you-she-yong-hu-guan-zhu-dong-tai}
+
+
+ :::warning
+ 用户关注动态需要米游社登录后的 Cookie 值,所以只能自建,详情见部署页面的配置模块。
+ :::
+
+
### 原神 {#mi-ha-you-yuan-shen}
#### 新闻 {#mi-ha-you-yuan-shen-xin-wen}
diff --git a/website/docs/routes/government.mdx b/website/docs/routes/government.mdx
index 71ca7b15e..da920cce8 100644
--- a/website/docs/routes/government.mdx
+++ b/website/docs/routes/government.mdx
@@ -12,9 +12,9 @@
-## Constitutional Court of Baden-Württemberg (Germany) {#constitutional-court-of-baden-w%C3%BCrttemberg-germany}
+## Constitutional Court of Baden-Württemberg (Germany) {#constitutional-court-of-baden-wvrttemberg-germany}
-### Press releases {#constitutional-court-of-baden-w%C3%BCrttemberg-germany-press-releases}
+### Press releases {#constitutional-court-of-baden-wvrttemberg-germany-press-releases}
diff --git a/website/docs/routes/other.mdx b/website/docs/routes/other.mdx
index abca26609..c69791094 100644
--- a/website/docs/routes/other.mdx
+++ b/website/docs/routes/other.mdx
@@ -121,7 +121,7 @@ See [#app-store-mac-app-store](/routes/program-update#app-store-mac-app-store)
-### Macao Pagina Electrónica Especial Contra Epidemias: What’s New {#corona-virus-disease-2019-macao-pagina-electr%C3%B3nica-especial-contra-epidemias-what-s-new}
+### Macao Pagina Electrónica Especial Contra Epidemias: What’s New {#corona-virus-disease-2019-macao-pagina-electronica-especial-contra-epidemias-what-s-new}
Official Website: [https://www.ssm.gov.mo/apps1/PreventWuhanInfection/en.aspx](https://www.ssm.gov.mo/apps1/PreventWuhanInfection/en.aspx)
diff --git a/website/i18n/zh/docusaurus-plugin-content-docs/current/install/config.md b/website/i18n/zh/docusaurus-plugin-content-docs/current/install/config.md
index cfd492e70..799c39868 100644
--- a/website/i18n/zh/docusaurus-plugin-content-docs/current/install/config.md
+++ b/website/i18n/zh/docusaurus-plugin-content-docs/current/install/config.md
@@ -553,6 +553,10 @@ Web 版认证 token 和 iOS 内购回执认证 token 只需选择其一填入即
- `TOPHUB_COOKIE`: 今日热榜登录后的 cookie,目前只需要 `itc_center_user=...` 以获取原始链接
+### 米游社
+
+- `MIHOYO_COOKIE`:登录米游社后的 cookie,用于获取用户关注动态时间线。
+
### 南方周末
付费全文