feat: 掌上英雄联盟-推荐新闻 (#2511)

This commit is contained in:
alizeegod
2019-06-28 17:56:08 +08:00
committed by DIYgod
parent 3225415e95
commit d5a6d5be38
3 changed files with 57 additions and 0 deletions

View File

@@ -253,6 +253,12 @@ Example: `https://store.steampowered.com/search/?specials=1&term=atelier` 中的
</Route>
## 掌上英雄联盟
### 推荐
<Route author="alizeegod" example="/lolapp/recommend" path="/lolapp/recommend"/>
## きららファンタジア|奇拉拉幻想曲
### 公告

View File

@@ -1449,4 +1449,7 @@ router.get('/lwn/alerts/:distributor', require('./routes/lwn/alerts'));
// 唱吧
router.get('/changba/:userid', require('./routes/changba/user'));
// 掌上英雄联盟
router.get('/lolapp/recommend', require('./routes/lolapp/recommend'));
module.exports = router;

View File

@@ -0,0 +1,48 @@
const got = require('@/utils/got');
const sourceTimezoneOffset = -8;
module.exports = async (ctx) => {
const cid = 12;
const areaid = 2;
const url = 'http://qt.qq.com/lua/lol_news/recommend_refresh?cid=' + cid + '&plat=ios&version=9880&areaid=' + areaid;
const res = await got.get(url);
const articles = (res.data || {}).update_list || [];
const out = await Promise.all(
articles.map(async (article) => {
const link = article.article_url;
const cache = await ctx.cache.get(link);
if (cache) {
return JSON.parse(cache);
}
const guid = article.content_id;
const title = article.title;
const time = new Date(article.publication_date);
time.setTime(time.getTime() + (sourceTimezoneOffset - time.getTimezoneOffset() / 60) * 60 * 60 * 1000);
const pubDate = time.toUTCString();
// const detailJsonLink = article.detail_json;
// const detailRes = await got.get(detailJsonLink);
const description = article.image_url_big;
const item = {
title,
description,
pubDate,
link,
guid,
};
ctx.cache.set(link, JSON.stringify(item));
return item;
})
);
ctx.state.data = {
title: '掌上英雄联盟 - 推荐',
link: 'http://lol.qq.com/app/index.html',
item: out,
};
};