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, + }; +};