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

View File

@ -24,7 +24,6 @@ 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
var err error
if val, exist := cache.Get("freegog_waf_session"); exist { if val, exist := cache.Get("freegog_waf_session"); exist {
session := ccs.Session{}
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 { } else {
session, err := ccs.WAFSession(config.Config.CFClearanceScraper.Url, constant.FreeGOGListURL) session, err = ccs.WAFSession(config.Config.CFClearanceScraper.Url, constant.FreeGOGListURL)
if err != nil { if err != nil {
return nil, err return nil, err
} }
c.session = &session
jsonBytes, _ := json.Marshal(session) jsonBytes, _ := json.Marshal(session)
_ = cache.AddWithExpire("freegog_waf_session", jsonBytes, 24*time.Hour) _ = cache.AddWithExpire("freegog_waf_session", jsonBytes, 24*time.Hour)
} }
} return &session, nil
return c.session, nil
} }
func (c *FreeGOGCrawler) Name() string { func (c *FreeGOGCrawler) Name() string {