Skip to content

Commit

Permalink
feat: add AI and R18 filters (#107)
Browse files Browse the repository at this point in the history
Co-authored-by: Maiko Sinkyaet Tan <[email protected]>
  • Loading branch information
SaarChaffee and MaikoTan authored Oct 30, 2023
1 parent 123eb38 commit 856637a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
29 changes: 19 additions & 10 deletions packages/lolicon/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class LoliconImageSource extends ImageSource<LoliconImageSource.Config> {
r18: this.config.r18,
tag: query.tags,
num: query.count,
excludeAI: this.config.excludeAI,
proxy,
}
const resp = await this.ctx.http.post<Lolicon.Response>(this.config.endpoint, param)
Expand All @@ -28,16 +29,19 @@ class LoliconImageSource extends ImageSource<LoliconImageSource.Config> {
return
}

return resp.data.map((setu) => {
return {
url: setu.urls.original,
title: setu.title,
author: setu.author,
nsfw: setu.r18,
tags: setu.tags,
pageUrl: `https://pixiv.net/i/${setu.pid}`,
}
})
return resp.data
.filter((setu) => !(this.config.excludeAI && setu.aiType === 2))
.filter((setu) => !!this.config.r18 || !!this.config.r18 === setu.r18)
.map((setu) => {
return {
url: setu.urls.original,
title: setu.title,
author: setu.author,
nsfw: setu.r18,
tags: setu.tags,
pageUrl: `https://pixiv.net/i/${setu.pid}`,
}
})
}
}

Expand All @@ -46,6 +50,7 @@ namespace LoliconImageSource {
endpoint: string
r18: number
proxy: { endpoint: string } | string
excludeAI: boolean
}

export const Config: Schema<Config> = Schema.intersect([
Expand All @@ -65,6 +70,10 @@ namespace LoliconImageSource {
endpoint: Schema.string().required().description('反代服务的地址。'),
}).description('自定义'),
]).description('Pixiv 反代服务。').default('i.pixiv.re'),
excludeAI: Schema.union([
Schema.const(true).description('排除AI作品'),
Schema.const(false).description('不排除AI作品')
]).description('是否排除 AI 作品。').default(true)
}).description('搜索设置'),
])
}
Expand Down
14 changes: 14 additions & 0 deletions packages/pixiv/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class PixivImageSource extends ImageSource<PixivImageSource.Config> {

return data.illusts
.filter((illust) => illust.total_bookmarks > this.config.minBookmarks)
.filter((illust) => illust.x_restrict <= this.config.rank)
.filter((illust) => illust.illust_ai_type <= this.config.ai)
.slice(0, query.count)
.map((illust) => {
let url = ''
Expand Down Expand Up @@ -132,6 +134,8 @@ namespace PixivImageSource {
endpoint: string
token?: string
minBookmarks: number
rank: number
ai: number
proxy?: { endpoint: string } | string
}

Expand All @@ -150,6 +154,16 @@ namespace PixivImageSource {
endpoint: Schema.string().required().description('反代服务的地址。'),
}).description('自定义'),
]).description('Pixiv 反代服务。').default('https://i.pixiv.re'),
rank: Schema.union([
Schema.const(0).description('全年龄'),
Schema.const(1).description('R18'),
Schema.const(2).description('R18G')
]).description('年龄分级').default(0),
ai: Schema.union([
Schema.const(0).description('不允许AI作品'),
Schema.const(1).description('允许未知(旧画作或字段未更新)'),
Schema.const(2).description('允许AI作品')
]).description('是否允许搜索AI作品').default(0)
}).description('搜索设置'),
])
}
Expand Down

0 comments on commit 856637a

Please sign in to comment.