fix: update HTTP client to flare for Batch 4 sources

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
This commit is contained in:
achmad
2026-05-13 21:35:10 +07:00
parent 46f930718c
commit 71ef2d24fa
5 changed files with 24 additions and 46 deletions
+7
View File
@@ -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}`
+4 -9
View File
@@ -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
}
+5 -16
View File
@@ -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
}
+4 -9
View File
@@ -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
}
+4 -12
View File
@@ -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
}