From 71ef2d24fa63aef1aee310baecd12b5b65fe57d2 Mon Sep 17 00:00:00 2001 From: achmad Date: Wed, 13 May 2026 21:35:10 +0700 Subject: [PATCH] fix: update HTTP client to flare for Batch 4 sources MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Based on Kotlin reference verification: - madtheme, mangabox, mangacatalog, mangahub → flare Also updated phase4-standalone.md with project requirement for checking HTTP client type when porting sources from Kotlin --- docs/phase4-standalone.md | 7 +++++++ sources/base/madtheme/madtheme.go | 13 ++++--------- sources/base/mangabox/mangabox.go | 21 +++++---------------- sources/base/mangacatalog/mangacatalog.go | 13 ++++--------- sources/base/mangahub/mangahub.go | 16 ++++------------ 5 files changed, 24 insertions(+), 46 deletions(-) diff --git a/docs/phase4-standalone.md b/docs/phase4-standalone.md index 376af75..64fb55e 100755 --- a/docs/phase4-standalone.md +++ b/docs/phase4-standalone.md @@ -585,6 +585,13 @@ Detailed implementation notes for complex sources are in the **Notes** section a ## Notes — Complex Sources +### Project Requirement: HTTP Client Selection +When porting sources from Kotlin to Go, ALWAYS check the Kotlin reference to determine whether the source needs: +- **Normal HTTP client** (`goyomi/internal/httpclient`) - for REST APIs returning JSON +- **FlareSolverr client** (`goyomi/internal/httpclient/flare`) - for JavaScript-rendered pages (uses `network.cloudflareClient` in Kotlin) + +Check in Kotlin: `override val client = network.cloudflareClient` or `network.cloudflareClient.newBuilder()` → needs FlareSolverr + ### `all/mangadex` ⚠️ - Rate limit: 5 req/s (`golang.org/x/time/rate`) - `GetPopularManga` — `GET /manga?order[rating]=desc&includes[]=cover_art&limit=20&offset={(n-1)*20}` diff --git a/sources/base/madtheme/madtheme.go b/sources/base/madtheme/madtheme.go index 3d425a1..1da9ab6 100755 --- a/sources/base/madtheme/madtheme.go +++ b/sources/base/madtheme/madtheme.go @@ -14,7 +14,7 @@ import ( "github.com/PuerkitoBio/goquery" - "goyomi/internal/httpclient" + "goyomi/internal/httpclient/flare" "goyomi/internal/source" "goyomi/sources/base/util" ) @@ -27,12 +27,12 @@ type Config struct { type Source struct { cfg Config - client *httpclient.Client + client *flare.Client id int64 } func New(cfg Config) *Source { - c := httpclient.NewClient(httpclient.WithRateLimit(1, 2)) + c := flare.NewClient(flare.WithRateLimit(1, 2)) return &Source{cfg: cfg, client: c, id: source.GenerateSourceID(cfg.Name, cfg.Lang)} } @@ -42,12 +42,7 @@ func (s *Source) Lang() string { return s.cfg.Lang } func (s *Source) SupportsLatest() bool { return true } func (s *Source) get(ctx context.Context, rawURL string) (*goquery.Document, error) { - req, err := http.NewRequestWithContext(ctx, http.MethodGet, rawURL, nil) - if err != nil { - return nil, err - } - req.Header.Set("Referer", s.cfg.BaseURL+"/") - resp, err := s.client.Do(req) + resp, err := s.client.Get(ctx, rawURL) if err != nil { return nil, err } diff --git a/sources/base/mangabox/mangabox.go b/sources/base/mangabox/mangabox.go index 692f452..ce6d270 100755 --- a/sources/base/mangabox/mangabox.go +++ b/sources/base/mangabox/mangabox.go @@ -14,7 +14,7 @@ import ( "github.com/PuerkitoBio/goquery" - "goyomi/internal/httpclient" + "goyomi/internal/httpclient/flare" "goyomi/internal/source" "goyomi/sources/base/util" ) @@ -30,7 +30,7 @@ type Config struct { type Source struct { cfg Config - client *httpclient.Client + client *flare.Client id int64 } @@ -44,7 +44,7 @@ func New(cfg Config) *Source { if cfg.SimpleQueryPath == "" { cfg.SimpleQueryPath = "search/story" } - c := httpclient.NewClient(httpclient.WithRateLimit(1, 2)) + c := flare.NewClient(flare.WithRateLimit(1, 2)) return &Source{cfg: cfg, client: c, id: source.GenerateSourceID(cfg.Name, cfg.Lang)} } @@ -56,12 +56,7 @@ func (s *Source) SupportsLatest() bool { return true } func (s *Source) base() string { return strings.TrimRight(s.cfg.BaseURL, "/") } func (s *Source) get(ctx context.Context, rawURL string) (*goquery.Document, error) { - req, err := http.NewRequestWithContext(ctx, http.MethodGet, rawURL, nil) - if err != nil { - return nil, err - } - req.Header.Set("Referer", s.cfg.BaseURL+"/") - resp, err := s.client.Do(req) + resp, err := s.client.Get(ctx, rawURL) if err != nil { return nil, err } @@ -73,13 +68,7 @@ func (s *Source) get(ctx context.Context, rawURL string) (*goquery.Document, err } func (s *Source) getJSON(ctx context.Context, rawURL string, out any) error { - req, err := http.NewRequestWithContext(ctx, http.MethodGet, rawURL, nil) - if err != nil { - return err - } - req.Header.Set("Referer", s.cfg.BaseURL+"/") - req.Header.Set("Accept", "application/json") - resp, err := s.client.Do(req) + resp, err := s.client.Get(ctx, rawURL) if err != nil { return err } diff --git a/sources/base/mangacatalog/mangacatalog.go b/sources/base/mangacatalog/mangacatalog.go index 70ef4cc..7218017 100755 --- a/sources/base/mangacatalog/mangacatalog.go +++ b/sources/base/mangacatalog/mangacatalog.go @@ -10,7 +10,7 @@ import ( "github.com/PuerkitoBio/goquery" - "goyomi/internal/httpclient" + "goyomi/internal/httpclient/flare" "goyomi/internal/source" "goyomi/sources/base/util" ) @@ -29,7 +29,7 @@ type Config struct { type Source struct { cfg Config - client *httpclient.Client + client *flare.Client id int64 } @@ -37,7 +37,7 @@ func New(cfg Config) *Source { if len(cfg.SourceList) == 0 { cfg.SourceList = []SourceEntry{{Name: cfg.Name, URL: cfg.BaseURL}} } - c := httpclient.NewClient(httpclient.WithRateLimit(1, 2)) + c := flare.NewClient(flare.WithRateLimit(1, 2)) return &Source{cfg: cfg, client: c, id: source.GenerateSourceID(cfg.Name, cfg.Lang)} } @@ -47,12 +47,7 @@ func (s *Source) Lang() string { return s.cfg.Lang } func (s *Source) SupportsLatest() bool { return false } func (s *Source) get(ctx context.Context, rawURL string) (*goquery.Document, error) { - req, err := http.NewRequestWithContext(ctx, http.MethodGet, rawURL, nil) - if err != nil { - return nil, err - } - req.Header.Set("Referer", s.cfg.BaseURL+"/") - resp, err := s.client.Do(req) + resp, err := s.client.Get(ctx, rawURL) if err != nil { return nil, err } diff --git a/sources/base/mangahub/mangahub.go b/sources/base/mangahub/mangahub.go index bf7e33f..a9f0263 100755 --- a/sources/base/mangahub/mangahub.go +++ b/sources/base/mangahub/mangahub.go @@ -3,7 +3,6 @@ package mangahub import ( - "bytes" "context" "encoding/json" "fmt" @@ -11,7 +10,7 @@ import ( "net/http" "strings" - "goyomi/internal/httpclient" + "goyomi/internal/httpclient/flare" "goyomi/internal/source" "goyomi/sources/base/util" ) @@ -25,7 +24,7 @@ type Config struct { type Source struct { cfg Config - client *httpclient.Client + client *flare.Client id int64 } @@ -33,7 +32,7 @@ func New(cfg Config) *Source { if cfg.APIURL == "" { cfg.APIURL = "https://api.mghubcdn.com" } - c := httpclient.NewClient(httpclient.WithRateLimit(1, 2)) + c := flare.NewClient(flare.WithRateLimit(1, 2)) return &Source{cfg: cfg, client: c, id: source.GenerateSourceID(cfg.Name, cfg.Lang)} } @@ -60,14 +59,7 @@ type mangaDTO struct { func (s *Source) gql(ctx context.Context, query string, vars map[string]any, out any) error { body, _ := json.Marshal(gqlRequest{Query: query, Variables: vars}) - req, err := http.NewRequestWithContext(ctx, http.MethodPost, s.cfg.APIURL+"/graphql", bytes.NewReader(body)) - if err != nil { - return err - } - req.Header.Set("Content-Type", "application/json") - req.Header.Set("Accept", "application/json") - req.Header.Set("x-mhub-access", "auto") - resp, err := s.client.Do(req) + resp, err := s.client.Post(ctx, s.cfg.APIURL+"/graphql", "application/json", strings.NewReader(string(body))) if err != nil { return err }