mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-04 19:17:37 +08:00
Merge pull request #1107 from bottify/master
fix: 当从 url 获取图片失败时,返回失败,而不是成功
This commit is contained in:
commit
a19baec013
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user