1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-05 03:23:49 +08:00

fix: return error when get_image from url failed

This commit is contained in:
Tamce 2021-10-15 02:33:22 +08:00
parent efdd6bd16a
commit 20fd8a9619

View File

@ -1051,12 +1051,15 @@ func (bot *CQBot) CQGetImage(file string) global.MSG {
}
local := path.Join(global.CachePath, file+"."+path.Ext(msg["filename"].(string)))
if !global.PathExists(local) {
f, _ := os.OpenFile(local, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o0644)
if body, err := global.HTTPGetReadCloser(msg["url"].(string)); err == nil {
f, _ := os.OpenFile(local, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o0644)
_, _ = f.ReadFrom(body)
_ = body.Close()
f.Close()
} else {
log.Warnf("下载图片 %v 时出现错误", msg["url"], err)
return Failed(100, "DOWNLOAD_IMAGE_ERROR", err.Error())
}
f.Close()
}
msg["file"] = local
return OK(msg)