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 4, 2024
1 parent 0ffd8b2 commit c34b727
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ require (
github.com/fumiama/cron v1.3.0
github.com/fumiama/go-base16384 v1.7.0
github.com/fumiama/go-registry v0.2.6
github.com/fumiama/terasu v0.0.0-20240502091919-c887e26289a8
github.com/gin-gonic/gin v1.8.2
github.com/go-playground/assert/v2 v2.2.0
github.com/go-playground/validator/v10 v10.11.1
Expand All @@ -38,7 +39,6 @@ require (
github.com/fumiama/go-simple-protobuf v0.1.0 // indirect
github.com/fumiama/gofastTEA v0.0.10 // indirect
github.com/fumiama/imgsz v0.0.2 // indirect
github.com/fumiama/terasu v0.0.0-20240502091919-c887e26289a8 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.6 // indirect
Expand Down
32 changes: 22 additions & 10 deletions img/pool/img.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (
"regexp"
"strings"

"github.com/fumiama/terasu/http2"
"github.com/sirupsen/logrus"
"github.com/wdvxdr1123/ZeroBot/message"

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

Expand Down Expand Up @@ -42,14 +42,21 @@ func GetImage(name string) (m *Image, err error) {
m.n = name
m.item, err = getItem(name)
if err == nil && m.u != "" {
_, err = web.RequestDataWithHeaders(web.NewDefaultClient(), m.String(), "HEAD", func(r *http.Request) error {
r.Header.Set("user-agent", web.RandUA())
return nil
}, nil)
var resp *http.Response
resp, err = http2.Head(m.String())
if err == nil {
return
}
if resp.StatusCode == http.StatusNotFound {
logrus.Debugln("[imgpool] image", name, m, "outdated:", err)
err = ErrImgFileOutdated
return
}
resp, err = http2.Get(m.String())
_ = resp.Body.Close()
if err == nil {
return
}
logrus.Debugln("[imgpool] image", name, m, "outdated:", err)
err = ErrImgFileOutdated
return
}
Expand All @@ -65,13 +72,18 @@ func NewImage(send ctxext.NoCtxSendMsg, get ctxext.NoCtxGetMsg, name, f string)
m.SetFile(f)
m.item, err = getItem(name)
if err == nil && m.item.u != "" {
_, err = web.RequestDataWithHeaders(web.NewDefaultClient(), m.String(), "HEAD", func(r *http.Request) error {
r.Header.Set("user-agent", web.RandUA())
return nil
}, nil)
var resp *http.Response
resp, err = http2.Head(m.String())
if err == nil {
return
}
if resp.StatusCode != http.StatusNotFound {
resp, err = http2.Get(m.String())
_ = resp.Body.Close()
if err == nil {
return
}
}
logrus.Debugln("[imgpool] image", name, m, "outdated:", err, "updating...")
}
hassent, err = m.Push(send, get)
Expand Down

0 comments on commit c34b727

Please sign in to comment.