feat: add 有道云笔记学霸感悟 & 笔记最新动态 (#6208)

This commit is contained in:
Ethan Shen 2020-11-24 20:11:28 +08:00 committed by GitHub
parent 061314a118
commit 61e2ef53a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 127 additions and 0 deletions

View File

@ -326,6 +326,16 @@ pageClass: routes
<Route author="HenryQW" example="/gbcc/trust" path="/gbcc/trust" />
## 有道云笔记
### 学霸感悟
<Route author="nczitzk" example="/youdao/xueba" path="/youdao/xueba" />
### 笔记最新动态
<Route author="nczitzk" example="/youdao/latest" path="/youdao/latest" />
## 语雀
### 知识库

View File

@ -3509,6 +3509,10 @@ router.get('/uisdc/news', require('./routes/uisdc/news'));
router.get('/uisdc/zt/:title?', require('./routes/uisdc/zt'));
router.get('/uisdc/topic/:title?/:sort?', require('./routes/uisdc/topic'));
// 有道云笔记
router.get('/youdao/xueba', require('./routes/youdao/xueba'));
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'));

View File

@ -0,0 +1,48 @@
const got = require('@/utils/got');
module.exports = async (ctx) => {
const rootUrl = 'http://xueba.youdao.com';
const apiUrl = `${rootUrl}/yws/mapi/xueba/library?method=realTimeCollect&count=10`;
const response = await got({
method: 'get',
url: apiUrl,
});
const list = response.data.Clt.map((item) => ({
title: `${item.name} 保存了 ${item.title}`,
pubDate: new Date(item.time).toUTCString(),
link: `http://note.youdao.com/publicshare/?id=${item.shareKey}`,
}));
const items = await Promise.all(
list.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const id = item.link.split('?id=')[1];
try {
const contentResponse = await got({
method: 'get',
url: `http://note.youdao.com/yws/public/notebook/${id}`,
});
item.description = '';
for (const note of contentResponse.data[2]) {
item.description += `<h3><a href="http://note.youdao.com/publicshare?id=${id}#/${note.p.split('/')[2]}">${note.tl}</a></h3><p>${note.pp.dg}</p>`;
}
} catch (e) {
const contentResponse = await got({
method: 'get',
url: `http://note.youdao.com/yws/public/note/${id}`,
});
item.description = contentResponse.data.content;
}
return item;
})
)
);
ctx.state.data = {
title: `笔记最新动态 - 有道云笔记`,
link: rootUrl,
item: items,
};
};

View File

@ -0,0 +1,65 @@
const got = require('@/utils/got');
module.exports = async (ctx) => {
const rootUrl = 'http://xueba.youdao.com';
const apiUrl = `${rootUrl}/yws/mapi/xueba/library?method=search`;
const response = await got({
method: 'post',
url: apiUrl,
form: {
keyword: '',
begin: 0,
count: 9,
primary_category: 4,
},
});
const authors = {};
for (const author of response.data.xuebas) {
authors[author.uid] = author.name;
}
const list = response.data.notes.map((item) => ({
type: item.type,
title: item.title,
author: item.userId,
description: item.description,
pubDate: new Date(item.upt).toUTCString(),
link: `http://note.youdao.com/publicshare/?type=${item.type}&id=${item.id}`,
}));
const items = await Promise.all(
list.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
try {
const id = item.link.split('&id=')[1];
const contentResponse = await got({
method: 'get',
url: `http://note.youdao.com/yws/public/${item.type}/${id}`,
});
if (item.type === 'note') {
item.description = contentResponse.data.content;
} else {
item.description = '';
for (const note of contentResponse.data[2]) {
item.description += `<h3><a href="http://note.youdao.com/publicshare?id=${id}#/${note.p.split('/')[2]}">${note.tl}</a></h3><p>${note.pp.dg}</p>`;
}
}
} catch (e) {
return Promise.resolve('');
} finally {
item.author = authors[item.author];
}
return item;
})
)
);
ctx.state.data = {
title: `学霸感悟 - 有道云笔记`,
link: rootUrl,
item: items,
};
};