Skip to content

Commit

Permalink
feat: pixiv search r18, close #1333, close #2932, close #3447
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed Nov 29, 2019
1 parent c0c27a9 commit 5a2a37f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
4 changes: 4 additions & 0 deletions docs/en/social-media.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ pageClass: routes

</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

### Channel
Expand Down
2 changes: 1 addition & 1 deletion docs/social-media.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>

### 关注的新作品

Expand Down
2 changes: 1 addition & 1 deletion lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/: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'));
router.get('/pixiv/search/:keyword/:order?/:r18?', require('./routes/pixiv/search'));

// 豆瓣
router.get('/douban/movie/playing', require('./routes/douban/playing'));
Expand Down
9 changes: 8 additions & 1 deletion lib/routes/pixiv/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = async (ctx) => {

const keyword = ctx.params.keyword;
const order = ctx.params.order || 'date';
const r18 = ctx.params.r18;

if (!getToken()) {
throw 'pixiv not login';
Expand All @@ -22,7 +23,12 @@ module.exports = async (ctx) => {
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 = {
title: `${keyword} 的 pixiv ${order === 'popular' ? '热门' : ''}内容`,
Expand All @@ -44,5 +50,6 @@ module.exports = async (ctx) => {
link: `https://www.pixiv.net/member_illust.php?mode=medium&illust_id=${illust.id}`,
};
}),
allowEmpty: true,
};
};

0 comments on commit 5a2a37f

Please sign in to comment.