Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

fix: improve Brotli compression handling and validate user input in vote status

LinkinStars4fd96675f356
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 {