feat: pixiv search r18, close #1333, close #2932, close #3447

This commit is contained in:
DIYgod
2019-11-29 17:41:50 +08:00
parent c0c27a9ed3
commit 5a2a37f3e1
4 changed files with 14 additions and 3 deletions

View File

@@ -44,6 +44,10 @@ pageClass: routes
</RouteEn> </RouteEn>
### Keyword
<Route author="DIYgod" example="/pixiv/search/麻衣/popular/2" path="/pixiv/search/:keyword/:order?/:r18?" :paramsDesc="['keyword', 'rank mode, empty or other for time order, popular for popular order', 'filte R18 content, 0 to no filter, 1 to only not R18, 2 to only R18, default to 0']" radar="1"/>
## Telegram ## Telegram
### Channel ### Channel

View File

@@ -322,7 +322,7 @@ Tiny Tiny RSS 会给所有 iframe 元素添加 `sandbox="allow-scripts"` 属性
### 关键词 ### 关键词
<Route author="DIYgod" example="/pixiv/search/麻衣/popular" path="/pixiv/search/:keyword/:order?" :paramsDesc="['关键词', '排序方式popular 按热门度排序,空或其他任意值按时间排序']" radar="1"/> <Route author="DIYgod" example="/pixiv/search/麻衣/popular/2" path="/pixiv/search/:keyword/:order?/:r18?" :paramsDesc="['关键词', '排序方式popular 按热门度排序,空或其他任意值按时间排序', '过滤 R18 内容0 为不过滤1 为只看非 R18 内容2 为只看 R18 内容,默认为 0']" radar="1"/>
### 关注的新作品 ### 关注的新作品

View File

@@ -142,7 +142,7 @@ router.get('/pixiv/user/bookmarks/:id', require('./routes/pixiv/bookmarks'));
router.get('/pixiv/user/illustfollows', require('./routes/pixiv/illustfollow')); router.get('/pixiv/user/illustfollows', require('./routes/pixiv/illustfollow'));
router.get('/pixiv/user/:id/', require('./routes/pixiv/user')); router.get('/pixiv/user/:id/', require('./routes/pixiv/user'));
router.get('/pixiv/ranking/:mode/:date?', require('./routes/pixiv/ranking')); router.get('/pixiv/ranking/:mode/:date?', require('./routes/pixiv/ranking'));
router.get('/pixiv/search/:keyword/:order?', require('./routes/pixiv/search')); router.get('/pixiv/search/:keyword/:order?/:r18?', require('./routes/pixiv/search'));
// 豆瓣 // 豆瓣
router.get('/douban/movie/playing', require('./routes/douban/playing')); router.get('/douban/movie/playing', require('./routes/douban/playing'));

View File

@@ -10,6 +10,7 @@ module.exports = async (ctx) => {
const keyword = ctx.params.keyword; const keyword = ctx.params.keyword;
const order = ctx.params.order || 'date'; const order = ctx.params.order || 'date';
const r18 = ctx.params.r18;
if (!getToken()) { if (!getToken()) {
throw 'pixiv not login'; throw 'pixiv not login';
@@ -22,7 +23,12 @@ module.exports = async (ctx) => {
response = await searchIllust(keyword, getToken()); response = await searchIllust(keyword, getToken());
} }
const illusts = response.data.illusts; let illusts = response.data.illusts;
if (r18 === '1') {
illusts = illusts.filter((item) => item.x_restrict === 0);
} else if (r18 === '2') {
illusts = illusts.filter((item) => item.x_restrict === 1);
}
ctx.state.data = { ctx.state.data = {
title: `${keyword} 的 pixiv ${order === 'popular' ? '热门' : ''}内容`, title: `${keyword} 的 pixiv ${order === 'popular' ? '热门' : ''}内容`,
@@ -44,5 +50,6 @@ module.exports = async (ctx) => {
link: `https://www.pixiv.net/member_illust.php?mode=medium&illust_id=${illust.id}`, link: `https://www.pixiv.net/member_illust.php?mode=medium&illust_id=${illust.id}`,
}; };
}), }),
allowEmpty: true,
}; };
}; };