mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-14 05:52:43 +00:00
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:
parent
93f7525061
commit
80a6b0f5bc
21 changed files with 705 additions and 477 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue