Refactor avatar package, support default avatar fallback (#36788)

* Fix #34715
This commit is contained in:
wxiaoguang authored and GitHub committed 2026-03-01 13:32:35 +00:00
1 parent 1592576fa5
commit 2c624d4deb
15 files changed
+205 -276

No files matched your search

+3 -9
View File
@@ -41,20 +41,14 @@ func generateRandomAvatar(ctx context.Context, repo *Repository) error {
idToString := strconv.FormatInt(repo.ID, 10)
seed := idToString
img, err := avatar.RandomImage([]byte(seed))
if err != nil {
return fmt.Errorf("RandomImage: %w", err)
}
img := avatar.RandomImageDefaultSize([]byte(seed))
repo.Avatar = idToString
if err := storage.SaveFrom(storage.RepoAvatars, repo.CustomAvatarRelativePath(), func(w io.Writer) error {
if err := png.Encode(w, img); err != nil {
log.Error("Encode: %v", err)
}
return err
return png.Encode(w, img)
}); err != nil {
return fmt.Errorf("Failed to create dir %s: %w", repo.CustomAvatarRelativePath(), err)
return fmt.Errorf("failed to create dir %s: %w", repo.CustomAvatarRelativePath(), err)
}
log.Info("New random avatar created for repository: %d", repo.ID)