From e4bb7f943d2626640074082f5e6db7922ba8bd7c Mon Sep 17 00:00:00 2001 From: everpcpc Date: Mon, 25 Nov 2024 14:45:20 +0800 Subject: [PATCH] fix: filter nsfw on search (#663) --- internal/search/handle.go | 8 ++++---- internal/search/handle_internal_test.go | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/search/handle.go b/internal/search/handle.go index b5842d2f5..f3ef51f35 100644 --- a/internal/search/handle.go +++ b/internal/search/handle.go @@ -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) @@ -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} } @@ -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 { diff --git a/internal/search/handle_internal_test.go b/internal/search/handle_internal_test.go index 738f5009f..fb54defb2 100644 --- a/internal/search/handle_internal_test.go +++ b/internal/search/handle_internal_test.go @@ -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{