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.
update captcha
aichyded980b6764e
diff --git a/internal/repo/captcha/captcha.go b/internal/repo/captcha/captcha.goindex 02e8ab8a..bda41d1e 100644--- a/internal/repo/captcha/captcha.go+++ b/internal/repo/captcha/captcha.go@@ -25,7 +25,7 @@ func NewCaptchaRepo(data *data.Data) action.CaptchaRepo {}func (cr *captchaRepo) SetActionType(ctx context.Context, ip, actionType string, amount int) (err error) {- cacheKey := fmt.Sprintf("ActionRecord:%s@%s", ip, actionType)+ cacheKey := fmt.Sprintf("ActionRecord:%s@", ip)err = cr.data.Cache.SetInt64(ctx, cacheKey, int64(amount), 6*time.Minute)if err != nil {err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()@@ -34,19 +34,16 @@ func (cr *captchaRepo) SetActionType(ctx context.Context, ip, actionType string,}func (cr *captchaRepo) GetActionType(ctx context.Context, ip, actionType string) (amount int, err error) {- //cacheKey := fmt.Sprintf("ActionRecord:%s@%s", ip, actionType)- //Detects behavior based on ip onlycacheKey := fmt.Sprintf("ActionRecord:%s@", ip)res, err := cr.data.Cache.GetInt64(ctx, cacheKey)if err != nil {err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()}- // TODO: cache reflect should return empty when key not foundreturn int(res), nil}func (cr *captchaRepo) DelActionType(ctx context.Context, ip, actionType string) (err error) {- cacheKey := fmt.Sprintf("ActionRecord:%s@%s", ip, actionType)+ cacheKey := fmt.Sprintf("ActionRecord:%s@", ip)err = cr.data.Cache.Del(ctx, cacheKey)if err != nil {err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()@@ -56,7 +53,6 @@ func (cr *captchaRepo) DelActionType(ctx context.Context, ip, actionType string)// SetCaptcha set captcha to cachefunc (cr *captchaRepo) SetCaptcha(ctx context.Context, key, captcha string) (err error) {- // TODO make cache time to configerr = cr.data.Cache.SetString(ctx, key, captcha, 6*time.Minute)if err != nil {err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()@@ -70,6 +66,5 @@ func (cr *captchaRepo) GetCaptcha(ctx context.Context, key string) (captcha striif err != nil {log.Debug(err)}- // TODO: cache reflect should return empty when key not foundreturn captcha, nil}