Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -878,19 +878,31 @@ func (c *Config) GetAvatarPath(uid string) string {

// GetGroupAvatarFilePath 获取群头像上传路径
func (c *Config) GetGroupAvatarFilePath(groupNo string) string {
avatarID := crc32.ChecksumIEEE([]byte(groupNo)) % uint32(c.Avatar.Partition)
partition := c.Avatar.Partition
if partition <= 0 {
partition = 1
}
avatarID := crc32.ChecksumIEEE([]byte(groupNo)) % uint32(partition)
return fmt.Sprintf("group/%d/%s.png", avatarID, groupNo)
}

// GetCommunityAvatarFilePath 获取社区头像上传路径
func (c *Config) GetCommunityAvatarFilePath(communityNo string) string {
avatarID := crc32.ChecksumIEEE([]byte(communityNo)) % uint32(c.Avatar.Partition)
partition := c.Avatar.Partition
if partition <= 0 {
partition = 1
}
avatarID := crc32.ChecksumIEEE([]byte(communityNo)) % uint32(partition)
return fmt.Sprintf("community/%d/%s.png", avatarID, communityNo)
}

// GetCommunityCoverFilePath 获取社区封面上传路径
func (c *Config) GetCommunityCoverFilePath(communityNo string) string {
avatarID := crc32.ChecksumIEEE([]byte(communityNo)) % uint32(c.Avatar.Partition)
partition := c.Avatar.Partition
if partition <= 0 {
partition = 1
}
avatarID := crc32.ChecksumIEEE([]byte(communityNo)) % uint32(partition)
return fmt.Sprintf("community/%d/%s_cover.png", avatarID, communityNo)
}

Expand Down Expand Up @@ -975,7 +987,7 @@ func GetEnvInt(key string, defaultValue int) int {
if strings.TrimSpace(v) == "" {
return defaultValue
}
i, err := strconv.ParseInt(v, 10, 64)
i, err := strconv.ParseInt(v, 10, 0)
if err != nil {
fmt.Printf("WARN: invalid env %s=%q, using default %d: %v\n", key, v, defaultValue, err)
return defaultValue
Expand Down
4 changes: 4 additions & 0 deletions config/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"math"
"net/http"
"strings"

Expand Down Expand Up @@ -155,6 +156,9 @@ func (c *Context) SendMessageWithResult(req *MsgSendReq) (*MsgSendResp, error) {
messageID := dataResult.Get("message_id").Int()
messageSeq := dataResult.Get("message_seq").Int()
clientMsgNo := dataResult.Get("client_msg_no").String()
if messageSeq < 0 || messageSeq > math.MaxUint32 {
return nil, fmt.Errorf("IM服务[SendMessage]返回 message_seq=%d 超出 uint32 范围", messageSeq)
}
return &MsgSendResp{
MessageID: messageID,
MessageSeq: uint32(messageSeq),
Expand Down
Loading