feat: added MaxNews of Dota 2 (#2176)

* feat: added MaxNews of Dota 2

* fix: CRLF -> LF
This commit is contained in:
Yu Jin
2019-05-19 02:31:25 -07:00
committed by DIYgod
parent 88e8b4900d
commit 501b8febd5
3 changed files with 54 additions and 0 deletions

View File

@@ -192,3 +192,9 @@ Example: `https://store.steampowered.com/search/?specials=1&term=atelier` 中的
### 公告 ### 公告
<Route author="magic-akari" example="/kirara/news" path="/kirara/news"/> <Route author="magic-akari" example="/kirara/news" path="/kirara/news"/>
## MaxNews
### Dota 2
<Route author="dearrrfish" example="/maxnews/dota2" path="maxnews/dota2" />

View File

@@ -1310,6 +1310,9 @@ router.get('/enclavebooks/category/:id?', require('./routes/enclavebooks/categor
router.get('/dsndsht23/:subforumid', require('./routes/dsndsht23/index')); router.get('/dsndsht23/:subforumid', require('./routes/dsndsht23/index'));
router.get('/dsndsht23', require('./routes/dsndsht23/index')); router.get('/dsndsht23', require('./routes/dsndsht23/index'));
// MaxNews - DotA 2
router.get('/maxnews/dota2', require('./routes/maxnews/dota2'));
// 数英网最新文章 // 数英网最新文章
router.get('/digitaling/index', require('./routes/digitaling/index')); router.get('/digitaling/index', require('./routes/digitaling/index'));

View File

@@ -0,0 +1,45 @@
const axios = require('@/utils/axios');
const sourceTimezoneOffset = -8;
module.exports = async (ctx) => {
const url = 'https://news.maxjia.com/maxnews/app/list/';
const res = await axios.get(url);
const articles = (res.data || {}).result || [];
const out = await Promise.all(
articles.map(async (article) => {
const link = article.newUrl;
const cache = await ctx.cache.get(link);
if (cache) {
return JSON.parse(cache);
}
const guid = article.newsid;
const title = article.title;
const time = new Date(article.date);
time.setTime(time.getTime() + (sourceTimezoneOffset - time.getTimezoneOffset() / 60) * 60 * 60 * 1000);
const pubDate = time.toUTCString();
const detailJsonLink = article.detail_json;
const detailRes = await axios.get(detailJsonLink);
const description = detailRes.data.content;
const item = {
title,
description,
pubDate,
link,
guid,
};
ctx.cache.set(link, JSON.stringify(item));
return item;
})
);
ctx.state.data = {
title: 'MaxNews - Dota 2',
link: 'https://www.maxjia.com',
item: out,
};
};