1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-05 11:33:48 +08:00

drop cache file .cqimg.

This commit is contained in:
wdvxdr 2021-08-09 21:31:06 +08:00
parent 84488f9bf1
commit 4c8b2e9f13
No known key found for this signature in database
GPG Key ID: 703F8C071DE7A1B6

View File

@ -1147,15 +1147,13 @@ func (bot *CQBot) makeImageOrVideoElem(d map[string]string, video, group bool) (
exist = true exist = true
rawPath = path.Join(global.ImagePathOld, f) rawPath = path.Join(global.ImagePathOld, f)
} }
if !exist && global.PathExists(rawPath+".cqimg") { if !exist {
exist = true if d["url"] != "" {
rawPath += ".cqimg"
}
if !exist && d["url"] != "" {
return bot.makeImageOrVideoElem(map[string]string{"file": d["url"]}, false, group) return bot.makeImageOrVideoElem(map[string]string{"file": d["url"]}, false, group)
} }
if exist { return nil, errors.New("invalid image")
if path.Ext(rawPath) != ".image" && path.Ext(rawPath) != ".cqimg" { }
if path.Ext(rawPath) != ".image" {
return &LocalImageElement{File: rawPath}, nil return &LocalImageElement{File: rawPath}, nil
} }
b, err := os.ReadFile(rawPath) b, err := os.ReadFile(rawPath)
@ -1165,29 +1163,11 @@ func (bot *CQBot) makeImageOrVideoElem(d map[string]string, video, group bool) (
if len(b) < 20 { if len(b) < 20 {
return nil, errors.New("invalid local file") return nil, errors.New("invalid local file")
} }
var (
size int32
hash []byte
imageURL string
)
if path.Ext(rawPath) == ".cqimg" {
for _, line := range strings.Split(global.ReadAllText(rawPath), "\n") {
kv := strings.SplitN(line, "=", 2)
switch kv[0] {
case "md5":
hash, _ = hex.DecodeString(strings.ReplaceAll(kv[1], "\r", ""))
case "size":
t, _ := strconv.Atoi(strings.ReplaceAll(kv[1], "\r", ""))
size = int32(t)
}
}
} else {
r := binary.NewReader(b) r := binary.NewReader(b)
hash = r.ReadBytes(16) hash := r.ReadBytes(16)
size = r.ReadInt32() size := r.ReadInt32()
r.ReadString() r.ReadString()
imageURL = r.ReadString() imageURL := r.ReadString()
}
if size == 0 { if size == 0 {
if imageURL != "" { if imageURL != "" {
return bot.makeImageOrVideoElem(map[string]string{"file": imageURL}, false, group) return bot.makeImageOrVideoElem(map[string]string{"file": imageURL}, false, group)
@ -1203,7 +1183,7 @@ func (bot *CQBot) makeImageOrVideoElem(d map[string]string, video, group bool) (
goto ok goto ok
} }
rsp, err = bot.Client.QueryFriendImage(int64(rand.Uint32()), hash, size) rsp, err = bot.Client.QueryFriendImage(int64(rand.Uint32()), hash, size)
ok: ok:
if err != nil { if err != nil {
if imageURL != "" { if imageURL != "" {
return bot.makeImageOrVideoElem(map[string]string{"file": imageURL}, false, group) return bot.makeImageOrVideoElem(map[string]string{"file": imageURL}, false, group)
@ -1211,8 +1191,6 @@ func (bot *CQBot) makeImageOrVideoElem(d map[string]string, video, group bool) (
return nil, err return nil, err
} }
return rsp, nil return rsp, nil
}
return nil, errors.New("invalid image")
} }
// makeShowPic 一种xml 方式发送的群消息图片 // makeShowPic 一种xml 方式发送的群消息图片