Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

fix: sensitive-words api colaKey error #121

Merged
merged 1 commit into from
Sep 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/interaction/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ func (s *InteractionServiceImpl) CommentAction(ctx context.Context, req *interac
return resp, nil
}

ok, err := commentService.MatchSensitiveWords(*req.CommentText)
fail, err := commentService.MatchSensitiveWords(*req.CommentText)
if err != nil {
resp.Base = pack.BuildBaseResp(errno.SensitiveWordsHTTPError)
return resp, nil
}
if ok {
if fail {
resp.Base = pack.BuildBaseResp(errno.SensitiveWordsError)
return resp, nil
}
Expand Down
14 changes: 10 additions & 4 deletions cmd/interaction/service/match_sensitive_words.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"io"
"net/http"

"github.com/cloudwego/kitex/pkg/klog"

"github.com/ozline/tiktok/cmd/interaction/dal/sensitive_words"
)

Expand All @@ -17,9 +19,9 @@ type ResponseBody struct {
}

func (s *InteractionService) MatchSensitiveWords(text string) (bool, error) {
ok := sensitive_words.St.Match(text)
if ok {
return ok, nil
fail := sensitive_words.St.Match(text)
if fail {
return fail, nil
}

requestBody := fmt.Sprintf(`{"ColaKey":"enB54tE5dI55Qv169215005005221MuejeU6z","wordStr": "%s","isStrict":"1"}`, text)
Expand All @@ -34,8 +36,12 @@ func (s *InteractionService) MatchSensitiveWords(text string) (bool, error) {

body, _ := io.ReadAll(resp.Body)
var res ResponseBody
if err = json.Unmarshal([]byte(string(body)), &res); err != nil {
if err = json.Unmarshal(body, &res); err != nil {
return false, err
}
if res.Code != 0 {
klog.Warnf("sensitive-words api error : %v", res.Msg)
return false, nil
}
return !res.IsPass, nil
}