Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make avatar lookup occur at image request #10540

Merged
merged 17 commits into from
Mar 27, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
make avatar lookup occur at image request
speed up page generation by making avatar lookup occur at the browser
not at page generation
  • Loading branch information
zeripath committed Feb 28, 2020
commit c185a233b1e23e108379ae8423212c5c1b3e2a9d
2 changes: 1 addition & 1 deletion modules/base/tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func SizedAvatarLink(email string, size int) string {
// which includes app sub-url as prefix. However, it is possible
// to return full URL if user enables Gravatar-like service.
func AvatarLink(email string) string {
return SizedAvatarLink(email, DefaultAvatarSize)
return setting.AppSubURL + "/avatar/" + url.PathEscape(email)
}

// FileSize calculates the file size and generate user-friendly string.
Expand Down
2 changes: 2 additions & 0 deletions routers/routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,8 @@ func RegisterRoutes(m *macaron.Macaron) {
})
// ***** END: User *****

m.Get("/avatar/:email", user.AvatarByEmail)

adminReq := context.Toggle(&context.ToggleOptions{SignInRequired: true, AdminRequired: true})

// ***** START: Admin *****
Expand Down
13 changes: 13 additions & 0 deletions routers/user/avatar.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/log"
)
Expand Down Expand Up @@ -41,3 +42,15 @@ func Avatar(ctx *context.Context) {

ctx.Redirect(user.RealSizedAvatarLink(size))
}

// AvatarByEmail redirects the browser to the appropriate Avatar link
func AvatarByEmail(ctx *context.Context) {
zeripath marked this conversation as resolved.
Show resolved Hide resolved
email := ctx.Params(":email")

size := ctx.QueryInt("size")
if size == 0 {
size = base.DefaultAvatarSize
}

ctx.Redirect(base.SizedAvatarLink(email, size))
}