More avatar providers (#622)
Don't fail if the last avatar file does not exist when deleting it Fix lint Remove old global avatar setting and update docs Generate docs Invalidate the avatar cache when uploading a new one Add debug logs Add caching for upload avatars Add cache locks Fix encoding Resize the uploaded image to a max of 1024 pixels Remove the old uploaded avatar if one already exists Add mimetype check for images Set avatar provider to upload when uploading an avatar Add upload avatar provider Make font size smaller to let the initials still look good in smaller sizes Add debug log Add cache and resizing of initials avatars Make font size depend on avatar size Add drawing initials avatar Add initials provider Make the initials avatar provider the default Add routes Add user avatar settings handler methods Add user avatar provider field Co-authored-by: kolaente <k@knt.li> Reviewed-on: https://kolaente.dev/vikunja/api/pulls/622
This commit is contained in:
@ -366,3 +366,30 @@ func (err ErrInvalidTOTPPasscode) HTTPError() web.HTTPError {
|
||||
Message: "Invalid totp passcode.",
|
||||
}
|
||||
}
|
||||
|
||||
// ErrInvalidAvatarProvider represents a "InvalidAvatarProvider" kind of error.
|
||||
type ErrInvalidAvatarProvider struct {
|
||||
AvatarProvider string
|
||||
}
|
||||
|
||||
// IsErrInvalidAvatarProvider checks if an error is a ErrInvalidAvatarProvider.
|
||||
func IsErrInvalidAvatarProvider(err error) bool {
|
||||
_, ok := err.(ErrInvalidAvatarProvider)
|
||||
return ok
|
||||
}
|
||||
|
||||
func (err ErrInvalidAvatarProvider) Error() string {
|
||||
return "Invalid avatar provider"
|
||||
}
|
||||
|
||||
// ErrCodeInvalidAvatarProvider holds the unique world-error code of this error
|
||||
const ErrCodeInvalidAvatarProvider = 1018
|
||||
|
||||
// HTTPError holds the http error description
|
||||
func (err ErrInvalidAvatarProvider) HTTPError() web.HTTPError {
|
||||
return web.HTTPError{
|
||||
HTTPCode: http.StatusPreconditionFailed,
|
||||
Code: ErrCodeInvalidAvatarProvider,
|
||||
Message: "Invalid avatar provider setting. See docs for valid types.",
|
||||
}
|
||||
}
|
||||
|
@ -55,6 +55,9 @@ type User struct {
|
||||
PasswordResetToken string `xorm:"varchar(450) null" json:"-"`
|
||||
EmailConfirmToken string `xorm:"varchar(450) null" json:"-"`
|
||||
|
||||
AvatarProvider string `xorm:"varchar(255) null" json:"-"`
|
||||
AvatarFileID int64 `xorn:"null" json:"-"`
|
||||
|
||||
// A timestamp when this task was created. You cannot change this value.
|
||||
Created time.Time `xorm:"created not null" json:"created"`
|
||||
// A timestamp when this task was last updated. You cannot change this value.
|
||||
@ -269,6 +272,8 @@ func CreateUser(user *User) (newUser *User, err error) {
|
||||
newUser.EmailConfirmToken = utils.MakeRandomString(60)
|
||||
}
|
||||
|
||||
newUser.AvatarProvider = "initials"
|
||||
|
||||
// Insert it
|
||||
_, err = x.Insert(newUser)
|
||||
if err != nil {
|
||||
@ -323,6 +328,16 @@ func UpdateUser(user *User) (updatedUser *User, err error) {
|
||||
|
||||
user.Password = theUser.Password // set the password to the one in the database to not accedently resetting it
|
||||
|
||||
// Validate the avatar type
|
||||
if user.AvatarProvider != "" {
|
||||
if user.AvatarProvider != "default" &&
|
||||
user.AvatarProvider != "gravatar" &&
|
||||
user.AvatarProvider != "initials" &&
|
||||
user.AvatarProvider != "upload" {
|
||||
return updatedUser, &ErrInvalidAvatarProvider{AvatarProvider: user.AvatarProvider}
|
||||
}
|
||||
}
|
||||
|
||||
// Update it
|
||||
_, err = x.ID(user.ID).Update(user)
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user