summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
Diffstat (limited to 'models')
-rw-r--r--models/repo/avatar.go12
-rw-r--r--models/user/avatar.go10
2 files changed, 6 insertions, 16 deletions
diff --git a/models/repo/avatar.go b/models/repo/avatar.go
index 72ee938ada..8395b8c2b7 100644
--- a/models/repo/avatar.go
+++ b/models/repo/avatar.go
@@ -9,10 +9,10 @@ import (
"image/png"
"io"
"net/url"
- "strings"
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/avatar"
+ "code.gitea.io/gitea/modules/httplib"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/storage"
@@ -84,13 +84,7 @@ func (repo *Repository) relAvatarLink(ctx context.Context) string {
return setting.AppSubURL + "/repo-avatars/" + url.PathEscape(repo.Avatar)
}
-// AvatarLink returns a link to the repository's avatar.
+// AvatarLink returns the full avatar url with http host. TODO: refactor it to a relative URL, but it is still used in API response at the moment
func (repo *Repository) AvatarLink(ctx context.Context) string {
- link := repo.relAvatarLink(ctx)
- // we only prepend our AppURL to our known (relative, internal) avatar link to get an absolute URL
- if strings.HasPrefix(link, "/") && !strings.HasPrefix(link, "//") {
- return setting.AppURL + strings.TrimPrefix(link, setting.AppSubURL)[1:]
- }
- // otherwise, return the link as it is
- return link
+ return httplib.MakeAbsoluteURL(ctx, repo.relAvatarLink(ctx))
}
diff --git a/models/user/avatar.go b/models/user/avatar.go
index c6937d7b51..921bc1b1a1 100644
--- a/models/user/avatar.go
+++ b/models/user/avatar.go
@@ -9,11 +9,11 @@ import (
"fmt"
"image/png"
"io"
- "strings"
"code.gitea.io/gitea/models/avatars"
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/avatar"
+ "code.gitea.io/gitea/modules/httplib"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/storage"
@@ -89,13 +89,9 @@ func (u *User) AvatarLinkWithSize(ctx context.Context, size int) string {
return avatars.GenerateEmailAvatarFastLink(ctx, u.AvatarEmail, size)
}
-// AvatarLink returns the full avatar link with http host
+// AvatarLink returns the full avatar url with http host. TODO: refactor it to a relative URL, but it is still used in API response at the moment
func (u *User) AvatarLink(ctx context.Context) string {
- link := u.AvatarLinkWithSize(ctx, 0)
- if !strings.HasPrefix(link, "//") && !strings.Contains(link, "://") {
- return setting.AppURL + strings.TrimPrefix(link, setting.AppSubURL+"/")
- }
- return link
+ return httplib.MakeAbsoluteURL(ctx, u.AvatarLinkWithSize(ctx, 0))
}
// IsUploadAvatarChanged returns true if the current user's avatar would be changed with the provided data