diff --git a/docs/study.md b/docs/study.md index 6dfe6888d..bc560a9cf 100644 --- a/docs/study.md +++ b/docs/study.md @@ -326,6 +326,16 @@ pageClass: routes +## 有道云笔记 + +### 学霸感悟 + + + +### 笔记最新动态 + + + ## 语雀 ### 知识库 diff --git a/lib/router.js b/lib/router.js index 8e11f8992..6f9e221fd 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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')); diff --git a/lib/routes/youdao/latest.js b/lib/routes/youdao/latest.js new file mode 100644 index 000000000..51483f05d --- /dev/null +++ b/lib/routes/youdao/latest.js @@ -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 += `

${note.tl}

${note.pp.dg}

`; + } + } 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, + }; +}; diff --git a/lib/routes/youdao/xueba.js b/lib/routes/youdao/xueba.js new file mode 100644 index 000000000..8b18a5447 --- /dev/null +++ b/lib/routes/youdao/xueba.js @@ -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 += `

${note.tl}

${note.pp.dg}

`; + } + } + } catch (e) { + return Promise.resolve(''); + } finally { + item.author = authors[item.author]; + } + return item; + }) + ) + ); + + ctx.state.data = { + title: `学霸感悟 - 有道云笔记`, + link: rootUrl, + item: items, + }; +};