Skip to content

Commit 919224b

Browse files
committed
Fix settings
1 parent 16ebe44 commit 919224b

File tree

3 files changed

+17
-58
lines changed

3 files changed

+17
-58
lines changed

models/unit_tests.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,8 @@ func MainTest(m *testing.M, pathToGiteaRoot string) {
7171

7272
setting.LFS.Storage.Path = filepath.Join(setting.AppDataPath, "lfs")
7373

74-
setting.Avatar.Storage.Type = setting.LocalStorageType
7574
setting.Avatar.Storage.Path = filepath.Join(setting.AppDataPath, "avatars")
7675

77-
setting.RepoAvatar.Storage.Type = setting.LocalStorageType
7876
setting.RepoAvatar.Storage.Path = filepath.Join(setting.AppDataPath, "repo-avatars")
7977

8078
if err = storage.Init(); err != nil {

modules/setting/picture.go

Lines changed: 15 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package setting
66

77
import (
88
"net/url"
9-
"path/filepath"
109

1110
"code.gitea.io/gitea/modules/log"
1211

@@ -18,14 +17,11 @@ var (
1817
// Picture settings
1918
Avatar = struct {
2019
Storage
20+
2121
MaxWidth int
2222
MaxHeight int
2323
MaxFileSize int64
2424
}{
25-
Storage: Storage{
26-
Type: LocalStorageType,
27-
ServeDirect: false,
28-
},
2925
MaxWidth: 4096,
3026
MaxHeight: 3072,
3127
MaxFileSize: 1048576,
@@ -39,43 +35,22 @@ var (
3935

4036
RepoAvatar = struct {
4137
Storage
38+
4239
Fallback string
4340
FallbackImage string
44-
}{
45-
Storage: Storage{
46-
Type: LocalStorageType,
47-
ServeDirect: false,
48-
},
49-
}
41+
}{}
5042
)
5143

5244
func newPictureService() {
5345
sec := Cfg.Section("picture")
5446

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())
6552

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)
7954

8055
Avatar.MaxWidth = sec.Key("AVATAR_MAX_WIDTH").MustInt(4096)
8156
Avatar.MaxHeight = sec.Key("AVATAR_MAX_HEIGHT").MustInt(3072)
@@ -126,27 +101,13 @@ func newPictureService() {
126101
func newRepoAvatarService() {
127102
sec := Cfg.Section("picture")
128103

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())
133109

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)
150111

151112
RepoAvatar.Fallback = sec.Key("REPOSITORY_AVATAR_FALLBACK").MustString("none")
152113
RepoAvatar.FallbackImage = sec.Key("REPOSITORY_AVATAR_FALLBACK_IMAGE").MustString("/img/repo_default.png")

modules/storage/storage.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func NewStorage(typStr string, cfg interface{}) (ObjectStorage, error) {
141141
}
142142

143143
func initAvatars() (err error) {
144-
Avatars, err = initStorage(setting.Avatar.Storage)
144+
Avatars, err = NewStorage(setting.Avatar.Storage.Type, setting.Avatar.Storage)
145145
return
146146
}
147147

@@ -156,6 +156,6 @@ func initLFS() (err error) {
156156
}
157157

158158
func initRepoAvatars() (err error) {
159-
RepoAvatars, err = initStorage(setting.RepoAvatar.Storage)
159+
RepoAvatars, err = NewStorage(setting.RepoAvatar.Storage.Type, setting.RepoAvatar.Storage)
160160
return
161161
}

0 commit comments

Comments
 (0)