aboutsummaryrefslogtreecommitdiffstats
path: root/models/user
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2024-05-07 16:26:13 +0800
committerGitHub <noreply@github.com>2024-05-07 08:26:13 +0000
commit67c1a07285008cc00036a87cef966c3bd519a50c (patch)
tree19d4ff344c4782596442a8c8de0a20142b0ca8ed /models/user
parentebf0c969403d91ed80745ff5bd7dfbdb08174fc7 (diff)
downloadgitea-67c1a07285008cc00036a87cef966c3bd519a50c.tar.gz
gitea-67c1a07285008cc00036a87cef966c3bd519a50c.zip
Refactor AppURL usage (#30885)
Fix #30883 Fix #29591 --------- Co-authored-by: KN4CK3R <admin@oldschoolhack.me>
Diffstat (limited to 'models/user')
-rw-r--r--models/user/avatar.go10
1 files changed, 3 insertions, 7 deletions
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