Refactor sha1 and time-limited code (#31023) (#31030)

Backport #31023 by wxiaoguang

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
Giteabot 2024-05-21 00:58:21 +08:00 committed by GitHub
parent 8a259e54c5
commit 55cb356b84
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 120 additions and 96 deletions

View file

@ -4,6 +4,8 @@
package git
import (
"crypto/sha1"
"encoding/hex"
"fmt"
"io"
"os"
@ -128,3 +130,9 @@ func (l *LimitedReaderCloser) Read(p []byte) (n int, err error) {
func (l *LimitedReaderCloser) Close() error {
return l.C.Close()
}
func HashFilePathForWebUI(s string) string {
h := sha1.New()
_, _ = h.Write([]byte(s))
return hex.EncodeToString(h.Sum(nil))
}