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:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user