mirror of
https://github.com/go-gitea/gitea
synced 2025-07-09 20:17:21 +00:00
Avatar refactor, move avatar code from models
to models.avatars
, remove duplicated code (#17123)
Why this refactor The goal is to move most files from `models` package to `models.xxx` package. Many models depend on avatar model, so just move this first. And the existing logic is not clear, there are too many function like `AvatarLink`, `RelAvatarLink`, `SizedRelAvatarLink`, `SizedAvatarLink`, `MakeFinalAvatarURL`, `HashedAvatarLink`, etc. This refactor make everything clear: * user.AvatarLink() * user.AvatarLinkWithSize(size) * avatars.GenerateEmailAvatarFastLink(email, size) * avatars.GenerateEmailAvatarFinalLink(email, size) And many duplicated code are deleted in route handler, the handler and the model share the same avatar logic now.
This commit is contained in:
@ -11,7 +11,6 @@ import (
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
@ -75,14 +74,8 @@ func TestUserAvatar(t *testing.T) {
|
||||
user2 = db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) // owner of the repo3, is an org
|
||||
|
||||
req = NewRequest(t, "GET", user2.AvatarLink())
|
||||
resp := session.MakeRequest(t, req, http.StatusFound)
|
||||
location := resp.Header().Get("Location")
|
||||
if !strings.HasPrefix(location, "/avatars") {
|
||||
assert.Fail(t, "Avatar location is not local: %s", location)
|
||||
}
|
||||
req = NewRequest(t, "GET", location)
|
||||
session.MakeRequest(t, req, http.StatusOK)
|
||||
_ = session.MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
// Can't test if the response matches because the image is regened on upload but checking that this at least doesn't give a 404 should be enough.
|
||||
// Can't test if the response matches because the image is re-generated on upload but checking that this at least doesn't give a 404 should be enough.
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user