forked from forgejo/forgejo
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:
parent
48c2578bd8
commit
f0ba87fda8
15 changed files with 274 additions and 300 deletions
|
@ -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.
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue