From a7fc1881f8f84d78746f468d4919787a5f00b11c Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Sun, 13 Dec 2020 00:21:21 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E5=8D=B0=E8=B1=A1=E8=AF=86?= =?UTF-8?q?=E5=A0=82=E7=94=A8=E6=88=B7=E5=85=AC=E5=BC=80=E7=AC=94=E8=AE=B0?= =?UTF-8?q?=20&=20=E7=AC=94=E8=AE=B0=E5=88=86=E7=B1=BB=20&=20=E7=AC=94?= =?UTF-8?q?=E8=AE=B0=E6=A0=87=E7=AD=BE=20(#6414)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/study.md | 12 +++++++++ lib/router.js | 5 +++- lib/routes/yinxiang/category.js | 47 ++++++++++++++++++++++++++++++++ lib/routes/yinxiang/personal.js | 48 +++++++++++++++++++++++++++++++++ lib/routes/yinxiang/tag.js | 47 ++++++++++++++++++++++++++++++++ 5 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 lib/routes/yinxiang/category.js create mode 100644 lib/routes/yinxiang/personal.js create mode 100644 lib/routes/yinxiang/tag.js diff --git a/docs/study.md b/docs/study.md index b4342b8c15..f79d1b8eff 100644 --- a/docs/study.md +++ b/docs/study.md @@ -399,6 +399,18 @@ pageClass: routes +### 用户公开笔记 + + + +### 笔记分类 + + + +### 笔记标签 + + + ## 英中协会 ### 奖学金 diff --git a/lib/router.js b/lib/router.js index 680e7736af..84212d5756 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3639,7 +3639,10 @@ router.get('/youdao/latest', require('./routes/youdao/latest')); // 印象识堂 router.get('/yinxiang/note', require('./routes/yinxiang/note')); -router.get('/yinxiang/card/:id?', require('./routes/yinxiang/card')); +router.get('/yinxiang/tag/:id', require('./routes/yinxiang/tag')); +router.get('/yinxiang/card/:id', require('./routes/yinxiang/card')); +router.get('/yinxiang/personal/:id', require('./routes/yinxiang/personal')); +router.get('/yinxiang/category/:id', require('./routes/yinxiang/category')); // 晚点LatePost router.get('/latepost/:proma?', require('./routes/latepost/index')); diff --git a/lib/routes/yinxiang/category.js b/lib/routes/yinxiang/category.js new file mode 100644 index 0000000000..3f5176496c --- /dev/null +++ b/lib/routes/yinxiang/category.js @@ -0,0 +1,47 @@ +const got = require('@/utils/got'); + +module.exports = async (ctx) => { + const id = ctx.params.id; + + const apiUrl = `https://app.yinxiang.com/third/discovery/client/restful/public/category/page?notePageSize=20&lastBlogNoteGuid=&cateGoryId=${id}`; + const response = await got({ + method: 'get', + url: apiUrl, + }); + + const list = response.data.categoryNoteSnapshotReply.map((item) => ({ + title: item.title, + link: item.noteGuid, + author: item.userNickname, + })); + + const items = await Promise.all( + list.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: `https://app.yinxiang.com/third/discovery/client/restful/public/blog-note?noteGuid=${item.link}`, + }); + + item.link = `https://www.yinxiang.com/everhub/note/${item.link}`; + item.pubDate = new Date(parseInt(detailResponse.data.blogNote.publishTime)).toUTCString(); + + const description = detailResponse.data.blogNote.htmlContent; + if (description.indexOf('(.*)<\/en-note>/)[1]; + } + + return item; + }) + ) + ); + + ctx.state.data = { + title: `${response.data.categoryName} - 印象识堂`, + link: `https://www.yinxiang.com/everhub/category/${id}`, + item: items, + }; +}; diff --git a/lib/routes/yinxiang/personal.js b/lib/routes/yinxiang/personal.js new file mode 100644 index 0000000000..32fa25a461 --- /dev/null +++ b/lib/routes/yinxiang/personal.js @@ -0,0 +1,48 @@ +const got = require('@/utils/got'); + +module.exports = async (ctx) => { + const id = ctx.params.id; + + const apiUrl = `https://app.yinxiang.com/third/discovery/client/restful/public/blog-user/homepage?encryptedUserId=${id}&lastNoteGuid=¬ePageSize=20`; + const response = await got({ + method: 'get', + url: apiUrl, + }); + + const list = response.data.blogNote.map((item) => ({ + title: item.title, + link: item.noteGuid, + author: item.userNickname, + })); + + const items = await Promise.all( + list.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: `https://app.yinxiang.com/third/discovery/client/restful/public/blog-note?noteGuid=${item.link}`, + }); + + item.link = `https://www.yinxiang.com/everhub/note/${item.link}`; + item.pubDate = new Date(parseInt(detailResponse.data.blogNote.publishTime)).toUTCString(); + + const description = detailResponse.data.blogNote.htmlContent; + if (description.indexOf('(.*)<\/en-note>/)[1]; + } + + return item; + }) + ) + ); + + ctx.state.data = { + title: `${response.data.blogUser.nickname} - 印象识堂`, + link: `https://www.yinxiang.com/everhub/category/${id}`, + description: response.data.blogUser.introduction, + item: items, + }; +}; diff --git a/lib/routes/yinxiang/tag.js b/lib/routes/yinxiang/tag.js new file mode 100644 index 0000000000..4490810fff --- /dev/null +++ b/lib/routes/yinxiang/tag.js @@ -0,0 +1,47 @@ +const got = require('@/utils/got'); + +module.exports = async (ctx) => { + const id = ctx.params.id; + + const apiUrl = `https://app.yinxiang.com/third/discovery/client/restful/public/tag/note?pageSize=20&tagName=${id}`; + const response = await got({ + method: 'get', + url: apiUrl, + }); + + const list = response.data.blogNote.map((item) => ({ + title: item.title, + link: item.noteGuid, + author: item.userNickname, + })); + + const items = await Promise.all( + list.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: `https://app.yinxiang.com/third/discovery/client/restful/public/blog-note?noteGuid=${item.link}`, + }); + + item.link = `https://www.yinxiang.com/everhub/note/${item.link}`; + item.pubDate = new Date(parseInt(detailResponse.data.blogNote.publishTime)).toUTCString(); + + const description = detailResponse.data.blogNote.htmlContent; + if (description.indexOf('(.*)<\/en-note>/)[1]; + } + + return item; + }) + ) + ); + + ctx.state.data = { + title: `${response.data.tagInfo.name} - 印象识堂`, + link: `https://www.yinxiang.com/everhub/tagtheme/${id}`, + item: items, + }; +};