diff --git a/internal/schema/comment_schema.go b/internal/schema/comment_schema.go index 4f318d87..275e1b9a 100644 --- a/internal/schema/comment_schema.go +++ b/internal/schema/comment_schema.go @@ -38,6 +38,9 @@ type AddCommentReq struct { ParsedText string `json:"-"` // @ user id list MentionUsernameList []string `validate:"omitempty" json:"mention_username_list"` + CaptchaID string `json:"captcha_id"` + CaptchaCode string `json:"captcha_code"` + // user id UserID string `json:"-"` // whether user can add it @@ -45,9 +48,7 @@ type AddCommentReq struct { // whether user can edit it CanEdit bool `json:"-"` // whether user can delete it - CanDelete bool `json:"-"` - CaptchaID string `json:"captcha_id"` // captcha_id - CaptchaCode string `json:"captcha_code"` + CanDelete bool `json:"-"` } func (req *AddCommentReq) Check() (errFields []*validator.FormErrorField, err error) { @@ -61,7 +62,7 @@ type RemoveCommentReq struct { CommentID string `validate:"required" json:"comment_id"` // user id UserID string `json:"-"` - CaptchaID string `json:"captcha_id"` // captcha_id + CaptchaID string `json:"captcha_id"` CaptchaCode string `json:"captcha_code"` } diff --git a/internal/schema/search_schema.go b/internal/schema/search_schema.go index 59f32c5e..50aeaa6f 100644 --- a/internal/schema/search_schema.go +++ b/internal/schema/search_schema.go @@ -29,13 +29,13 @@ import ( ) type SearchDTO struct { - UserID string // UserID current login user ID - Query string `validate:"required,gte=1,lte=60" json:"q" form:"q"` // Query the query string - Page int `validate:"omitempty,min=1" form:"page,default=1" json:"page"` //Query number of pages - Size int `validate:"omitempty,min=1,max=50" form:"size,default=30" json:"size"` //Search page size - Order string `validate:"required,oneof=newest active score relevance" form:"order,default=relevance" json:"order" enums:"newest,active,score,relevance"` - CaptchaID string `json:"captcha_id"` // captcha_id - CaptchaCode string `json:"captcha_code"` + Query string `validate:"required,gte=1,lte=60" form:"q"` + Page int `validate:"omitempty,min=1" form:"page,default=1"` + Size int `validate:"omitempty,min=1,max=50" form:"size,default=30"` + Order string `validate:"required,oneof=newest active score relevance" form:"order,default=relevance" enums:"newest,active,score,relevance"` + CaptchaID string `form:"captcha_id"` + CaptchaCode string `form:"captcha_code"` + UserID string `json:"-"` } func (s *SearchDTO) Check() (errField []*validator.FormErrorField, err error) { diff --git a/internal/schema/user_schema.go b/internal/schema/user_schema.go index a95acfc7..016fd1eb 100644 --- a/internal/schema/user_schema.go +++ b/internal/schema/user_schema.go @@ -220,8 +220,8 @@ func (u *UserRegisterReq) Check() (errFields []*validator.FormErrorField, err er type UserModifyPasswordReq struct { OldPass string `validate:"omitempty,gte=8,lte=32" json:"old_pass"` Pass string `validate:"required,gte=8,lte=32" json:"pass"` - CaptchaID string `validate:"omitempty,gt=0,lte=500" json:"captcha_id"` - CaptchaCode string `validate:"omitempty,gt=0,lte=500" json:"captcha_code"` + CaptchaID string `json:"captcha_id"` + CaptchaCode string `json:"captcha_code"` UserID string `json:"-"` AccessToken string `json:"-"` } @@ -382,8 +382,8 @@ type UserChangeEmailVerifyReq struct { } type UserVerifyEmailSendReq struct { - CaptchaID string `validate:"omitempty,gt=0,lte=500" json:"captcha_id"` - CaptchaCode string `validate:"omitempty,gt=0,lte=500" json:"captcha_code"` + CaptchaID string `json:"captcha_id"` + CaptchaCode string `json:"captcha_code"` } // UserRankingResp user ranking response diff --git a/internal/schema/vote_schema.go b/internal/schema/vote_schema.go index f941e1e4..e82adcc2 100644 --- a/internal/schema/vote_schema.go +++ b/internal/schema/vote_schema.go @@ -20,11 +20,11 @@ package schema type VoteReq struct { - ObjectID string `validate:"required" form:"object_id" json:"object_id"` // id - IsCancel bool `validate:"omitempty" form:"is_cancel" json:"is_cancel"` // is cancel - UserID string `json:"-"` - CaptchaID string `json:"captcha_id"` // captcha_id + ObjectID string `validate:"required" json:"object_id"` + IsCancel bool `validate:"omitempty" json:"is_cancel"` + CaptchaID string `json:"captcha_id"` CaptchaCode string `json:"captcha_code"` + UserID string `json:"-"` } type VoteResp struct { diff --git a/plugin/plugin.go b/plugin/plugin.go index 1dd14cf6..6e491252 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -21,6 +21,7 @@ package plugin import ( "encoding/json" + "sync" "github.com/segmentfault/pacman/i18n" @@ -142,10 +143,13 @@ func MakePlugin[T Base](super bool) (CallFn[T], RegisterFn[T]) { } type statusManager struct { + lock sync.Mutex status map[string]bool } func (m *statusManager) Enable(name string, enabled bool) { + m.lock.Lock() + defer m.lock.Unlock() m.status[name] = enabled }