From ba3ef16542658d429fbf1354ad7cc6a3ba56b159 Mon Sep 17 00:00:00 2001 From: Chenyang Shi Date: Wed, 13 Feb 2019 14:29:14 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E8=85=BE=E8=AE=AF=E5=A4=A7=E5=AE=B6?= =?UTF-8?q?=E7=9A=84=E4=BD=9C=E8=80=85=E4=B8=8E=E4=B8=93=E6=A0=8F=20(#1537?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes #1535 --- docs/README.md | 2 ++ lib/router.js | 2 ++ lib/routes/tencent/dajia/author.js | 52 +++++++++++++++++++++++++++ lib/routes/tencent/dajia/zhuanlan.js | 54 ++++++++++++++++++++++++++++ 4 files changed, 110 insertions(+) create mode 100644 lib/routes/tencent/dajia/author.js create mode 100644 lib/routes/tencent/dajia/zhuanlan.js diff --git a/docs/README.md b/docs/README.md index ceebc5c38..5bce90321 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2703,6 +2703,8 @@ Example: `https://store.steampowered.com/search/?specials=1&term=atelier` 中的 ### 腾讯大家 + + ### 抽屉 diff --git a/lib/router.js b/lib/router.js index 4d93d2ebf..eb3ced727 100644 --- a/lib/router.js +++ b/lib/router.js @@ -467,6 +467,8 @@ router.get('/aqk/:category', require('./routes/aqk/category')); // 腾讯大家 router.get('/dajia', require('./routes/tencent/dajia/index')); +router.get('/dajia/author/:uid', require('./routes/tencent/dajia/author')); +router.get('/dajia/zhuanlan/:uid', require('./routes/tencent/dajia/zhuanlan')); // 腾讯游戏开发者社区 router.get('/gameinstitute/community/:tag?', require('./routes/tencent/gameinstitute/community')); diff --git a/lib/routes/tencent/dajia/author.js b/lib/routes/tencent/dajia/author.js new file mode 100644 index 000000000..d253709b4 --- /dev/null +++ b/lib/routes/tencent/dajia/author.js @@ -0,0 +1,52 @@ +const axios = require('../../../utils/axios'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const uid = ctx.params.uid; + const link = `http://dajia.qq.com/author_personal.htm#!/${uid}`; + + const info_api = `http://i.match.qq.com/ninjayc/dajiazuozheye?action=zuojia&authorid=${uid}`; + const info_response = await axios.get(info_api); + const author_name = info_response.data.data.author.name; + const description = info_response.data.data.author.description; + + const article_api = `http://i.match.qq.com/ninjayc/dajiawenzhanglist?action=wz&authorid=${uid}`; + const response = await axios.get(article_api); + const list = response.data.data; + + const out = await Promise.all( + list.map(async (info) => { + const title = info.n_title; + const date = info.n_publishtime; + const itemUrl = info.n_mobile_url; + + const cache = await ctx.cache.get(itemUrl); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + + const response = await axios.get(itemUrl); + const $ = cheerio.load(response.data); + const description = $('#articleContent') + .html() + .replace(/src="\//g, 'src="http:/') + .trim(); + + const single = { + title: title, + link: itemUrl, + description: description, + pubDate: new Date(date).toUTCString(), + }; + ctx.cache.set(itemUrl, JSON.stringify(single), 24 * 60 * 60); + return Promise.resolve(single); + }) + ); + + ctx.state.data = { + title: `${author_name}的文章——腾讯大家`, + link: link, + description: description, + item: out, + }; +}; diff --git a/lib/routes/tencent/dajia/zhuanlan.js b/lib/routes/tencent/dajia/zhuanlan.js new file mode 100644 index 000000000..7f462daae --- /dev/null +++ b/lib/routes/tencent/dajia/zhuanlan.js @@ -0,0 +1,54 @@ +const axios = require('../../../utils/axios'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const uid = ctx.params.uid; + const link = `http://dajia.qq.com/tanzi_diceng.htm#!/${uid}`; + + const info_api = `http://i.match.qq.com/ninjayc/dajialanmu?action=lanmu&channelid=${uid}`; + const info_response = await axios.get(info_api); + const name = info_response.data.data.channel.n_cname; + const description = info_response.data.data.channel.n_describe; + + const article_api = `http://i.match.qq.com/ninjayc/dajiawenzhanglist?action=wz&channelid=${uid}`; + const response = await axios.get(article_api); + const list = response.data.data; + + const out = await Promise.all( + list.map(async (info) => { + const title = info.n_title; + const date = info.n_publishtime; + const itemUrl = info.n_mobile_url; + const author = info.name; + + const cache = await ctx.cache.get(itemUrl); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + + const response = await axios.get(itemUrl); + const $ = cheerio.load(response.data); + const description = $('#articleContent') + .html() + .replace(/src="\//g, 'src="http:/') + .trim(); + + const single = { + title: title, + link: itemUrl, + description: description, + author: author, + pubDate: new Date(date).toUTCString(), + }; + ctx.cache.set(itemUrl, JSON.stringify(single), 24 * 60 * 60); + return Promise.resolve(single); + }) + ); + + ctx.state.data = { + title: `${name}——腾讯大家`, + link: link, + description: description, + item: out, + }; +};