From 96797fed311151ff889f87c94c7b6aaa16c5d535 Mon Sep 17 00:00:00 2001 From: Gusted Date: Mon, 2 Jan 2023 22:46:39 +0100 Subject: Unify hashing for avatar (#22289) - Unify the hashing code for repository and user avatars into a function. - Use a sane hash function instead of MD5. - Only require hashing once instead of twice(w.r.t. hashing for user avatar). - Improve the comment for the hashing code of why it works. Co-authored-by: Lunny Xiao Co-authored-by: Yarden Shoham --- services/repository/avatar.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'services/repository/avatar.go') diff --git a/services/repository/avatar.go b/services/repository/avatar.go index a829a1000a..5fe8bd2c72 100644 --- a/services/repository/avatar.go +++ b/services/repository/avatar.go @@ -5,7 +5,6 @@ package repository import ( "context" - "crypto/md5" "fmt" "image/png" "io" @@ -27,7 +26,7 @@ func UploadAvatar(repo *repo_model.Repository, data []byte) error { return err } - newAvatar := fmt.Sprintf("%d-%x", repo.ID, md5.Sum(data)) + newAvatar := avatar.HashAvatar(repo.ID, data) if repo.Avatar == newAvatar { // upload the same picture return nil } -- cgit v1.2.3