From 61e2ef53a996dd579b5019151f09e53e6b856584 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Tue, 24 Nov 2020 20:11:28 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E6=9C=89=E9=81=93=E4=BA=91?= =?UTF-8?q?=E7=AC=94=E8=AE=B0=E5=AD=A6=E9=9C=B8=E6=84=9F=E6=82=9F=20&=20?= =?UTF-8?q?=E7=AC=94=E8=AE=B0=E6=9C=80=E6=96=B0=E5=8A=A8=E6=80=81=20(#6208?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/study.md | 10 ++++++ lib/router.js | 4 +++ lib/routes/youdao/latest.js | 48 +++++++++++++++++++++++++++ lib/routes/youdao/xueba.js | 65 +++++++++++++++++++++++++++++++++++++ 4 files changed, 127 insertions(+) create mode 100644 lib/routes/youdao/latest.js create mode 100644 lib/routes/youdao/xueba.js 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, + }; +};