summaryrefslogtreecommitdiffstats
path: root/modules/storage/storage.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2020-10-14 21:07:51 +0800
committerGitHub <noreply@github.com>2020-10-14 21:07:51 +0800
commit80a6b0f5bce15a641fc75f5f1ef6e42ef54424bc (patch)
tree504c7ccdc9cb42e0e282abdd8dbb75c4b24e9f5b /modules/storage/storage.go
parent93f7525061bc9e6f5be734aba0de31b64c63d7a8 (diff)
downloadgitea-80a6b0f5bce15a641fc75f5f1ef6e42ef54424bc.tar.gz
gitea-80a6b0f5bce15a641fc75f5f1ef6e42ef54424bc.zip
Avatars and Repo avatars support storing in minio (#12516)
* Avatar support minio * Support repo avatar minio storage * Add missing migration * Fix bug * Fix test * Add test for minio store type on avatars and repo avatars; Add documents * Fix bug * Fix bug * Add back missed avatar link method * refactor codes * Simplify the codes * Code improvements * Fix lint * Fix test mysql * Fix test mysql * Fix test mysql * Fix settings * Fix test * fix test * Fix bug
Diffstat (limited to 'modules/storage/storage.go')
-rw-r--r--modules/storage/storage.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/modules/storage/storage.go b/modules/storage/storage.go
index 8b1c336ae6..1fa04119c7 100644
--- a/modules/storage/storage.go
+++ b/modules/storage/storage.go
@@ -82,12 +82,32 @@ func Copy(dstStorage ObjectStorage, dstPath string, srcStorage ObjectStorage, sr
return dstStorage.Save(dstPath, f)
}
+// SaveFrom saves data to the ObjectStorage with path p from the callback
+func SaveFrom(objStorage ObjectStorage, p string, callback func(w io.Writer) error) error {
+ pr, pw := io.Pipe()
+ defer pr.Close()
+ go func() {
+ defer pw.Close()
+ if err := callback(pw); err != nil {
+ _ = pw.CloseWithError(err)
+ }
+ }()
+
+ _, err := objStorage.Save(p, pr)
+ return err
+}
+
var (
// Attachments represents attachments storage
Attachments ObjectStorage
// LFS represents lfs storage
LFS ObjectStorage
+
+ // Avatars represents user avatars storage
+ Avatars ObjectStorage
+ // RepoAvatars represents repository avatars storage
+ RepoAvatars ObjectStorage
)
// Init init the stoarge
@@ -96,6 +116,14 @@ func Init() error {
return err
}
+ if err := initAvatars(); err != nil {
+ return err
+ }
+
+ if err := initRepoAvatars(); err != nil {
+ return err
+ }
+
return initLFS()
}
@@ -112,6 +140,11 @@ func NewStorage(typStr string, cfg interface{}) (ObjectStorage, error) {
return fn(context.Background(), cfg)
}
+func initAvatars() (err error) {
+ Avatars, err = NewStorage(setting.Avatar.Storage.Type, setting.Avatar.Storage)
+ return
+}
+
func initAttachments() (err error) {
Attachments, err = NewStorage(setting.Attachment.Storage.Type, setting.Attachment.Storage)
return
@@ -121,3 +154,8 @@ func initLFS() (err error) {
LFS, err = NewStorage(setting.LFS.Storage.Type, setting.LFS.Storage)
return
}
+
+func initRepoAvatars() (err error) {
+ RepoAvatars, err = NewStorage(setting.RepoAvatar.Storage.Type, setting.RepoAvatar.Storage)
+ return
+}