Skip to content

Commit

Permalink
fix: img pool
Browse files Browse the repository at this point in the history
  • Loading branch information
fumiama committed May 5, 2024
1 parent b7df371 commit 608a591
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions img/pool/img.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/sirupsen/logrus"
"github.com/wdvxdr1123/ZeroBot/message"

"github.com/FloatTech/floatbox/web"
"github.com/FloatTech/zbputils/ctxext"
)

Expand Down Expand Up @@ -49,18 +50,20 @@ func GetImage(name string) (m *Image, err error) {
return
}
if resp.StatusCode == http.StatusNotFound {
logrus.Debugln("[imgpool] image", name, m, "outdated:", err)
logrus.Debugln("[imgpool] image", name, m, "outdated, code:", resp.StatusCode)
err = ErrImgFileOutdated
return
}
}
resp, err = http2.Get(m.String())
_, err = web.RequestDataWithHeaders(http.DefaultClient, m.String(), "GET", func(r *http.Request) error {
r.Header.Set("Range", "bytes=0-1")
r.Header.Set("User-Agent", web.RandUA())
return nil
}, nil)
if err == nil {
_ = resp.Body.Close()
if resp.StatusCode == http.StatusOK {
return
}
return
}
logrus.Debugln("[imgpool] image", name, m, "outdated:", err)
err = ErrImgFileOutdated
return
}
Expand All @@ -83,12 +86,13 @@ func NewImage(send ctxext.NoCtxSendMsg, get ctxext.NoCtxGetMsg, name, f string)
return
}
if resp.StatusCode != http.StatusNotFound {
resp, err = http2.Get(m.String())
_, err = web.RequestDataWithHeaders(http.DefaultClient, m.String(), "GET", func(r *http.Request) error {
r.Header.Set("Range", "bytes=0-1")
r.Header.Set("User-Agent", web.RandUA())
return nil
}, nil)
if err == nil {
_ = resp.Body.Close()
if resp.StatusCode == http.StatusOK {
return
}
return
}
}
}
Expand Down

0 comments on commit 608a591

Please sign in to comment.