@@ -6,7 +6,6 @@ package setting
6
6
7
7
import (
8
8
"net/url"
9
- "path/filepath"
10
9
11
10
"code.gitea.io/gitea/modules/log"
12
11
@@ -18,14 +17,11 @@ var (
18
17
// Picture settings
19
18
Avatar = struct {
20
19
Storage
20
+
21
21
MaxWidth int
22
22
MaxHeight int
23
23
MaxFileSize int64
24
24
}{
25
- Storage : Storage {
26
- Type : LocalStorageType ,
27
- ServeDirect : false ,
28
- },
29
25
MaxWidth : 4096 ,
30
26
MaxHeight : 3072 ,
31
27
MaxFileSize : 1048576 ,
@@ -39,43 +35,22 @@ var (
39
35
40
36
RepoAvatar = struct {
41
37
Storage
38
+
42
39
Fallback string
43
40
FallbackImage string
44
- }{
45
- Storage : Storage {
46
- Type : LocalStorageType ,
47
- ServeDirect : false ,
48
- },
49
- }
41
+ }{}
50
42
)
51
43
52
44
func newPictureService () {
53
45
sec := Cfg .Section ("picture" )
54
46
55
- Avatar .Storage .Type = sec .Key ("AVATAR_STORAGE_TYPE" ).MustString ("" )
56
- if Avatar .Storage .Type == "" {
57
- Avatar .Storage .Type = "default"
58
- }
59
-
60
- storage , ok := storages [Avatar .Storage .Type ]
61
- if ! ok {
62
- log .Fatal ("Failed to get avatar storage type: %s" , Avatar .Storage .Type )
63
- }
64
- Avatar .Storage = storage
47
+ avatarSec := Cfg .Section ("avatar" )
48
+ storageType := sec .Key ("AVATAR_STORAGE_TYPE" ).MustString ("" )
49
+ // Specifically default PATH to AVATAR_UPLOAD_PATH
50
+ avatarSec .Key ("PATH" ).MustString (
51
+ sec .Key ("AVATAR_UPLOAD_PATH" ).String ())
65
52
66
- switch Avatar .Storage .Type {
67
- case LocalStorageType :
68
- Avatar .Path = sec .Key ("AVATAR_UPLOAD_PATH" ).MustString (Avatar .Path )
69
- if Avatar .Path == "" {
70
- Avatar .Path = filepath .Join (AppDataPath , "avatars" )
71
- }
72
- forcePathSeparator (Avatar .Path )
73
- if ! filepath .IsAbs (Avatar .Path ) {
74
- Avatar .Path = filepath .Join (AppWorkPath , Avatar .Path )
75
- }
76
- case MinioStorageType :
77
- Avatar .Minio .BasePath = sec .Key ("AVATAR_UPLOAD_PATH" ).MustString ("avatars/" )
78
- }
53
+ Avatar .Storage = getStorage ("avatar" , storageType , avatarSec )
79
54
80
55
Avatar .MaxWidth = sec .Key ("AVATAR_MAX_WIDTH" ).MustInt (4096 )
81
56
Avatar .MaxHeight = sec .Key ("AVATAR_MAX_HEIGHT" ).MustInt (3072 )
@@ -126,27 +101,13 @@ func newPictureService() {
126
101
func newRepoAvatarService () {
127
102
sec := Cfg .Section ("picture" )
128
103
129
- RepoAvatar .Storage .Type = sec .Key ("REPOSITORY_AVATAR_STORAGE_TYPE" ).MustString ("" )
130
- if RepoAvatar .Storage .Type == "" {
131
- RepoAvatar .Storage .Type = "default"
132
- }
104
+ repoAvatarSec := Cfg .Section ("repo-avatar" )
105
+ storageType := sec .Key ("REPOSITORY_AVATAR_STORAGE_TYPE" ).MustString ("" )
106
+ // Specifically default PATH to AVATAR_UPLOAD_PATH
107
+ repoAvatarSec .Key ("PATH" ).MustString (
108
+ sec .Key ("REPOSITORY_AVATAR_UPLOAD_PATH" ).String ())
133
109
134
- storage , ok := storages [RepoAvatar .Storage .Type ]
135
- if ! ok {
136
- log .Fatal ("Failed to get repo-avatar storage type: %s" , RepoAvatar .Storage .Type )
137
- }
138
- RepoAvatar .Storage = storage
139
-
140
- switch RepoAvatar .Storage .Type {
141
- case LocalStorageType :
142
- RepoAvatar .Path = sec .Key ("REPOSITORY_AVATAR_UPLOAD_PATH" ).MustString (filepath .Join (AppDataPath , "repo-avatars" ))
143
- forcePathSeparator (RepoAvatar .Path )
144
- if ! filepath .IsAbs (RepoAvatar .Path ) {
145
- RepoAvatar .Path = filepath .Join (AppWorkPath , RepoAvatar .Path )
146
- }
147
- case MinioStorageType :
148
- RepoAvatar .Minio .BasePath = sec .Key ("REPOSITORY_AVATAR_MINIO_BASE_PATH" ).MustString ("repo-avatars/" )
149
- }
110
+ RepoAvatar .Storage = getStorage ("avatar" , storageType , repoAvatarSec )
150
111
151
112
RepoAvatar .Fallback = sec .Key ("REPOSITORY_AVATAR_FALLBACK" ).MustString ("none" )
152
113
RepoAvatar .FallbackImage = sec .Key ("REPOSITORY_AVATAR_FALLBACK_IMAGE" ).MustString ("/img/repo_default.png" )
0 commit comments