Unify page routing and harden acquire wiring after review (#62)
This commit is contained in:
@@ -3,7 +3,6 @@ package latest
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"slices"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -36,11 +35,9 @@ type Acquirer struct {
|
||||
// BrowserFetch disables acquisition entirely.
|
||||
Fetch Fetcher
|
||||
// BrowserFetch retrieves kagane and novelfull pages through the browser
|
||||
// sidecar, which is the only thing that clears their Cloudflare
|
||||
// challenge. Nil leaves those Sites unacquired; kagane never falls back
|
||||
// to Fetch (a plain request only retrieves a challenge page), while
|
||||
// novelfull does, because its challenge is a live time-varying fact and
|
||||
// its cover bytes never need the browser.
|
||||
// sidecar, the only thing that clears their Cloudflare challenge. The
|
||||
// per-site fallback policy lives in fetcherFor. Nil leaves those Sites
|
||||
// unacquired when no fallback applies.
|
||||
BrowserFetch Fetcher
|
||||
// Covers retrieves the cover bytes. Nil leaves the Cover blank and the
|
||||
// chapter half working.
|
||||
@@ -108,7 +105,7 @@ func (a *Acquirer) acquire(ctx context.Context, sr store.Series) {
|
||||
return
|
||||
}
|
||||
|
||||
f := a.fetcherFor(sr.Site)
|
||||
f := fetcherFor(sr.Site, a.BrowserFetch, a.Fetch)
|
||||
if f == nil {
|
||||
log.Printf("acquire %q: no fetcher for site %q", sr.Key(), sr.Site)
|
||||
return
|
||||
@@ -148,24 +145,3 @@ func (a *Acquirer) acquire(ctx context.Context, sr store.Series) {
|
||||
log.Printf("acquire %q: persist cover: %v", sr.Key(), err)
|
||||
}
|
||||
}
|
||||
|
||||
// fetcherFor returns the fetcher a site's page needs, or nil when the site
|
||||
// cannot be fetched at all right now. kagane and novelfull pages sit behind a
|
||||
// Cloudflare JavaScript challenge, so they prefer the browser; novelfull alone
|
||||
// falls back to the plain-TLS fetcher when no browser is configured, because
|
||||
// its challenge is a live time-varying fact (AGENTS.md) and its cover bytes
|
||||
// never need the browser. kagane never falls back: a plain fetch of a kagane
|
||||
// page or cover would only ever retrieve a challenge page.
|
||||
func (a *Acquirer) fetcherFor(site string) Fetcher {
|
||||
switch {
|
||||
case site == "kagane":
|
||||
return a.BrowserFetch
|
||||
case slices.Contains(browserBackedSites, site): // novelfull
|
||||
if a.BrowserFetch != nil {
|
||||
return a.BrowserFetch
|
||||
}
|
||||
return a.Fetch
|
||||
default:
|
||||
return a.Fetch
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user