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.

picture.go 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // Copyright 2020 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package setting
  4. // settings
  5. var (
  6. // Picture settings
  7. Avatar = struct {
  8. Storage
  9. MaxWidth int
  10. MaxHeight int
  11. MaxFileSize int64
  12. RenderedSizeFactor int
  13. }{
  14. MaxWidth: 4096,
  15. MaxHeight: 3072,
  16. MaxFileSize: 1048576,
  17. RenderedSizeFactor: 3,
  18. }
  19. GravatarSource string
  20. DisableGravatar bool // Depreciated: migrated to database
  21. EnableFederatedAvatar bool // Depreciated: migrated to database
  22. RepoAvatar = struct {
  23. Storage
  24. Fallback string
  25. FallbackImage string
  26. }{}
  27. )
  28. func newPictureService() {
  29. sec := Cfg.Section("picture")
  30. avatarSec := Cfg.Section("avatar")
  31. storageType := sec.Key("AVATAR_STORAGE_TYPE").MustString("")
  32. // Specifically default PATH to AVATAR_UPLOAD_PATH
  33. avatarSec.Key("PATH").MustString(
  34. sec.Key("AVATAR_UPLOAD_PATH").String())
  35. Avatar.Storage = getStorage("avatars", storageType, avatarSec)
  36. Avatar.MaxWidth = sec.Key("AVATAR_MAX_WIDTH").MustInt(4096)
  37. Avatar.MaxHeight = sec.Key("AVATAR_MAX_HEIGHT").MustInt(3072)
  38. Avatar.MaxFileSize = sec.Key("AVATAR_MAX_FILE_SIZE").MustInt64(1048576)
  39. Avatar.RenderedSizeFactor = sec.Key("AVATAR_RENDERED_SIZE_FACTOR").MustInt(3)
  40. switch source := sec.Key("GRAVATAR_SOURCE").MustString("gravatar"); source {
  41. case "duoshuo":
  42. GravatarSource = "http://gravatar.duoshuo.com/avatar/"
  43. case "gravatar":
  44. GravatarSource = "https://secure.gravatar.com/avatar/"
  45. case "libravatar":
  46. GravatarSource = "https://seccdn.libravatar.org/avatar/"
  47. default:
  48. GravatarSource = source
  49. }
  50. DisableGravatar = sec.Key("DISABLE_GRAVATAR").MustBool(GetDefaultDisableGravatar())
  51. deprecatedSettingDB("", "DISABLE_GRAVATAR")
  52. EnableFederatedAvatar = sec.Key("ENABLE_FEDERATED_AVATAR").MustBool(GetDefaultEnableFederatedAvatar(DisableGravatar))
  53. deprecatedSettingDB("", "ENABLE_FEDERATED_AVATAR")
  54. newRepoAvatarService()
  55. }
  56. func GetDefaultDisableGravatar() bool {
  57. return OfflineMode
  58. }
  59. func GetDefaultEnableFederatedAvatar(disableGravatar bool) bool {
  60. v := !InstallLock
  61. if OfflineMode {
  62. v = false
  63. }
  64. if disableGravatar {
  65. v = false
  66. }
  67. return v
  68. }
  69. func newRepoAvatarService() {
  70. sec := Cfg.Section("picture")
  71. repoAvatarSec := Cfg.Section("repo-avatar")
  72. storageType := sec.Key("REPOSITORY_AVATAR_STORAGE_TYPE").MustString("")
  73. // Specifically default PATH to AVATAR_UPLOAD_PATH
  74. repoAvatarSec.Key("PATH").MustString(
  75. sec.Key("REPOSITORY_AVATAR_UPLOAD_PATH").String())
  76. RepoAvatar.Storage = getStorage("repo-avatars", storageType, repoAvatarSec)
  77. RepoAvatar.Fallback = sec.Key("REPOSITORY_AVATAR_FALLBACK").MustString("none")
  78. RepoAvatar.FallbackImage = sec.Key("REPOSITORY_AVATAR_FALLBACK_IMAGE").MustString("/assets/img/repo_default.png")
  79. }