feat: add pixiv illustfollows (#3073)

This commit is contained in:
Clarke
2019-09-15 12:52:29 +08:00
committed by DIYgod
parent 2a164517aa
commit a96171334f
5 changed files with 73 additions and 0 deletions
+6
View File
@@ -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': {
+10
View File
@@ -298,6 +298,16 @@ pageClass: routes
<Route author="DIYgod" example="/pixiv/search/麻衣/popular" path="/pixiv/search/:keyword/:order?" :paramsDesc="['关键词', '排序方式,popular 按热门度排序,空或其他任意值按时间排序']" radar="1"/>
### 关注的新作品
<Route author="ClarkeCheng" example="/pixiv/user/illustfollows" path="/pixiv/user/illustfollows" radar="1"/>
::: warning 注意
因为每个人关注的画师不同,所以只能自建。请不要将画师设为“悄悄关注”,这样子画师的作品就不会出现在订阅里了。
:::
</Route>
## Soul
### 瞬间更新
+1
View File
@@ -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'));
+21
View File
@@ -0,0 +1,21 @@
const got = require('@/utils/got');
const maskHeader = require('../constants').maskHeader;
/**
* 获取用户关注的画师们的最新插画
* @param {string} token pixiv oauth token
* @returns {Promise<got.AxiosResponse<{illusts: illust[]}>>}
*/
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',
},
});
};
+35
View File
@@ -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 <a href="https://docs.rsshub.app/install/#%E9%83%A8%E5%88%86-rss-%E6%A8%A1%E5%9D%97%E9%85%8D%E7%BD%AE">relevant config</a>';
}
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(`<p><img src="https://pixiv.cat/${illust.id}.jpg"/></p>`);
} else {
for (let i = 0; i < illust.page_count; i++) {
images.push(`<p><img src="https://pixiv.cat/${illust.id}-${i + 1}.jpg"/></p>`);
}
}
return {
title: illust.title,
author: illust.user.name,
pubDate: new Date(illust.create_date).toUTCString(),
description: `<p>画师:${illust.user.name} - 阅览数:${illust.total_view} - 收藏数:${illust.total_bookmarks}</p>${images.join('')}`,
link: `https://www.pixiv.net/member_illust.php?mode=medium&illust_id=${illust.id}`,
};
}),
};
};