add 电商在线 (#1936)

closes #1914
This commit is contained in:
Chenyang Shi
2019-04-17 11:58:12 +08:00
committed by DIYgod
parent 61547c4f3c
commit ec33f344e0
3 changed files with 71 additions and 0 deletions
+4
View File
@@ -483,3 +483,7 @@ type 为 all 时,category 参数不支持 cost 和 free
### checkee.info
<Route name="美国签证 check 动态" author="lalxyy" example="/checkee/2019-03" path="/checkee/:month" :paramsDesc="['签证被 check 的年份-月份,如 2019-03']" />
### 电商在线
<Route name="电商在线" author="LogicJake" example="/imaijia/category/xls" path="/imaijia/category/:category" :paramsDesc="['类别id,可在 URL 中找到']" />
+3
View File
@@ -1248,6 +1248,9 @@ router.get('/mobdata/report', require('./routes/mobdata/report'));
// 谷雨
router.get('/tencent/guyu/channel/:name', require('./routes/tencent/guyu/channel'));
// 电商在线
router.get('/imaijia/category/:category', require('./routes/imaijia/category'));
// 21财经
router.get('/21caijing/channel/:name', require('./routes/21caijing/channel'));
+64
View File
@@ -0,0 +1,64 @@
const axios = require('../../utils/axios');
const qs = require('querystring');
module.exports = async (ctx) => {
const category = ctx.params.category;
const api_url = `http://www.imaijia.com/xstb/front/authorArticleController.do?indexArticles&pageSize=20`;
const url = `http://www.imaijia.com/#/information.htm?catid=${category}`;
const response = await axios({
method: 'post',
headers: {
Referer: url,
},
url: api_url,
data: qs.stringify({
pageNo: 1,
catid: `${category}`,
}),
});
const data = response.data;
const description = data.description;
const name = data.catName;
const list = data.resList;
const out = await Promise.all(
list.map(async (info) => {
const title = info.title;
const cat_path = info.catPath;
const id = info.id;
const itemUrl = `http://www.imaijia.com/#/atricleDetails.htm?atricleId=${id}&catPath=${cat_path}`;
const api_url = `http://www.imaijia.com/data/details/${cat_path}${id}.json`;
const pubDate = info.created;
const author = info.author;
const cache = await ctx.cache.get(itemUrl);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const response = await axios.get(api_url);
const description = response.data.resList.articleDataF.content.replace(/src="/g, 'src="http://www.imaijia.com');
const single = {
title: title,
link: itemUrl,
author: author,
description: description,
pubDate: new Date(pubDate).toUTCString(),
};
ctx.cache.set(itemUrl, JSON.stringify(single), 24 * 60 * 60);
return Promise.resolve(single);
})
);
ctx.state.data = {
title: `电商在线-${name}`,
description: description,
link: url,
item: out,
};
};