feat: 添加【英雄联盟-新闻中心】RSS (#3404)

This commit is contained in:
Jeason0228
2019-11-11 12:17:05 +08:00
committed by DIYgod
parent 2583be6834
commit 77c5ce4571
3 changed files with 109 additions and 0 deletions

View File

@@ -277,6 +277,12 @@ Example: `https://store.steampowered.com/search/?specials=1&term=atelier` 中的
<Route author="MyFaith" example="/xiaoheihe/discount" path="xiaoheihe/discount"/> <Route author="MyFaith" example="/xiaoheihe/discount" path="xiaoheihe/discount"/>
## 英雄联盟
### 新闻中心
<Route author="Jeason0228" example="/lol/newsindex/all" path="/lol/newsindex/:type" :paramsDesc="['栏目分类,all=全部,zh=综合,gg=公告,ss=赛事,gl=攻略,sq=社区']"/>
## 游民星空 ## 游民星空
### 游民星空今日推荐 ### 游民星空今日推荐

View File

@@ -1569,6 +1569,9 @@ router.get('/lwn/alerts/:distributor', require('./routes/lwn/alerts'));
// 唱吧 // 唱吧
router.get('/changba/:userid', require('./routes/changba/user')); router.get('/changba/:userid', require('./routes/changba/user'));
// 英雄联盟
router.get('/lol/newsindex/:type', require('./routes/lol/newsindex'));
// 掌上英雄联盟 // 掌上英雄联盟
router.get('/lolapp/recommend', require('./routes/lolapp/recommend')); router.get('/lolapp/recommend', require('./routes/lolapp/recommend'));

100
lib/routes/lol/newsindex.js Normal file
View File

@@ -0,0 +1,100 @@
const got = require('@/utils/got');
const map = new Map([
['zh', { name: '综合', channelid: '23' }],
['gg', { name: '公告', channelid: '24' }],
['ss', { name: '赛事', channelid: '25' }],
['gl', { name: '攻略', channelid: '27' }],
['sq', { name: '社区', channelid: '1934' }],
]);
const refererUrl = 'https://lol.qq.com/news/index.shtml';
const apiUrl = 'https://apps.game.qq.com/cmc/zmMcnTargetContentList?r0=jsonp&page=1&num=16&target=';
module.exports = async (ctx) => {
const type = ctx.params.type || 'all';
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://lol.qq.com/news/index.shtml`,
description: `英雄联盟官方网站,海量风格各异的英雄,丰富、便捷的物品合成系统,游戏内置的匹配、排行和竞技系统,独创的“召唤师”系统及技能、符文、天赋等系统组合,必将带你进入一个崭新而又丰富多彩的游戏世界。`,
item: items,
};
} else {
const OutName = map.get(type).name;
const OutId = map.get(type).channelid;
ctx.state.data = {
title: `${OutName}】 - 英雄联盟 - 新闻列表`,
link: `https://lol.qq.com/news/index.shtml`,
description: `英雄联盟官方网站,海量风格各异的英雄,丰富、便捷的物品合成系统,游戏内置的匹配、排行和竞技系统,独创的“召唤师”系统及技能、符文、天赋等系统组合,必将带你进入一个崭新而又丰富多彩的游戏世界。`,
item: await getPage(OutId, OutName),
};
}
async function getPage(id, typeName) {
let list;
if (id !== '1934') {
// 非社区的数据处理多了callback需要截取
const response = (await got({
method: 'get',
url: apiUrl + id,
headers: {
Referer: refererUrl,
},
})).data.trim();
try {
const jsonString = response.slice(9, -2);
list = JSON.parse(jsonString).data.result;
} catch (error) {
// console.error(error);
}
} else {
// id=1934社区的数据是另一个api
const response = await got({
method: 'get',
url: 'https://apps.game.qq.com/cmc/cross?serviceId=3&source=zm&tagids=1934&typeids=1,2&withtop=yes&start=0&limit=16',
headers: {
Referer: refererUrl,
},
});
list = response.data.data.items;
}
function getUrl(sRedirectURL, iDocID, sVID) {
// 由于数据源太多具体的URL返回逻辑可以参考news/index.html页面里面的handleData方法
let pageUrl;
if (sRedirectURL) {
pageUrl = sRedirectURL;
if (pageUrl.indexOf('docid') > 0) {
sRedirectURL = pageUrl;
} else {
if (pageUrl.indexOf('?') > 0) {
sRedirectURL = pageUrl + '&docid=' + iDocID;
} else {
sRedirectURL = pageUrl + '?docid=' + iDocID;
}
}
} else {
if (sVID) {
sRedirectURL = 'http://lol.qq.com/v/v2/detail.shtml?docid=' + iDocID;
} else {
sRedirectURL = 'http://lol.qq.com/news/detail.shtml?docid=' + iDocID;
}
}
pageUrl = sRedirectURL;
// console.log(iDocID,pageUrl);
// console.log('\niDocID:', iDocID, '\nsVID:', sVID, '\nsRedirectURL:', sRedirectURL, '\nsURL:', sUrl, '\npageurl:', pageUrl, '\n');
return pageUrl;
}
return list.map((item) => ({
title: `${typeName}` + item.sTitle,
link: getUrl(item.sRedirectURL, item.iDocID, item.sVID),
pubDate: new Date(`${item.sCreated} GMT`).toUTCString(),
guid: item.iDocID,
}));
}
};