Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复错误 #123

Merged
merged 3 commits into from
Nov 14, 2024
Merged
Changes from 1 commit
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
60 changes: 19 additions & 41 deletions message/elements.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,22 +193,14 @@ func NewRecord(data []byte, summary ...string) *VoiceElement {
func NewStreamRecord(r io.ReadSeeker, summary ...string) *VoiceElement {
md5, sha1, length := crypto.ComputeMd5AndSha1AndLength(r)
return &VoiceElement{
Size: uint32(length),
Summary: func() string {
if len(summary) != 0 {
return summary[0]
}
return ""
}(),
Stream: r,
Md5: md5,
Sha1: sha1,
Size: uint32(length),
Summary: utils.Ternary(len(summary) == 0, "", summary[0]),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

显然这是不对的,如果没有传summary,这就是一个数组越界访问

Stream: r,
Md5: md5,
Sha1: sha1,
Duration: func() uint32 {
info, err := audio.Decode(r)
if err != nil {
return uint32(info.Time)
}
return uint32(length)
return utils.Ternary(err == nil, uint32(info.Time), uint32(length))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果err不是nil,info.Time就是空指针引用

}(),
}
}
Expand All @@ -228,16 +220,11 @@ func NewImage(data []byte, summary ...string) *ImageElement {
func NewStreamImage(r io.ReadSeeker, summary ...string) *ImageElement {
md5, sha1, length := crypto.ComputeMd5AndSha1AndLength(r)
return &ImageElement{
Size: uint32(length),
Summary: func() string {
if len(summary) != 0 {
return summary[0]
}
return ""
}(),
Stream: r,
Md5: md5,
Sha1: sha1,
Size: uint32(length),
Summary: utils.Ternary(len(summary) == 0, "", summary[0]),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上

Stream: r,
Md5: md5,
Sha1: sha1,
}
}

Expand All @@ -256,18 +243,13 @@ func NewVideo(data, thumb []byte, summary ...string) *ShortVideoElement {
func NewStreamVideo(r io.ReadSeeker, thumb io.ReadSeeker, summary ...string) *ShortVideoElement {
md5, sha1, length := crypto.ComputeMd5AndSha1AndLength(r)
return &ShortVideoElement{
Size: uint32(length),
Thumb: NewVideoThumb(thumb),
Summary: func() string {
if len(summary) != 0 {
return summary[0]
}
return ""
}(),
Md5: md5,
Sha1: sha1,
Stream: r,
Compat: &message.VideoFile{},
Size: uint32(length),
Thumb: NewVideoThumb(thumb),
Summary: utils.Ternary(len(summary) == 0, "", summary[0]),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

写宏写混了,意识没切过来😓😓😓😓😓

Md5: md5,
Sha1: sha1,
Stream: r,
Compat: &message.VideoFile{},
}
}

Expand Down Expand Up @@ -318,11 +300,7 @@ func NewLocalFile(path string, name ...string) (*FileElement, error) {
if err != nil {
return nil, err
}
return NewStreamFile(file, utils.LazyTernary(len(name) == 0, func() string {
return filepath.Base(file.Name())
}, func() string {
return name[0]
})), nil
return NewStreamFile(file, utils.Ternary(len(name) == 0, filepath.Base(file.Name()), name[0])), nil
Redmomn marked this conversation as resolved.
Show resolved Hide resolved
}

func NewLightApp(content string) *LightAppElement {
Expand Down