From 80a6b0f5bce15a641fc75f5f1ef6e42ef54424bc Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 14 Oct 2020 21:07:51 +0800 Subject: 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 --- cmd/migrate_storage.go | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'cmd') diff --git a/cmd/migrate_storage.go b/cmd/migrate_storage.go index 5f19556d87..871baed92d 100644 --- a/cmd/migrate_storage.go +++ b/cmd/migrate_storage.go @@ -91,6 +91,20 @@ func migrateLFS(dstStorage storage.ObjectStorage) error { }) } +func migrateAvatars(dstStorage storage.ObjectStorage) error { + return models.IterateUser(func(user *models.User) error { + _, err := storage.Copy(dstStorage, user.CustomAvatarRelativePath(), storage.Avatars, user.CustomAvatarRelativePath()) + return err + }) +} + +func migrateRepoAvatars(dstStorage storage.ObjectStorage) error { + return models.IterateRepository(func(repo *models.Repository) error { + _, err := storage.Copy(dstStorage, repo.CustomAvatarRelativePath(), storage.RepoAvatars, repo.CustomAvatarRelativePath()) + return err + }) +} + func runMigrateStorage(ctx *cli.Context) error { if err := initDB(); err != nil { return err @@ -142,9 +156,8 @@ func runMigrateStorage(ctx *cli.Context) error { UseSSL: ctx.Bool("minio-use-ssl"), }) default: - return fmt.Errorf("Unsupported attachments storage type: %s", ctx.String("storage")) + return fmt.Errorf("Unsupported storage type: %s", ctx.String("storage")) } - if err != nil { return err } @@ -159,6 +172,14 @@ func runMigrateStorage(ctx *cli.Context) error { if err := migrateLFS(dstStorage); err != nil { return err } + case "avatars": + if err := migrateAvatars(dstStorage); err != nil { + return err + } + case "repo-avatars": + if err := migrateRepoAvatars(dstStorage); err != nil { + return err + } default: return fmt.Errorf("Unsupported storage: %s", ctx.String("type")) } -- cgit v1.2.3