diff --git a/backend/internal/latest/cover.go b/backend/internal/latest/cover.go index 6e765b0..ebe52e1 100644 --- a/backend/internal/latest/cover.go +++ b/backend/internal/latest/cover.go @@ -145,6 +145,10 @@ func (f *TLSCoverFetcher) Fetch(ctx context.Context, sourceURL string) ([]byte, if err != nil { return nil, "", fmt.Errorf("build cover request: %w", err) } + // cdn.asurascans.com answers Go's default User-Agent with a Cloudflare + // challenge (403, cf-mitigated) and a Chrome one with the image; measured + // 2026-12-04. No TLS fingerprint needed — the UA alone flips it. + req.Header.Set("User-Agent", chromeUA) resp, err := f.client.Do(req) if err != nil { return nil, "", fmt.Errorf("fetch cover: %w", err) diff --git a/backend/internal/latest/cover_fetch_test.go b/backend/internal/latest/cover_fetch_test.go index 600d520..1300bda 100644 --- a/backend/internal/latest/cover_fetch_test.go +++ b/backend/internal/latest/cover_fetch_test.go @@ -228,6 +228,24 @@ func TestCoverFetcherRejectsNonImage(t *testing.T) { } } +// cdn.asurascans.com challenges Go's default User-Agent (measured 2026-12-04), +// so every cover from it failed until the fetcher sent a browser one. +func TestCoverFetcherSendsBrowserUserAgent(t *testing.T) { + client := &http.Client{Transport: roundTripFunc(func(r *http.Request) (*http.Response, error) { + if r.UserAgent() != chromeUA { + return coverResponse(http.StatusForbidden, "text/html", "", []byte("Just a moment...")), nil + } + return coverResponse(http.StatusOK, "image/webp", "", []byte("cover-bytes")), nil + })} + fetcher := newCoverFetcher(client, func(context.Context, string) ([]netip.Addr, error) { + return []netip.Addr{netip.MustParseAddr("198.51.100.10")}, nil + }) + + if _, _, err := fetcher.Fetch(context.Background(), "https://cdn.asurascans.com/asura-images/covers/x.webp"); err != nil { + t.Fatalf("Fetch: %v", err) + } +} + // comix labels its covers "image/jpg", which is not a registered type but is // what the Site actually answers with; the bytes are stored under the real // name so one image cannot land under two spellings. diff --git a/backend/internal/latest/sites.go b/backend/internal/latest/sites.go index 7628a8d..408018a 100644 --- a/backend/internal/latest/sites.go +++ b/backend/internal/latest/sites.go @@ -341,13 +341,27 @@ func comixCoverURL(seriesURL, body string) string { return publishedCoverURL(entry.Poster.Medium) } -// ogImageCover reads the og:image metadata shared by asura, demonic and +// ogImageCover reads the og:image metadata shared by demonic and // lightnovelworld. func ogImageCover(_, body string) (string, bool) { cover := metaContent(body, "property", "og:image") return cover, cover != "" } +// asuraCoverRe reads coverUrl from the astro-island props, in both quote forms +// asuraStatusRe accepts. asura's og:image stopped being the cover (seen +// 2026-12-04): it is now a 1200x630 social card on asurascans.com itself, +// which also challenges every fetch without a Chrome TLS fingerprint. +var asuraCoverRe = regexp.MustCompile(`(?:"|")coverUrl(?:"|"):\[0,(?:"|")(https://[^&"]+)`) + +func asuraCover(_, body string) (string, bool) { + m := asuraCoverRe.FindStringSubmatch(body) + if m == nil { + return "", false + } + return m[1], true +} + func novelfullCoverEntry(_, body string) (string, bool) { cover := metaContent(body, "name", "image") return cover, cover != "" @@ -541,7 +555,7 @@ var sites = map[string]site{ "asura": { Host: "asurascans.com", LatestChapter: asuraLatestChapter, - Cover: ogImageCover, + Cover: asuraCover, Completed: asuraCompleted, Rest: defaultRest, Gap: defaultGap, diff --git a/backend/internal/latest/sites_test.go b/backend/internal/latest/sites_test.go index 40d3926..dc85eee 100644 --- a/backend/internal/latest/sites_test.go +++ b/backend/internal/latest/sites_test.go @@ -286,9 +286,11 @@ const lnwOngoingFixture = `` -// Trimmed from https://asurascans.com/comics/chronicles-of-the-demon-faction-f886a8af -// (redirected to ...-00dcbf97) on 2026-08-10. -const asuraCoverFixture = `` +// Trimmed from https://asurascans.com/comics/chronicles-of-the-demon-faction-ce13e3a9 +// on 2026-12-04. og:image is a social card, not the cover; the cover is the +// astro-island coverUrl prop. +const asuraCoverFixture = `` + + `` // Trimmed from https://demonicscans.org/manga/Catastrophic-Necromancer on 2026-08-10. // The source publishes the raw space in this URL. @@ -321,7 +323,7 @@ func TestCoverFrom(t *testing.T) { wantCover string }{ { - name: "asura uses published metadata URL", + name: "asura reads coverUrl prop, not og social card", site: "asura", body: asuraCoverFixture, wantOK: true, wantCover: "https://cdn.asurascans.com/asura-images/covers/chronicles-of-the-demon-faction.d4dcb8.webp", }, @@ -352,10 +354,10 @@ func TestCoverFrom(t *testing.T) { }, { name: "later metadata cover survives empty match", - site: "asura", - body: `` + asuraCoverFixture, + site: "demonic", + body: `` + demonicCoverFixture, wantOK: true, - wantCover: "https://cdn.asurascans.com/asura-images/covers/chronicles-of-the-demon-faction.d4dcb8.webp", + wantCover: "https://readermc.org/images/thumbnails/Catastrophic%20Necromancer.webp", }, { name: "page without cover is empty",