From 6fe52ef253adcc6cf11a556ff90d000723efcd65 Mon Sep 17 00:00:00 2001
From: Raven-tu <80778915raventu@gmail.com>
Date: Fri, 28 Oct 2022 04:25:34 +0800
Subject: [PATCH] fix(route): yuanshen news error (#11115)
* fix: yuanshen new route
* refactor: migrate to v2
* fix: full article feed
---
docs/game.md | 24 +++++------
lib/router.js | 4 +-
lib/routes/yuanshen/index.js | 70 -------------------------------
lib/v2/mihoyo/maintainer.js | 1 +
lib/v2/mihoyo/radar.js | 21 +++++++++-
lib/v2/mihoyo/router.js | 1 +
lib/v2/mihoyo/ys/news.js | 80 ++++++++++++++++++++++++++++++++++++
7 files changed, 116 insertions(+), 85 deletions(-)
delete mode 100644 lib/routes/yuanshen/index.js
create mode 100644 lib/v2/mihoyo/ys/news.js
diff --git a/docs/game.md b/docs/game.md
index c9400f7424..f20d3f287a 100644
--- a/docs/game.md
+++ b/docs/game.md
@@ -675,6 +675,18 @@ Example:`https://www.iyingdi.com/tz/people/55547` ,id 是 `55547`
+### 原神
+
+#### 新闻
+
+
+
+| 最新 | 新闻 | 公告 | 活动 |
+| ------ | ---- | ------ | -------- |
+| latest | news | notice | activity |
+
+
+
## 明日方舟
### 游戏公告与新闻
@@ -889,18 +901,6 @@ Example:`https://www.iyingdi.com/tz/people/55547` ,id 是 `55547`
-## 原神
-
-### 新闻
-
-
-
-| 最新 | 新闻 | 公告 | 活动 |
-| ------ | ---- | ------ | -------- |
-| latest | news | notice | activity |
-
-
-
## 掌上英雄联盟
### 推荐
diff --git a/lib/router.js b/lib/router.js
index 2f0d4609a7..68b5c928bb 100644
--- a/lib/router.js
+++ b/lib/router.js
@@ -3275,8 +3275,8 @@ router.get('/ofweek/news', lazyloadRouteHandler('./routes/ofweek/news'));
// 八阕
router.get('/popyard/:caty?', lazyloadRouteHandler('./routes/popyard/index'));
-// 原神
-router.get('/yuanshen/:location?/:category?', lazyloadRouteHandler('./routes/yuanshen/index'));
+// 原神 migrated to v2
+// router.get('/yuanshen/:location?/:category?', lazyloadRouteHandler('./routes/yuanshen/index'));
// World Trade Organization
router.get('/wto/dispute-settlement/:year?', lazyloadRouteHandler('./routes/wto/dispute-settlement'));
diff --git a/lib/routes/yuanshen/index.js b/lib/routes/yuanshen/index.js
deleted file mode 100644
index 5f93f36760..0000000000
--- a/lib/routes/yuanshen/index.js
+++ /dev/null
@@ -1,70 +0,0 @@
-const got = require('@/utils/got');
-
-const config = {
- latest: {
- zh_CN: '10',
- zh_TW: '87',
- },
- news: {
- zh_CN: '11',
- zh_TW: '90',
- },
- notice: {
- zh_CN: '12',
- zh_TW: '91',
- },
- activity: {
- zh_CN: '258',
- zh_TW: '92',
- },
-};
-
-const titles = {
- latest: {
- zh_CN: '最新',
- zh_TW: '最新',
- },
- news: {
- zh_CN: '新闻',
- zh_TW: '資訊',
- },
- notice: {
- zh_CN: '公告',
- zh_TW: '公告',
- },
- activity: {
- zh_CN: '活动',
- zh_TW: '活動',
- },
-};
-
-module.exports = async (ctx) => {
- ctx.params.location = ctx.params.location || 'zh_CN';
- ctx.params.category = ctx.params.category || 'latest';
-
- let rootUrl;
-
- if (ctx.params.location === 'zh_CN') {
- rootUrl = `https://ys.mihoyo.com/content/ysCn/getContentList?pageSize=5&pageNum=1&channelId=${config[ctx.params.category][ctx.params.location]}`;
- } else {
- rootUrl = `https://genshin.mihoyo.com/content/yuanshen/getContentList?pageSize=5&pageNum=1&channelId=${config[ctx.params.category][ctx.params.location]}`;
- }
-
- const response = await got({
- method: 'get',
- url: rootUrl,
- });
-
- const list = response.data.data.list.map((item) => ({
- title: item.title,
- link: `https://ys.mihoyo.com/main/news/detail/${item.id}`,
- pubDate: new Date(item.start_time + ' GMT+8').toUTCString(),
- author: item.author,
- }));
-
- ctx.state.data = {
- title: `${titles[ctx.params.category][ctx.params.location]} - 原神`,
- link: rootUrl,
- item: list,
- };
-};
diff --git a/lib/v2/mihoyo/maintainer.js b/lib/v2/mihoyo/maintainer.js
index a18b6786d8..1346058213 100644
--- a/lib/v2/mihoyo/maintainer.js
+++ b/lib/v2/mihoyo/maintainer.js
@@ -1,3 +1,4 @@
module.exports = {
'/bbs/official/:gids/:type?/:page_size?/:last_id?': ['CaoMeiYouRen'],
+ '/ys/:location?/:category?': ['nczitzk'],
};
diff --git a/lib/v2/mihoyo/radar.js b/lib/v2/mihoyo/radar.js
index 1f593992c5..a4d14a88d8 100644
--- a/lib/v2/mihoyo/radar.js
+++ b/lib/v2/mihoyo/radar.js
@@ -1,6 +1,17 @@
module.exports = {
+ 'hoyoverse.com': {
+ _name: '米哈游',
+ genshin: [
+ {
+ title: '原神 - 新闻',
+ docs: 'https://docs.rsshub.app/game.html##mi-ha-you',
+ source: '/:location/news',
+ target: '/mihoyo/ys/:location',
+ },
+ ],
+ },
'mihoyo.com': {
- _name: '米游社v2',
+ _name: '米哈游',
bbs: [
{
title: '米游社 - 官方公告',
@@ -27,5 +38,13 @@ module.exports = {
},
},
],
+ ys: [
+ {
+ title: '原神 - 新闻',
+ docs: 'https://docs.rsshub.app/game.html##mi-ha-you',
+ source: '/:location/news/:category',
+ target: '/mihoyo/ys/:location/:category',
+ },
+ ],
},
};
diff --git a/lib/v2/mihoyo/router.js b/lib/v2/mihoyo/router.js
index b0bd1b7836..1e16b7cb2e 100644
--- a/lib/v2/mihoyo/router.js
+++ b/lib/v2/mihoyo/router.js
@@ -1,3 +1,4 @@
module.exports = function (router) {
router.get('/bbs/official/:gids/:type?/:page_size?/:last_id?', require('./bbs'));
+ router.get('/ys/:location?/:category?', require('./ys/news'));
};
diff --git a/lib/v2/mihoyo/ys/news.js b/lib/v2/mihoyo/ys/news.js
new file mode 100644
index 0000000000..6e41867974
--- /dev/null
+++ b/lib/v2/mihoyo/ys/news.js
@@ -0,0 +1,80 @@
+const got = require('@/utils/got');
+const { parseDate } = require('@/utils/parse-date');
+const timezone = require('@/utils/timezone');
+
+const config = {
+ latest: {
+ main: '10',
+ 'zh-tw': '87',
+ },
+ news: {
+ main: '11',
+ 'zh-tw': '90',
+ },
+ notice: {
+ main: '12',
+ 'zh-tw': '91',
+ },
+ activity: {
+ main: '258',
+ 'zh-tw': '92',
+ },
+};
+
+const titles = {
+ latest: {
+ main: '最新',
+ 'zh-tw': '最新',
+ },
+ news: {
+ main: '新闻',
+ 'zh-tw': '資訊',
+ },
+ notice: {
+ main: '公告',
+ 'zh-tw': '公告',
+ },
+ activity: {
+ main: '活动',
+ 'zh-tw': '活動',
+ },
+};
+
+module.exports = async (ctx) => {
+ const location = ctx.params.location ?? 'main';
+ const category = ctx.params.category ?? 'latest';
+
+ const is_zh_CN = location === 'main';
+
+ const rootUrl = is_zh_CN
+ ? `https://ys.mihoyo.com/content/ysCn/getContentList?pageSize=5&pageNum=1&channelId=${config[category][location]}`
+ : `https://genshin.mihoyo.com/content/yuanshen/getContentList?pageSize=5&pageNum=1&channelId=${config[category][location]}`;
+
+ const response = await got(rootUrl);
+
+ const article_zh_CN = 'https://ys.mihoyo.com/main/news';
+ const article_zh_TW = 'https://genshin.hoyoverse.com/zh-tw/news';
+
+ const list = response.data.data.list.map((item) => ({
+ title: item.title,
+ link: is_zh_CN ? `${article_zh_CN}/detail/${item.id}` : `${article_zh_TW}/detail/${item.id}`,
+ pubDate: timezone(parseDate(item.start_time), 8),
+ author: item.author,
+ }));
+
+ const items = await Promise.all(
+ list.map((item) =>
+ ctx.cache.tryGet(item.link, async () => {
+ const { data: response } = await got(item.link);
+ item.description = JSON.parse(response.match(/,content:(".*?"),ext:\[\{/)[1]);
+ return item;
+ })
+ )
+ );
+
+ ctx.state.data = {
+ title: `${titles[category][location]} - 原神`,
+ link: is_zh_CN ? `${article_zh_CN}/${config[category][location]}` : article_zh_TW,
+ item: items,
+ };
+};