From b138550d9baee71959a6015e253b9a1c678b4f96 Mon Sep 17 00:00:00 2001 From: nite07 Date: Thu, 21 Nov 2024 00:03:39 +0800 Subject: [PATCH] try fix freegog crawler --- crawler/freegog.go | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/crawler/freegog.go b/crawler/freegog.go index d5274c3..bb6a112 100644 --- a/crawler/freegog.go +++ b/crawler/freegog.go @@ -19,8 +19,7 @@ import ( ) type FreeGOGCrawler struct { - logger *zap.Logger - session *utils.WAFSession + logger *zap.Logger } func NewFreeGOGCrawler(logger *zap.Logger) *FreeGOGCrawler { @@ -35,17 +34,14 @@ func (c *FreeGOGCrawler) Name() string { func (c *FreeGOGCrawler) Crawl(num int) ([]*model.GameItem, error) { count := 0 - var err error - if c.session == nil { - c.session, err = utils.CCSWAFSession(config.Config.CFClearanceScraper.Url, constant.FreeGOGListURL) - } + session, err := utils.CCSWAFSession(config.Config.CFClearanceScraper.Url, constant.FreeGOGListURL) if err != nil { c.logger.Error("Failed to create session", zap.Error(err)) return nil, err } resp, err := utils.FetchWithWAFSession(utils.FetchConfig{ Url: constant.FreeGOGListURL, - }, c.session) + }, session) if err != nil { c.logger.Error("Failed to fetch", zap.Error(err)) return nil, err @@ -72,7 +68,7 @@ func (c *FreeGOGCrawler) Crawl(num int) ([]*model.GameItem, error) { continue } c.logger.Info("Crawling", zap.String("URL", u)) - item, err := c.CrawlByUrl(u) + item, err := c.CrawlByUrl(u, session) if err != nil { c.logger.Warn("Failed to crawl", zap.Error(err), zap.String("URL", u)) continue @@ -99,17 +95,14 @@ func (c *FreeGOGCrawler) Crawl(num int) ([]*model.GameItem, error) { return res, nil } -func (c *FreeGOGCrawler) CrawlByUrl(url string) (*model.GameItem, error) { +func (c *FreeGOGCrawler) CrawlByUrl(url string, session *utils.WAFSession) (*model.GameItem, error) { var err error - if c.session == nil { - c.session, err = utils.CCSWAFSession(config.Config.CFClearanceScraper.Url, constant.FreeGOGListURL) - } if err != nil { return nil, errors.New("Failed to create session") } resp, err := utils.FetchWithWAFSession(utils.FetchConfig{ Url: url, - }, c.session) + }, session) if err != nil { return nil, err }