mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-06-01 04:12:10 +00:00
fix: repo avatar generating (#6338)
This commit is contained in:
parent
4e820ff795
commit
be076c98d4
2 changed files with 37 additions and 3 deletions
|
@ -8,7 +8,6 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
|
@ -107,7 +106,18 @@ func RemoveRandomAvatars(ctx context.Context) error {
|
|||
|
||||
// generateAvatar generates the avatar from a template repository
|
||||
func generateAvatar(ctx context.Context, templateRepo, generateRepo *repo_model.Repository) error {
|
||||
generateRepo.Avatar = strings.Replace(templateRepo.Avatar, strconv.FormatInt(templateRepo.ID, 10), strconv.FormatInt(generateRepo.ID, 10), 1)
|
||||
file, err := storage.RepoAvatars.Open(templateRepo.CustomAvatarRelativePath())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
data, err := io.ReadAll(file)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
generateRepo.Avatar = avatar.HashAvatar(generateRepo.ID, data)
|
||||
if _, err := storage.Copy(storage.RepoAvatars, generateRepo.CustomAvatarRelativePath(), storage.RepoAvatars, templateRepo.CustomAvatarRelativePath()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue