feat: 王者荣耀 - 新闻列表 Rss (#3395)

This commit is contained in:
Jeason0228 2019-11-08 12:08:45 +08:00 committed by DIYgod
parent f88b07a3ef
commit e62c346df8
3 changed files with 70 additions and 0 deletions

View File

@ -257,6 +257,12 @@ Example: `https://store.steampowered.com/search/?specials=1&term=atelier` 中的
<Route author="Astrian" example="/arknights/news" path="/arknights/news"/>
## 王者荣耀
### 新闻中心
<Route author="Jeason0228" example="/pvp/newsindex/all" path="/pvp/newsindex" :paramsDesc="['栏目分类,all=全部,rm=热门xw=新闻,gg=公告,hd=活动,ss=赛事']"/>
## 小黑盒
### 用户动态

View File

@ -1621,6 +1621,9 @@ router.get('/bof/home', require('./routes/bof/home'));
router.get('/afdian/explore/:type?/:category?', require('./routes/afdian/explore'));
router.get('/afdian/dynamic/:uid', require('./routes/afdian/dynamic'));
// 王者荣耀
router.get('/pvp/newsindex/:type', require('./routes/pvp/newsindex'));
// 《明日方舟》游戏
router.get('/arknights/news', require('./routes/arknights/news'));

View File

@ -0,0 +1,61 @@
const got = require('@/utils/got');
const map = new Map([
['rm', { name: '热门', channelid: 1760 }],
['xw', { name: '新闻', channelid: 1761 }],
['gg', { name: '公告', channelid: 1762 }],
['hd', { name: '活动', channelid: 1763 }],
['ss', { name: '赛事', channelid: 1764 }],
// ['all', { name: '全部', channelid: 0 }],
]);
const refererUrl = 'https://pvp.qq.com/web201706/newsindex.shtml';
const apiUrl = 'https://apps.game.qq.com/wmp/v3.1/?p0=18&p1=searchNewsKeywordsList&order=sIdxTime&r0=cors&type=iTarget&source=app_news_search&pagesize=12&page=1&id=';
const pageUrl = `https://pvp.qq.com/web201706/newsdetail.shtml?tid=`;
module.exports = async (ctx) => {
const type = ctx.params.type;
if (type === 'all') {
const tasks = [];
for (const value of map.values()) {
tasks.push(getPage(value.channelid, value.name));
}
const results = await Promise.all(tasks);
let items = [];
results.forEach((result) => {
items = items.concat(result);
});
ctx.state.data = {
title: `【全部】 - 王者荣耀 - 新闻列表`,
link: `https://pvp.qq.com/web201706/newsindex.shtml`,
description: `《王者荣耀》是腾讯天美工作室历时3年推出的东方英雄即时对战手游大作抗塔强杀、团灭超神领略爽热血竞技的酣畅淋漓1v1、3v3、闯关等丰富游戏模式随时战更自由跨服匹配秒开局好友组队战排位不靠装备、没有等级更公平、更爽快的无差异对战`,
item: items,
};
} else {
const OutName = map.get(type).name;
const OutId = map.get(type).channelid;
// const OutData = map.get(type).dataArr;
ctx.state.data = {
title: `${OutName}】 - 王者荣耀 - 新闻列表`,
link: `https://pvp.qq.com/web201706/newsindex.shtml`,
description: `《王者荣耀》是腾讯天美工作室历时3年推出的东方英雄即时对战手游大作抗塔强杀、团灭超神领略爽热血竞技的酣畅淋漓1v1、3v3、闯关等丰富游戏模式随时战更自由跨服匹配秒开局好友组队战排位不靠装备、没有等级更公平、更爽快的无差异对战`,
item: await getPage(OutId, OutName),
};
}
async function getPage(id, typeName) {
const response = await got({
method: 'get',
url: apiUrl + id,
headers: {
Referer: refererUrl,
},
});
const list = response.data.msg.result;
return list.map((item) => {
const single = {
title: `${typeName}` + item.sTitle,
link: pageUrl + item.iNewsId,
pubDate: new Date(`${item.sTargetIdxTime} GMT`).toUTCString(),
guid: item.iNewsId,
};
return single;
});
}
};