From a9406ea936311c500cfdb814dbb7f23c08068ba0 Mon Sep 17 00:00:00 2001 From: Howard Yin <37261065+yindaheng98@users.noreply.github.com> Date: Fri, 25 Jun 2021 15:09:41 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20Bilibili=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E8=BF=BD=E6=BC=AB=E5=88=97=E8=A1=A8=20(#7758)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * bilibili追漫更新 * 文档更新 * 文档编译出错,更新 --- docs/social-media.md | 11 +++++++ lib/router.js | 1 + lib/routes/bilibili/manga_followings.js | 39 +++++++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 lib/routes/bilibili/manga_followings.js diff --git a/docs/social-media.md b/docs/social-media.md index 50c6b0fb28..8621b3c79f 100644 --- a/docs/social-media.md +++ b/docs/social-media.md @@ -302,6 +302,17 @@ Tiny Tiny RSS 会给所有 iframe 元素添加 `sandbox="allow-scripts"` 属性 +### 用户追漫更新 + + +::: warning 注意 + +用户追漫需要 b 站登录后的 Cookie 值,所以只能自建,详情见部署页面的配置模块。 + +::: + + + ## Dev.to ### 最高职位 diff --git a/lib/router.js b/lib/router.js index 9768f9b811..bae6256168 100644 --- a/lib/router.js +++ b/lib/router.js @@ -86,6 +86,7 @@ router.get('/bilibili/followings/article/:uid', require('./routes/bilibili/follo router.get('/bilibili/readlist/:listid', require('./routes/bilibili/readlist')); router.get('/bilibili/weekly', require('./routes/bilibili/weekly_recommend')); router.get('/bilibili/manga/update/:comicid', require('./routes/bilibili/manga_update')); +router.get('/bilibili/manga/followings/:uid/:limits?', require('./routes/bilibili/manga_followings')); router.get('/bilibili/app/:id?', require('./routes/bilibili/app')); // bangumi diff --git a/lib/routes/bilibili/manga_followings.js b/lib/routes/bilibili/manga_followings.js new file mode 100644 index 0000000000..4727b6b5fd --- /dev/null +++ b/lib/routes/bilibili/manga_followings.js @@ -0,0 +1,39 @@ +const got = require('@/utils/got'); +const cache = require('./cache'); +const config = require('@/config').value; + +module.exports = async (ctx) => { + const uid = String(ctx.params.uid); + const name = await cache.getUsernameFromUID(ctx, uid); + + const cookie = config.bilibili.cookies[uid]; + if (cookie === undefined) { + throw Error('缺少对应 uid 的 Bilibili 用户登录后的 Cookie 值'); + } + const page_size = ctx.params.limits || 10; + const link = 'https://manga.bilibili.com/account-center'; + const response = await got({ + method: 'POST', + url: `https://manga.bilibili.com/twirp/bookshelf.v1.Bookshelf/ListFavorite?device=pc&platform=web`, + json: { page_num: 1, page_size: page_size, order: 2, wait_free: 0 }, + headers: { + Referer: link, + Cookie: cookie, + }, + }); + if (response.data.code === -6) { + throw Error('对应 uid 的 Bilibili 用户的 Cookie 已过期'); + } + const comics = response.data.data; + + ctx.state.data = { + title: `${name} 的追漫更新 - 哔哩哔哩漫画`, + link: link, + item: comics.map((item) => ({ + title: `${item.title} ${item.latest_ep_short_title}`, + description: ``, + pubDate: new Date(item.last_ep_publish_time + ' +0800'), + link: `https://manga.bilibili.com/detail/mc${item.comic_id}`, + })), + }; +};