fix(route): yuanshen news error (#11115)

* fix: yuanshen new route

* refactor: migrate to v2

* fix: full article feed
This commit is contained in:
Raven-tu
2022-10-28 04:25:34 +08:00
committed by GitHub
parent 125f2733ca
commit 6fe52ef253
7 changed files with 116 additions and 85 deletions
+12 -12
View File
@@ -675,6 +675,18 @@ Example:`https://www.iyingdi.com/tz/people/55547` ,id 是 `55547`
</Route>
### 原神
#### 新闻
<Route author="nczitzk" example="/mihoyo/ys" path="/mihoyo/ys/:location?/:category?" :paramsDesc="['区域,可选 `main`(简中)或 `zh-tw`(繁中)', '分类,见下表,默认为最新']">
| 最新 | 新闻 | 公告 | 活动 |
| ------ | ---- | ------ | -------- |
| latest | news | notice | activity |
</Route>
## 明日方舟
### 游戏公告与新闻
@@ -889,18 +901,6 @@ Example:`https://www.iyingdi.com/tz/people/55547` ,id 是 `55547`
<Route author="HaitianLiu" example="/yystv/docs" path="/yystv/docs" />
## 原神
### 新闻
<Route author="nczitzk" example="/yuanshen" path="/yuanshen/:location?/:category?" :paramsDesc="['区域,可选 zh_CN 或 zh_TW', '分类,见下表,默认为最新']">
| 最新 | 新闻 | 公告 | 活动 |
| ------ | ---- | ------ | -------- |
| latest | news | notice | activity |
</Route>
## 掌上英雄联盟
### 推荐
+2 -2
View File
@@ -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'));
-70
View File
@@ -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,
};
};
+1
View File
@@ -1,3 +1,4 @@
module.exports = {
'/bbs/official/:gids/:type?/:page_size?/:last_id?': ['CaoMeiYouRen'],
'/ys/:location?/:category?': ['nczitzk'],
};
+20 -1
View File
@@ -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',
},
],
},
};
+1
View File
@@ -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'));
};
+80
View File
@@ -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,
};
};