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
This commit is contained in:
Lunny Xiao 2020-10-14 21:07:51 +08:00 committed by GitHub
parent 93f7525061
commit 80a6b0f5bc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 705 additions and 477 deletions

View file

@ -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
}