commit 20afb4e66068bef9ef389832f2b16c2fbd7ae3f9
parent bfb484b4b897fb265477b9ebd1f5bbd382ce2867
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Fri, 29 Dec 2023 12:06:38 -0500
use crc32 instead of md5
Diffstat:
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go
@@ -29,6 +29,7 @@ import (
"github.com/ProtonMail/go-crypto/openpgp/packet"
"github.com/alecthomas/chroma/formatters/html"
"github.com/asaskevich/govalidator"
+ "hash/crc32"
html2 "html"
"image"
"image/jpeg"
@@ -232,6 +233,12 @@ func MD5(in []byte) string {
return hex.EncodeToString(h.Sum(nil))
}
+func Crc32(in []byte) uint32 {
+ h := crc32.NewIEEE()
+ _, _ = h.Write(in)
+ return h.Sum32()
+}
+
// ShortDisplayID generate a short display id
func ShortDisplayID(size int64) string {
if size <= 4 || size > 20 {
diff --git a/pkg/web/handlers/api/v1/chat.go b/pkg/web/handlers/api/v1/chat.go
@@ -440,7 +440,7 @@ func ChatStreamMenuHandler(c echo.Context) error {
defer streamItem.Cleanup()
send := func(s string) { _, _ = c.Response().Write([]byte(s)) }
- var prevHash string
+ var prevHash uint32
var menuID int
var once utils.Once
@@ -463,7 +463,7 @@ Loop:
data := GetChatMenuData(c, room)
rightColumn := RenderRightColumn(authUser, data)
- newHash := utils.MD5([]byte(rightColumn))
+ newHash := utils.Crc32([]byte(rightColumn))
if newHash != prevHash {
send(fmt.Sprintf(`<style>#menu_%d{display:none}</style><div id="menu_%d">%s</div>`, menuID, menuID+1, rightColumn))
c.Response().Flush()