support thumb url (#62)

This commit is contained in:
Sarv
2025-04-19 18:30:41 +08:00
committed by GitHub
parent a745519451
commit d124086e70
7 changed files with 126 additions and 37 deletions

View File

@@ -35,6 +35,7 @@ type Image struct {
}
type Video struct {
Md5 string `xml:"md5,attr"`
RawMd5 string `xml:"rawmd5,attr"`
// Length string `xml:"length,attr"`
// PlayLength string `xml:"playlength,attr"`

View File

@@ -79,7 +79,12 @@ func (m *Message) ParseMediaInfo(data string) error {
case 3:
m.Contents["md5"] = msg.Image.MD5
case 43:
m.Contents["md5"] = msg.Video.RawMd5
if msg.Video.Md5 != "" {
m.Contents["md5"] = msg.Video.Md5
}
if msg.Video.RawMd5 != "" {
m.Contents["rawmd5"] = msg.Video.RawMd5
}
case 49:
m.SubType = int64(msg.App.Type)
switch m.SubType {
@@ -234,7 +239,23 @@ func (m *Message) PlainTextContent() string {
case 1:
return m.Content
case 3:
return fmt.Sprintf("![图片](http://%s/image/%s)", m.Contents["host"], m.Contents["md5"])
keylist := make([]string, 0)
if m.Contents["md5"] != nil {
if md5, ok := m.Contents["md5"].(string); ok {
keylist = append(keylist, md5)
}
}
if m.Contents["imgfile"] != nil {
if imgfile, ok := m.Contents["imgfile"].(string); ok {
keylist = append(keylist, imgfile)
}
}
if m.Contents["thumb"] != nil {
if thumb, ok := m.Contents["thumb"].(string); ok {
keylist = append(keylist, thumb)
}
}
return fmt.Sprintf("![图片](http://%s/image/%s)", m.Contents["host"], strings.Join(keylist, ","))
case 34:
if voice, ok := m.Contents["voice"]; ok {
return fmt.Sprintf("[语音](http://%s/voice/%s)", m.Contents["host"], voice)
@@ -243,10 +264,28 @@ func (m *Message) PlainTextContent() string {
case 42:
return "[名片]"
case 43:
if path, ok := m.Contents["path"]; ok {
return fmt.Sprintf("![视频](http://%s/data/%s)", m.Contents["host"], path)
keylist := make([]string, 0)
if m.Contents["md5"] != nil {
if md5, ok := m.Contents["md5"].(string); ok {
keylist = append(keylist, md5)
}
}
return fmt.Sprintf("![视频](http://%s/video/%s)", m.Contents["host"], m.Contents["md5"])
if m.Contents["rawmd5"] != nil {
if rawmd5, ok := m.Contents["rawmd5"].(string); ok {
keylist = append(keylist, rawmd5)
}
}
if m.Contents["videofile"] != nil {
if videofile, ok := m.Contents["videofile"].(string); ok {
keylist = append(keylist, videofile)
}
}
if m.Contents["thumb"] != nil {
if thumb, ok := m.Contents["thumb"].(string); ok {
keylist = append(keylist, thumb)
}
}
return fmt.Sprintf("![视频](http://%s/video/%s)", m.Contents["host"], strings.Join(keylist, ","))
case 47:
return "[动画表情]"
case 49:

View File

@@ -96,7 +96,7 @@ func (m *MessageV3) Wrap() *Message {
if len(parts) > 1 {
path = strings.Join(parts[1:], "/")
}
_m.Contents["path"] = path
_m.Contents["videofile"] = path
}
}
}

View File

@@ -2,7 +2,10 @@ package model
import (
"bytes"
"crypto/md5"
"encoding/hex"
"fmt"
"path/filepath"
"strings"
"time"
@@ -85,10 +88,14 @@ func (m *MessageV4) Wrap(talker string) *Message {
if packedInfo := ParsePackedInfo(m.PackedInfoData); packedInfo != nil {
// FIXME 尝试解决 v4 版本 xml 数据无法匹配到 hardlink 记录的问题
if _m.Type == 3 && packedInfo.Image != nil {
_m.Contents["md5"] = packedInfo.Image.Md5
_talkerMd5Bytes := md5.Sum([]byte(talker))
talkerMd5 := hex.EncodeToString(_talkerMd5Bytes[:])
_m.Contents["imgfile"] = filepath.Join("msg", "attach", talkerMd5, _m.Time.Format("2006-01"), "Img", fmt.Sprintf("%s.dat", packedInfo.Image.Md5))
_m.Contents["thumb"] = filepath.Join("msg", "attach", talkerMd5, _m.Time.Format("2006-01"), "Img", fmt.Sprintf("%s_t.dat", packedInfo.Image.Md5))
}
if _m.Type == 43 && packedInfo.Video != nil {
_m.Contents["md5"] = packedInfo.Video.Md5
_m.Contents["videofile"] = filepath.Join("msg", "video", _m.Time.Format("2006-01"), fmt.Sprintf("%s.mp4", packedInfo.Video.Md5))
_m.Contents["thumb"] = filepath.Join("msg", "video", _m.Time.Format("2006-01"), fmt.Sprintf("%s_thumb.jpg", packedInfo.Video.Md5))
}
}
}