From af87d8f304d11611ee64fb51b2c566b89167b6ea Mon Sep 17 00:00:00 2001 From: Trim21 Date: Sun, 30 Jun 2024 22:49:27 +0800 Subject: [PATCH] fix(search): nsfw response --- internal/search/handle.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/internal/search/handle.go b/internal/search/handle.go index d4af8e959..02d929745 100644 --- a/internal/search/handle.go +++ b/internal/search/handle.go @@ -110,15 +110,19 @@ func (c *client) Handle(ctx echo.Context) error { } ids := slice.Map(hits, func(h hit) model.SubjectID { return h.ID }) - subjects, err := c.subjectRepo.GetByIDs(ctx.Request().Context(), ids, subject.Filter{NSFW: r.Filter.NSFW}) + subjects, err := c.subjectRepo.GetByIDs(ctx.Request().Context(), ids, subject.Filter{}) if err != nil { return errgo.Wrap(err, "subjectRepo.GetByIDs") } - data := slice.Map(ids, func(id model.SubjectID) ReponseSubject { - s := subjects[id] + var data = make([]ReponseSubject, 0, len(subjects)) + for _, id := range ids { + s, ok := subjects[id] + if !ok { + continue + } - return ReponseSubject{ + data = append(data, ReponseSubject{ Date: s.Date, Image: res.SubjectImage(s.Image).Large, Type: s.TypeID, @@ -131,8 +135,9 @@ func (c *client) Handle(ctx echo.Context) error { Score: s.Rating.Score, ID: s.ID, Rank: s.Rating.Rank, - } - }) + }) + + } return ctx.JSON(http.StatusOK, res.Paged{ Data: data,