Skip to content

Commit 4fd9667

Browse files
committed
fix: improve Brotli compression handling and validate user input in vote status
1 parent a5edc4f commit 4fd9667

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

internal/base/server/http.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"html/template"
2424
"io/fs"
2525
"os"
26+
"strings"
2627

2728
brotli "github.com/anargu/gin-brotli"
2829
"github.com/apache/answer/internal/base/middleware"
@@ -51,7 +52,12 @@ func NewHTTPServer(debug bool,
5152
gin.SetMode(gin.ReleaseMode)
5253
}
5354
r := gin.New()
54-
r.Use(brotli.Brotli(brotli.DefaultCompression), middleware.ExtractAndSetAcceptLanguage, shortIDMiddleware.SetShortIDFlag())
55+
r.Use(func(ctx *gin.Context) {
56+
if strings.Contains(ctx.Request.URL.Path, "/chat/completions") {
57+
return
58+
}
59+
brotli.Brotli(brotli.DefaultCompression)(ctx)
60+
}, middleware.ExtractAndSetAcceptLanguage, shortIDMiddleware.SetShortIDFlag())
5561
r.GET("/healthz", func(ctx *gin.Context) { ctx.String(200, "OK") })
5662

5763
templatePath := os.Getenv("ANSWER_TEMPLATE_PATH")

internal/repo/activity_common/vote.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,13 @@ func NewVoteRepo(data *data.Data, activityRepo activity_common.ActivityRepo) act
4747
}
4848

4949
func (vr *VoteRepo) GetVoteStatus(ctx context.Context, objectID, userID string) (status string) {
50+
if len(userID) == 0 {
51+
return ""
52+
}
5053
objectID = uid.DeShortID(objectID)
54+
if len(objectID) == 0 || objectID == "0" {
55+
return ""
56+
}
5157
for _, action := range []string{"vote_up", "vote_down"} {
5258
activityType, _, _, err := vr.activityRepo.GetActivityTypeByObjID(ctx, objectID, action)
5359
if err != nil {

0 commit comments

Comments
 (0)