Skip to content

Commit

Permalink
fix: 视频和图片缓存
Browse files Browse the repository at this point in the history
  • Loading branch information
Redmomn committed Nov 14, 2024
1 parent be805fd commit cf86eab
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 30 deletions.
1 change: 0 additions & 1 deletion cmd/gocq/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ func LoginInteract() {
app := auth.AppList["linux"]["3.2.10-25765"]
log.Infof("使用协议: %s %s", app.OS, app.CurrentVersion)
cli = newClient(app)
cli.UseVersion(app)
cli.UseDevice(device)
isQRCodeLogin := (base.Account.Uin == 0 || len(base.Account.Password) == 0) && !base.Account.Encrypt
isTokenLogin := false
Expand Down
8 changes: 2 additions & 6 deletions coolq/cqcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -1020,13 +1020,9 @@ func (bot *CQBot) readVideoCache(b []byte) message.IMessageElement {
r := binary.NewReader(b)
return &message.ShortVideoElement{ // todo 检查缓存是否有效
Md5: r.ReadBytes(16),
Size: r.ReadU32(),
Thumb: &message.VideoThumb{
Md5: r.ReadBytes(16),
Size: r.ReadU32(),
},
Sha1: r.ReadBytes(20),
Name: r.ReadStringWithLength("u32", true),
UUID: r.ReadBytes(r.Len()),
UUID: r.ReadStringWithLength("u32", true),
}
}

Expand Down
27 changes: 7 additions & 20 deletions coolq/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,21 +534,16 @@ func (bot *CQBot) checkMedia(e []message.IMessageElement, source message.Source)
switch i := elem.(type) {
case *message.ImageElement:
// 闪照已经4了(私聊还没)
//if i.Flash && sourceID != 0 {
// u, err := bot.Client.GetGroupImageDownloadUrl(i.FileId, sourceID, i.Md5)
//if i.Flash && source.PrimaryID != 0 {
// u, err := bot.Client.GetGroupImageURL(uint32(source.PrimaryID), i.MsgInfo.MsgInfoBody[0].Index)
// if err != nil {
// log.Warnf("获取闪照地址时出现错误: %v", err)
// } else {
// i.Url = u
// i.URL = u
// }
//}
data := binary.NewWriterF(func(w *binary.Builder) {
_, err := w.Write(i.Md5)
if err != nil {
log.Warnf("计算图片md5时出现错误: %v", err)
return
}

_, _ = w.Write(i.Md5)
w.WritePacketString(i.FileUUID, "u32", true)
w.WritePacketString(i.ImageID, "u32", true)
})
Expand All @@ -567,18 +562,10 @@ func (bot *CQBot) checkMedia(e []message.IMessageElement, source message.Source)
}
case *message.ShortVideoElement:
data := binary.NewWriterF(func(w *binary.Builder) {
_, err := w.Write(i.Md5)
if err != nil {
log.Warnf("计算视频md5时出现错误: %v", err)
return
}
_, err = w.Write(i.Sha1)
if err != nil {
log.Warnf("计算视频sha1时出现错误: %v", err)
return
}
_, _ = w.Write(i.Md5)
_, _ = w.Write(i.Sha1)
w.WritePacketString(i.Name, "u32", true)
w.WritePacketBytes(i.UUID, "u32", true)
w.WritePacketString(i.UUID, "u32", true)
})
filename := hex.EncodeToString(i.Md5) + ".video"
cache.Video.Insert(i.Md5, data)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.20

require (
github.com/FloatTech/sqlite v1.6.3
github.com/LagrangeDev/LagrangeGo v0.1.2-0.20241112102104-63ccad50ea67
github.com/LagrangeDev/LagrangeGo v0.1.2-0.20241114034146-304fa373b532
github.com/Microsoft/go-winio v0.6.2-0.20230724192519-b29bbd58a65a
github.com/RomiChan/syncx v0.0.0-20240418144900-b7402ffdebc7
github.com/RomiChan/websocket v1.4.3-0.20220227141055-9b2c6168c9c5
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ github.com/FloatTech/sqlite v1.6.3 h1:MQkqBNlkPuCoKQQgoNLuTL/2Ci3tBTFAnVYBdD0Wy4
github.com/FloatTech/sqlite v1.6.3/go.mod h1:zFbHzRfB+CJ+VidfjuVbrcin3DAz283F7hF1hIeHzpY=
github.com/FloatTech/ttl v0.0.0-20230307105452-d6f7b2b647d1 h1:g4pTnDJUW4VbJ9NvoRfUvdjDrHz/6QhfN/LoIIpICbo=
github.com/FloatTech/ttl v0.0.0-20230307105452-d6f7b2b647d1/go.mod h1:fHZFWGquNXuHttu9dUYoKuNbm3dzLETnIOnm1muSfDs=
github.com/LagrangeDev/LagrangeGo v0.1.2-0.20241112102104-63ccad50ea67 h1:rbD3p2W6IaQxaZIo1X5fWxeRStHb+VeJBhBITUg2bhE=
github.com/LagrangeDev/LagrangeGo v0.1.2-0.20241112102104-63ccad50ea67/go.mod h1:m7ydyvA8DKOg5c6iTFDfNtfIK9uhqXVJKRXl4mlGkTA=
github.com/LagrangeDev/LagrangeGo v0.1.2-0.20241114034146-304fa373b532 h1:fcNkzgqc31OKtBm19XyT6GXKF/OvH9bWvmiUKKENjTM=
github.com/LagrangeDev/LagrangeGo v0.1.2-0.20241114034146-304fa373b532/go.mod h1:m7ydyvA8DKOg5c6iTFDfNtfIK9uhqXVJKRXl4mlGkTA=
github.com/Microsoft/go-winio v0.6.2-0.20230724192519-b29bbd58a65a h1:aU1703IHxupjzipvhu16qYKLMR03e+8WuNR+JMsKfGU=
github.com/Microsoft/go-winio v0.6.2-0.20230724192519-b29bbd58a65a/go.mod h1:OZqLNXdYJHmx7aqq/T6wAdFEdoGm5nmIfC4kU7M8P8o=
github.com/RomiChan/protobuf v0.1.1-0.20230204044148-2ed269a2e54d h1:/Xuj3fIiMY2ls1TwvPKmaqQrtJsPY+c9s+0lOScVHd8=
Expand Down

0 comments on commit cf86eab

Please sign in to comment.