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

@@ -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,
};
};