feat: add 印象识堂用户公开笔记 & 笔记分类 & 笔记标签 (#6414)

This commit is contained in:
Ethan Shen
2020-12-13 00:21:21 +08:00
committed by GitHub
parent 7eca233758
commit a7fc1881f8
5 changed files with 158 additions and 1 deletions

View File

@@ -399,6 +399,18 @@ pageClass: routes
</Route>
### 用户公开笔记
<Route author="nczitzk" example="/yinxiang/personal/ZUhuRTmW5SKE7vvHPqI7cg" path="/yinxiang/personal/:id" :paramsDesc="['用户 id可在用户页 URL 中找到']" />
### 笔记分类
<Route author="nczitzk" example="/yinxiang/category/28" path="/yinxiang/category/:id" :paramsDesc="['分类 id可在分类页 URL 中找到']" />
### 笔记标签
<Route author="nczitzk" example="/yinxiang/tag/人生算法" path="/yinxiang/tag/:id" :paramsDesc="['标签名,可在标签页中找到']" />
## 英中协会
### 奖学金

View File

@@ -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'));

View File

@@ -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('<?xml') < 0) {
item.description = description;
} else {
item.description = description.match(/<en-note>(.*)<\/en-note>/)[1];
}
return item;
})
)
);
ctx.state.data = {
title: `${response.data.categoryName} - 印象识堂`,
link: `https://www.yinxiang.com/everhub/category/${id}`,
item: items,
};
};

View File

@@ -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=&notePageSize=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('<?xml') < 0) {
item.description = description;
} else {
item.description = description.match(/<en-note>(.*)<\/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,
};
};

View File

@@ -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('<?xml') < 0) {
item.description = description;
} else {
item.description = description.match(/<en-note>(.*)<\/en-note>/)[1];
}
return item;
})
)
);
ctx.state.data = {
title: `${response.data.tagInfo.name} - 印象识堂`,
link: `https://www.yinxiang.com/everhub/tagtheme/${id}`,
item: items,
};
};