You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
917 B

  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package user
  5. import (
  6. "strconv"
  7. "code.gitea.io/gitea/models"
  8. "code.gitea.io/gitea/modules/context"
  9. "code.gitea.io/gitea/modules/log"
  10. )
  11. // Avatar redirect browser to user avatar of requested size
  12. func Avatar(ctx *context.Context) {
  13. userName := ctx.Params(":username")
  14. size, err := strconv.Atoi(ctx.Params(":size"))
  15. if err != nil {
  16. ctx.ServerError("Invalid avatar size", err)
  17. return
  18. }
  19. log.Debug("Asked avatar for user %v and size %v", userName, size)
  20. user, err := models.GetUserByName(userName)
  21. if err != nil {
  22. if models.IsErrUserNotExist(err) {
  23. ctx.ServerError("Requested avatar for invalid user", err)
  24. } else {
  25. ctx.ServerError("Retrieving user by name", err)
  26. }
  27. return
  28. }
  29. ctx.Redirect(user.RealSizedAvatarLink(size))
  30. }