fix: delete current avatar when setting new avatar (fixes #33)

This commit is contained in:
Sam 2023-03-23 10:07:51 +01:00
parent da67d12b60
commit 9813e1795e
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
2 changed files with 16 additions and 0 deletions

View file

@ -190,6 +190,14 @@ func (s *Server) patchMember(w http.ResponseWriter, r *http.Request) error {
return err return err
} }
avatarHash = &hash avatarHash = &hash
// delete current avatar if member has one
if m.Avatar != nil {
err = s.DB.DeleteMemberAvatar(ctx, claims.UserID, *m.Avatar)
if err != nil {
log.Errorf("deleting existing avatar: %v", err)
}
}
} }
} }

View file

@ -137,6 +137,14 @@ func (s *Server) patchUser(w http.ResponseWriter, r *http.Request) error {
return err return err
} }
avatarHash = &hash avatarHash = &hash
// delete current avatar if user has one
if u.Avatar != nil {
err = s.DB.DeleteUserAvatar(ctx, claims.UserID, *u.Avatar)
if err != nil {
log.Errorf("deleting existing avatar: %v", err)
}
}
} }
} }