1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-08-01 17:38:37 +00:00

Refactor HTTP Client and LocalizedError packages

This commit is contained in:
Frédéric Guillot 2023-10-21 19:50:29 -07:00
parent 120aabfbce
commit 14e25ab9fe
104 changed files with 1277 additions and 10672 deletions

View file

@ -6,7 +6,7 @@ package form // import "miniflux.app/v2/internal/ui/form"
import (
"net/http"
"miniflux.app/v2/internal/errors"
"miniflux.app/v2/internal/locale"
)
// APIKeyForm represents the API Key form.
@ -15,9 +15,9 @@ type APIKeyForm struct {
}
// Validate makes sure the form values are valid.
func (a APIKeyForm) Validate() error {
func (a APIKeyForm) Validate() *locale.LocalizedError {
if a.Description == "" {
return errors.NewLocalizedError("error.fields_mandatory")
return locale.NewLocalizedError("error.fields_mandatory")
}
return nil

View file

@ -7,7 +7,7 @@ import (
"net/http"
"strings"
"miniflux.app/v2/internal/errors"
"miniflux.app/v2/internal/locale"
)
// AuthForm represents the authentication form.
@ -17,9 +17,9 @@ type AuthForm struct {
}
// Validate makes sure the form values are valid.
func (a AuthForm) Validate() error {
func (a AuthForm) Validate() *locale.LocalizedError {
if a.Username == "" || a.Password == "" {
return errors.NewLocalizedError("error.fields_mandatory")
return locale.NewLocalizedError("error.fields_mandatory")
}
return nil

View file

@ -7,7 +7,7 @@ import (
"net/http"
"strconv"
"miniflux.app/v2/internal/errors"
"miniflux.app/v2/internal/locale"
"miniflux.app/v2/internal/model"
)
@ -64,13 +64,13 @@ func (s *SettingsForm) Merge(user *model.User) *model.User {
}
// Validate makes sure the form values are valid.
func (s *SettingsForm) Validate() error {
func (s *SettingsForm) Validate() *locale.LocalizedError {
if s.Username == "" || s.Theme == "" || s.Language == "" || s.Timezone == "" || s.EntryDirection == "" || s.DisplayMode == "" || s.DefaultHomePage == "" {
return errors.NewLocalizedError("error.settings_mandatory_fields")
return locale.NewLocalizedError("error.settings_mandatory_fields")
}
if s.CJKReadingSpeed <= 0 || s.DefaultReadingSpeed <= 0 {
return errors.NewLocalizedError("error.settings_reading_speed_is_positive")
return locale.NewLocalizedError("error.settings_reading_speed_is_positive")
}
if s.Confirmation == "" {
@ -80,7 +80,7 @@ func (s *SettingsForm) Validate() error {
s.Password = ""
} else if s.Password != "" {
if s.Password != s.Confirmation {
return errors.NewLocalizedError("error.different_passwords")
return locale.NewLocalizedError("error.different_passwords")
}
}

View file

@ -7,7 +7,7 @@ import (
"net/http"
"strconv"
"miniflux.app/v2/internal/errors"
"miniflux.app/v2/internal/locale"
"miniflux.app/v2/internal/validator"
)
@ -29,26 +29,26 @@ type SubscriptionForm struct {
UrlRewriteRules string
}
// Validate makes sure the form values are valid.
func (s *SubscriptionForm) Validate() error {
// Validate makes sure the form values locale.are valid.
func (s *SubscriptionForm) Validate() *locale.LocalizedError {
if s.URL == "" || s.CategoryID == 0 {
return errors.NewLocalizedError("error.feed_mandatory_fields")
return locale.NewLocalizedError("error.feed_mandatory_fields")
}
if !validator.IsValidURL(s.URL) {
return errors.NewLocalizedError("error.invalid_feed_url")
return locale.NewLocalizedError("error.invalid_feed_url")
}
if !validator.IsValidRegex(s.BlocklistRules) {
return errors.NewLocalizedError("error.feed_invalid_blocklist_rule")
return locale.NewLocalizedError("error.feed_invalid_blocklist_rule")
}
if !validator.IsValidRegex(s.KeeplistRules) {
return errors.NewLocalizedError("error.feed_invalid_keeplist_rule")
return locale.NewLocalizedError("error.feed_invalid_keeplist_rule")
}
if !validator.IsValidRegex(s.UrlRewriteRules) {
return errors.NewLocalizedError("error.feed_invalid_urlrewrite_rule")
return locale.NewLocalizedError("error.feed_invalid_urlrewrite_rule")
}
return nil

View file

@ -6,7 +6,7 @@ package form // import "miniflux.app/v2/internal/ui/form"
import (
"net/http"
"miniflux.app/v2/internal/errors"
"miniflux.app/v2/internal/locale"
"miniflux.app/v2/internal/model"
)
@ -19,31 +19,31 @@ type UserForm struct {
}
// ValidateCreation validates user creation.
func (u UserForm) ValidateCreation() error {
func (u UserForm) ValidateCreation() *locale.LocalizedError {
if u.Username == "" || u.Password == "" || u.Confirmation == "" {
return errors.NewLocalizedError("error.fields_mandatory")
return locale.NewLocalizedError("error.fields_mandatory")
}
if u.Password != u.Confirmation {
return errors.NewLocalizedError("error.different_passwords")
return locale.NewLocalizedError("error.different_passwords")
}
return nil
}
// ValidateModification validates user modification.
func (u UserForm) ValidateModification() error {
func (u UserForm) ValidateModification() *locale.LocalizedError {
if u.Username == "" {
return errors.NewLocalizedError("error.user_mandatory_fields")
return locale.NewLocalizedError("error.user_mandatory_fields")
}
if u.Password != "" {
if u.Password != u.Confirmation {
return errors.NewLocalizedError("error.different_passwords")
return locale.NewLocalizedError("error.different_passwords")
}
if len(u.Password) < 6 {
return errors.NewLocalizedError("error.password_min_length")
return locale.NewLocalizedError("error.password_min_length")
}
}