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(user): convert user bio markdown
LinkinStar020262f66243
diff --git a/internal/schema/user_schema.go b/internal/schema/user_schema.goindex 9b449b80..52449664 100644--- a/internal/schema/user_schema.go+++ b/internal/schema/user_schema.go@@ -8,6 +8,7 @@ import ("github.com/answerdev/answer/internal/base/validator""github.com/answerdev/answer/internal/entity""github.com/answerdev/answer/pkg/checker"+ "github.com/answerdev/answer/pkg/converter""github.com/jinzhu/copier""github.com/segmentfault/pacman/errors")@@ -283,7 +284,7 @@ type UpdateInfoRequest struct {// bioBio string `validate:"omitempty,gt=0,lte=4096" json:"bio"`// bio- BioHTML string `validate:"omitempty,gt=0,lte=4096" json:"bio_html"`+ BioHTML string `json:"-"`// websiteWebsite string `validate:"omitempty,gt=0,lte=500" json:"website"`// location@@ -298,11 +299,11 @@ type AvatarInfo struct {Custom string `validate:"omitempty,gt=0,lte=200" json:"custom"`}-func (u *UpdateInfoRequest) Check() (errFields []*validator.FormErrorField, err error) {- if len(u.Username) > 0 {+func (req *UpdateInfoRequest) Check() (errFields []*validator.FormErrorField, err error) {+ if len(req.Username) > 0 {errFields := make([]*validator.FormErrorField, 0)re := regexp.MustCompile(`^[a-z0-9._-]{4,30}$`)- match := re.MatchString(u.Username)+ match := re.MatchString(req.Username)if !match {errField := &validator.FormErrorField{ErrorField: "username",@@ -312,6 +313,7 @@ func (u *UpdateInfoRequest) Check() (errFields []*validator.FormErrorField, errreturn errFields, errors.BadRequest(reason.UsernameInvalid)}}+ req.BioHTML = converter.Markdown2HTML(req.Bio)return nil, nil}diff --git a/internal/service/user_service.go b/internal/service/user_service.goindex 306fea13..e7bd4374 100644--- a/internal/service/user_service.go+++ b/internal/service/user_service.go@@ -22,7 +22,6 @@ import (usercommon "github.com/answerdev/answer/internal/service/user_common""github.com/answerdev/answer/pkg/checker""github.com/google/uuid"- "github.com/microcosm-cc/bluemonday""github.com/segmentfault/pacman/errors""github.com/segmentfault/pacman/log""golang.org/x/crypto/bcrypt"@@ -268,17 +267,12 @@ func (us *UserService) UpdateInfo(ctx context.Context, req *schema.UpdateInfoReqif err != nil {return nil, errors.BadRequest(reason.UserSetAvatar).WithError(err).WithStack()}- xss := bluemonday.UGCPolicy()- bio := xss.Sanitize(- req.BioHTML,- )-userInfo := entity.User{}userInfo.ID = req.UserIDuserInfo.Avatar = string(avatar)userInfo.DisplayName = req.DisplayNameuserInfo.Bio = req.Bio- userInfo.BioHTML = bio+ userInfo.BioHTML = req.BioHTMLuserInfo.Location = req.LocationuserInfo.Website = req.WebsiteuserInfo.Username = req.Username