This is an automated email from the ASF dual-hosted git repository.
linkinstar pushed a commit to branch test
in repository https://gitbox.apache.org/repos/asf/answer.git
The following commit(s) were added to refs/heads/test by this push:
new 4fd96675 fix: improve Brotli compression handling and validate user
input in vote status
4fd96675 is described below
commit 4fd96675f356de5932948c40f658e47370b80394
Author: LinkinStars <[email protected]>
AuthorDate: Wed Jan 28 12:11:28 2026 +0800
fix: improve Brotli compression handling and validate user input in vote
status
---
internal/base/server/http.go | 8 +++++++-
internal/repo/activity_common/vote.go | 6 ++++++
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/internal/base/server/http.go b/internal/base/server/http.go
index 512f3da2..050e3192 100644
--- a/internal/base/server/http.go
+++ b/internal/base/server/http.go
@@ -23,6 +23,7 @@ import (
"html/template"
"io/fs"
"os"
+ "strings"
brotli "github.com/anargu/gin-brotli"
"github.com/apache/answer/internal/base/middleware"
@@ -51,7 +52,12 @@ func NewHTTPServer(debug bool,
gin.SetMode(gin.ReleaseMode)
}
r := gin.New()
- r.Use(brotli.Brotli(brotli.DefaultCompression),
middleware.ExtractAndSetAcceptLanguage, shortIDMiddleware.SetShortIDFlag())
+ r.Use(func(ctx *gin.Context) {
+ if strings.Contains(ctx.Request.URL.Path, "/chat/completions") {
+ return
+ }
+ brotli.Brotli(brotli.DefaultCompression)(ctx)
+ }, middleware.ExtractAndSetAcceptLanguage,
shortIDMiddleware.SetShortIDFlag())
r.GET("/healthz", func(ctx *gin.Context) { ctx.String(200, "OK") })
templatePath := os.Getenv("ANSWER_TEMPLATE_PATH")
diff --git a/internal/repo/activity_common/vote.go
b/internal/repo/activity_common/vote.go
index 50657842..8ec83423 100644
--- a/internal/repo/activity_common/vote.go
+++ b/internal/repo/activity_common/vote.go
@@ -47,7 +47,13 @@ func NewVoteRepo(data *data.Data, activityRepo
activity_common.ActivityRepo) act
}
func (vr *VoteRepo) GetVoteStatus(ctx context.Context, objectID, userID
string) (status string) {
+ if len(userID) == 0 {
+ return ""
+ }
objectID = uid.DeShortID(objectID)
+ if len(objectID) == 0 || objectID == "0" {
+ return ""
+ }
for _, action := range []string{"vote_up", "vote_down"} {
activityType, _, _, err :=
vr.activityRepo.GetActivityTypeByObjID(ctx, objectID, action)
if err != nil {