1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

Fix user avatar name (#8547)

Migrate avatar names to include user ID and the md5 hash.
This commit is contained in:
Masudur Rahman
2019-12-28 00:27:59 +06:00
committed by zeripath
parent 145c1ea0b6
commit e3a5b83212
3 changed files with 119 additions and 1 deletions

View File

@@ -521,7 +521,11 @@ func (u *User) UploadAvatar(data []byte) error {
}
u.UseCustomAvatar = true
u.Avatar = fmt.Sprintf("%x", md5.Sum(data))
// Different users can upload same image as avatar
// If we prefix it with u.ID, it will be separated
// Otherwise, if any of the users delete his avatar
// Other users will lose their avatars too.
u.Avatar = fmt.Sprintf("%x", md5.Sum([]byte(fmt.Sprintf("%d-%x", u.ID, md5.Sum(data)))))
if err = updateUser(sess, u); err != nil {
return fmt.Errorf("updateUser: %v", err)
}