From cee08ee087519e5e073ee542b628435ac5970f7f Mon Sep 17 00:00:00 2001 From: Cloud Date: Tue, 16 Jul 2019 11:05:53 +0800 Subject: [PATCH] feat: add nosetime (#2623) --- docs/other.md | 10 +++++++ lib/router.js | 4 +++ lib/routes/nosetime/comment.js | 52 ++++++++++++++++++++++++++++++++++ lib/routes/nosetime/home.js | 28 ++++++++++++++++++ 4 files changed, 94 insertions(+) create mode 100644 lib/routes/nosetime/comment.js create mode 100644 lib/routes/nosetime/home.js diff --git a/docs/other.md b/docs/other.md index c2ef839043..0033212e61 100644 --- a/docs/other.md +++ b/docs/other.md @@ -887,6 +887,16 @@ type 为 all 时,category 参数不支持 cost 和 free +## 香水时代 + +### 首页 + + + +### 香评 + + + ## 新浪专栏 ### 创事记 diff --git a/lib/router.js b/lib/router.js index 4e92312798..d36f489e37 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1495,4 +1495,8 @@ router.get('/aptonic/action', require('./routes/aptonic/action')); // 印记中文周刊 router.get('/docschina/jsweekly', require('./routes/docschina/jsweekly')); +// 香水时代 +router.get('/nosetime/:id/:type/:sort?', require('./routes/nosetime/comment')); +router.get('/nosetime/home', require('./routes/nosetime/home')); + module.exports = router; diff --git a/lib/routes/nosetime/comment.js b/lib/routes/nosetime/comment.js new file mode 100644 index 0000000000..0f5cd4508c --- /dev/null +++ b/lib/routes/nosetime/comment.js @@ -0,0 +1,52 @@ +const got = require('@/utils/got'); + +module.exports = async (ctx) => { + const id = ctx.params.id; + const type = ctx.params.type || 'discuss'; // short一句话 discuss + const sort = ctx.params.sort || 'new'; // new最新 agree最有用 + + const link = `https://www.nosetime.com/member/member_comment.php?id=${id}&type=${type}&o=${sort}`; + + const userinfo = await got({ + method: 'POST', + url: 'https://www.nosetime.com/app/user.php', + headers: { + Referer: link, + 'Content-Type': 'application/json;charset=utf-8', + }, + data: JSON.stringify({ + method: 'getsocialinfo', + id: id, + }), + }); + + const response = await got({ + method: 'POST', + url: 'https://www.nosetime.com/app/user.php', + headers: { + Referer: link, + 'Content-Type': 'application/json;charset=utf-8', + }, + data: JSON.stringify({ + method: `getweb${type}`, + id: id, + orderby: sort, + page: 1, + }), + }); + + const items = response.data.items.map((item) => ({ + title: `${'★★★★★☆☆☆☆☆'.slice(5 - item.score, 10 - item.score)} ${item.name}`, + description: item.content, + pubDate: new Date(item.time).toUTCString(), + link: `https://www.nosetime.com/xiangshui/${item.id}-${item.iurl}.html`, + author: userinfo.data.uname, + })); + + ctx.state.data = { + title: `香水时代 - ${userinfo.data.uname}`, + link: link, + description: userinfo.data.udesc, + item: items, + }; +}; diff --git a/lib/routes/nosetime/home.js b/lib/routes/nosetime/home.js new file mode 100644 index 0000000000..a935f9aeb2 --- /dev/null +++ b/lib/routes/nosetime/home.js @@ -0,0 +1,28 @@ +const got = require('@/utils/got'); + +module.exports = async (ctx) => { + const link = `https://www.nosetime.com/perfume.php`; + + const response = await got({ + method: 'GET', + url: 'https://www.nosetime.com/app/smart.php?page=1&type=discovery', + headers: { + Referer: link, + }, + }); + + const items = response.data.items.map((item) => ({ + title: `${'★★★★★☆☆☆☆☆'.slice(5 - item.uwscore, 10 - item.uwscore)} ${item.ifullname}`, + description: item.udcontent, + pubDate: new Date(item.uface * 1000).toUTCString(), + link: `https://www.nosetime.com/xiangshui/${item.iid}-${item.iurl}.html`, + author: item.uname, + })); + + ctx.state.data = { + title: `香水时代`, + link: link, + description: '最新香水评论|发现香水圈的新鲜事 - 香水时代NoseTime.com', + item: items, + }; +};