From a96171334f0229e86bc815e0935ce18084c3c265 Mon Sep 17 00:00:00 2001 From: Clarke Date: Sun, 15 Sep 2019 12:52:29 +0800 Subject: [PATCH] feat: add pixiv illustfollows (#3073) --- assets/radar-rules.js | 6 ++++ docs/social-media.md | 10 +++++++ lib/router.js | 1 + lib/routes/pixiv/api/getIllustFollows.js | 21 ++++++++++++++ lib/routes/pixiv/illustfollow.js | 35 ++++++++++++++++++++++++ 5 files changed, 73 insertions(+) create mode 100644 lib/routes/pixiv/api/getIllustFollows.js create mode 100644 lib/routes/pixiv/illustfollow.js diff --git a/assets/radar-rules.js b/assets/radar-rules.js index a311519ae4..27c1d42546 100644 --- a/assets/radar-rules.js +++ b/assets/radar-rules.js @@ -88,6 +88,12 @@ source: '/search.php', target: (params, url) => `/pixiv/user/bookmarks/${new URL(url).searchParams.get('id')}`, }, + { + title: '关注的新作品', + docs: 'https://docs.rsshub.app/social-media.html#pixiv', + source: '/bookmark_new_illust.php', + target: '/pixiv/user/illustfollows', + }, ], }, 'twitter.com': { diff --git a/docs/social-media.md b/docs/social-media.md index 67b5912175..cff5abd53c 100644 --- a/docs/social-media.md +++ b/docs/social-media.md @@ -298,6 +298,16 @@ pageClass: routes +### 关注的新作品 + + +::: warning 注意 + +因为每个人关注的画师不同,所以只能自建。请不要将画师设为“悄悄关注”,这样子画师的作品就不会出现在订阅里了。 + +::: + + ## Soul ### 瞬间更新 diff --git a/lib/router.js b/lib/router.js index 196f3dc1bc..fe818dd678 100644 --- a/lib/router.js +++ b/lib/router.js @@ -112,6 +112,7 @@ router.get('/mzitu/tag/:tag', require('./routes/mzitu/tag')); // pixiv router.get('/pixiv/user/bookmarks/:id', require('./routes/pixiv/bookmarks')); +router.get('/pixiv/user/illustfollows', require('./routes/pixiv/illustfollow')); router.get('/pixiv/user/:id/', require('./routes/pixiv/user')); router.get('/pixiv/ranking/:mode/:date?', require('./routes/pixiv/ranking')); router.get('/pixiv/search/:keyword/:order?', require('./routes/pixiv/search')); diff --git a/lib/routes/pixiv/api/getIllustFollows.js b/lib/routes/pixiv/api/getIllustFollows.js new file mode 100644 index 0000000000..f857fe3feb --- /dev/null +++ b/lib/routes/pixiv/api/getIllustFollows.js @@ -0,0 +1,21 @@ +const got = require('@/utils/got'); +const maskHeader = require('../constants').maskHeader; + +/** + * 获取用户关注的画师们的最新插画 + * @param {string} token pixiv oauth token + * @returns {Promise>} + */ +module.exports = async function getUserIllustFollows(token) { + return await got({ + method: 'get', + url: 'https://app-api.pixiv.net/v2/illust/follow', + headers: { + ...maskHeader, + Authorization: 'Bearer ' + token, + }, + params: { + restrict: 'public', + }, + }); +}; diff --git a/lib/routes/pixiv/illustfollow.js b/lib/routes/pixiv/illustfollow.js new file mode 100644 index 0000000000..527dc14ae3 --- /dev/null +++ b/lib/routes/pixiv/illustfollow.js @@ -0,0 +1,35 @@ +const getToken = require('./token'); +const getIllustFollows = require('./api/getIllustFollows'); +const config = require('@/config'); +module.exports = async (ctx) => { + if (!config.pixiv || !config.pixiv.username || !config.pixiv.password) { + throw 'pixiv RSS is disabled due to the lack of relevant config'; + } + if (!getToken()) { + throw 'pixiv not login'; + } + const response = await getIllustFollows(getToken()); + const illusts = response.data.illusts; + ctx.state.data = { + title: `Pixiv关注的新作品`, + link: 'https://www.pixiv.net/bookmark_new_illust.php', + description: `Pixiv关注的画师们的最新作品`, + item: illusts.map((illust) => { + const images = []; + if (illust.page_count === 1) { + images.push(`

`); + } else { + for (let i = 0; i < illust.page_count; i++) { + images.push(`

`); + } + } + return { + title: illust.title, + author: illust.user.name, + pubDate: new Date(illust.create_date).toUTCString(), + description: `

画师:${illust.user.name} - 阅览数:${illust.total_view} - 收藏数:${illust.total_bookmarks}

${images.join('')}`, + link: `https://www.pixiv.net/member_illust.php?mode=medium&illust_id=${illust.id}`, + }; + }), + }; +};