Skip to content

Commit

Permalink
fix: filter nsfw on search (#663)
Browse files Browse the repository at this point in the history
  • Loading branch information
everpcpc authored Nov 25, 2024
1 parent 6ad9900 commit e4bb7f9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions internal/search/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (c *client) Handle(ctx echo.Context) error {
}

if !auth.AllowNSFW() {
r.Filter.NSFW.Set = false
r.Filter.NSFW = null.Bool{Set: true, Value: false}
}

result, err := c.doSearch(r.Keyword, filterToMeiliFilter(r.Filter), r.Sort, q.Limit, q.Offset)
Expand All @@ -119,7 +119,7 @@ func (c *client) Handle(ctx echo.Context) error {

var sf = subject.Filter{}

if !r.Filter.NSFW.Set || !r.Filter.NSFW.Value {
if r.Filter.NSFW.Set && !r.Filter.NSFW.Value {
sf.NSFW = null.Bool{Set: true, Value: false}
}

Expand Down Expand Up @@ -223,8 +223,8 @@ func filterToMeiliFilter(req ReqFilter) [][]string {
}))
}

if !req.NSFW.Set || !req.NSFW.Value {
filter = append(filter, []string{"nsfw = false"})
if req.NSFW.Set {
filter = append(filter, []string{fmt.Sprintf("nsfw = %t", req.NSFW.Value)})
}

for _, tag := range req.MetaTags {
Expand Down
2 changes: 1 addition & 1 deletion internal/search/handle_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func Test_ReqFilterToMeiliFilter(t *testing.T) {

actual := filterToMeiliFilter(ReqFilter{
Tag: []string{"a", "b"},
NSFW: null.Bool{Set: false},
NSFW: null.Bool{Set: true, Value: false},
})

require.Equal(t, [][]string{
Expand Down

0 comments on commit e4bb7f9

Please sign in to comment.