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

Merge pull request #1107 from bottify/master

fix: 当从 url 获取图片失败时,返回失败,而不是成功
This commit is contained in:
wdvxdr1123 2021-10-19 15:56:16 +08:00 committed by GitHub
commit a19baec013
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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 时出现错误: %v", msg["url"], err)
return Failed(100, "DOWNLOAD_IMAGE_ERROR", err.Error())
}
f.Close()
}
msg["file"] = local
return OK(msg)