From ec33f344e01b041442e99388966333b4f563fd40 Mon Sep 17 00:00:00 2001 From: Chenyang Shi Date: Wed, 17 Apr 2019 11:58:12 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E7=94=B5=E5=95=86=E5=9C=A8=E7=BA=BF=20(#?= =?UTF-8?q?1936)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes #1914 --- docs/other.md | 4 +++ lib/router.js | 3 ++ lib/routes/imaijia/category.js | 64 ++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 lib/routes/imaijia/category.js diff --git a/docs/other.md b/docs/other.md index d7c516c88e..dabe7d75ec 100644 --- a/docs/other.md +++ b/docs/other.md @@ -483,3 +483,7 @@ type 为 all 时,category 参数不支持 cost 和 free ### checkee.info + +### 电商在线 + + diff --git a/lib/router.js b/lib/router.js index 005279bc2f..d42fdafe07 100755 --- a/lib/router.js +++ b/lib/router.js @@ -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')); diff --git a/lib/routes/imaijia/category.js b/lib/routes/imaijia/category.js new file mode 100644 index 0000000000..7e5dd5a5fe --- /dev/null +++ b/lib/routes/imaijia/category.js @@ -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, + }; +};