This commit is contained in:
Nite07 2024-12-02 16:51:06 +08:00
parent 7fd4acd238
commit f358a74079

View File

@ -23,8 +23,7 @@ import (
) )
type FreeGOGCrawler struct { type FreeGOGCrawler struct {
logger *zap.Logger logger *zap.Logger
session *ccs.Session
} }
func NewFreeGOGCrawler(logger *zap.Logger) *FreeGOGCrawler { func NewFreeGOGCrawler(logger *zap.Logger) *FreeGOGCrawler {
@ -34,25 +33,22 @@ func NewFreeGOGCrawler(logger *zap.Logger) *FreeGOGCrawler {
} }
func (c *FreeGOGCrawler) getWAFSession() (*ccs.Session, error) { func (c *FreeGOGCrawler) getWAFSession() (*ccs.Session, error) {
if c.session == nil { var session ccs.Session
if val, exist := cache.Get("freegog_waf_session"); exist { var err error
session := ccs.Session{} if val, exist := cache.Get("freegog_waf_session"); exist {
err := json.Unmarshal([]byte(val), &session) err := json.Unmarshal([]byte(val), &session)
if err != nil { if err != nil {
return nil, err return nil, err
}
c.session = &session
} else {
session, err := ccs.WAFSession(config.Config.CFClearanceScraper.Url, constant.FreeGOGListURL)
if err != nil {
return nil, err
}
c.session = &session
jsonBytes, _ := json.Marshal(session)
_ = cache.AddWithExpire("freegog_waf_session", jsonBytes, 24*time.Hour)
} }
} else {
session, err = ccs.WAFSession(config.Config.CFClearanceScraper.Url, constant.FreeGOGListURL)
if err != nil {
return nil, err
}
jsonBytes, _ := json.Marshal(session)
_ = cache.AddWithExpire("freegog_waf_session", jsonBytes, 24*time.Hour)
} }
return c.session, nil return &session, nil
} }
func (c *FreeGOGCrawler) Name() string { func (c *FreeGOGCrawler) Name() string {