Skip to content

fix(preview): stop flagging live links as broken - #46

Merged
stahnma merged 1 commit into
mainfrom
fix/preview-false-404s
Nov 21, 2026
Merged

stahnma merged 1 commit into
mainfrom
fix/preview-false-404s

Conversation

@stahnma

@stahnma stahnma commented Nov 21, 2026

Copy link
Copy Markdown
Member

Problem

Links on the front page showed as 404 while loading fine in a browser. Of the 40 most recent links, production flagged 10 as errors. With this branch, only 2 are flagged.

Causes and fixes

Cause Example Fix
Frontend shows data.status || 404, so any error without a status became a 404 FAA PDF, dead trycloudflare host Badge says unreachable when no HTTP response was received
Fake Chrome UA trips bot checks; only 403 triggered a retry textualapp.com (503), bluestarfam.org (403) Try browser, plain and crawler UAs; stop early only on 404/410
Bot protection (DataDome) blocks every server request, whatever the UA surfer.com On 403/429/5xx, build the preview from the latest archive.org snapshot
Non-HTML bodies were parsed as HTML PDFs, images Basic file card based on Content-Type; HTML reads capped at 2 MB
X oEmbed returns 404 for /photo/N URLs x.com/…/photo/1 Strip /photo/N and /video/N before oEmbed
Temporary errors cached for 24h support.google.com (429) 403/429/5xx on links under 10 days old cached for 1h
/api/v1/preview never read its cache (the lookup was dropped with the rate limiter in 61305fd) every page view re-scraped every link New PreviewHandler checks the cache first

New endpoint

GET /api/v1/preview/diagnose?url=… (requires the admin API key; localhost is always allowed) sends HEAD and GET with each user agent and reports status, content type, redirects, timing and errors for each. It then clears the cached preview and fetches a fresh one. Documented in openapi.json.

Still flagged

  • trycloudflare.com link: really dead (DNS name doesn't resolve). Shows unreachable.
  • A new post on a bot-blocking site that archive.org hasn't saved yet still shows a 403 badge.

Testing

  • make test, go vet and git diff --check pass. New tests cover the UA fallback, the PDF card, the TTLs, the X URL fix, the snapshot URL rewrite and the diagnose endpoint.
  • Ran all 40 recent links through production and a local build side by side (results above).
  • Not checked in a browser: how the new badge and the cards render.

Many links on the front page showed as 404 while working in a browser.
The causes, and what this changes:

- The frontend labeled any error without a status as 404. It now
  says "unreachable" when no HTTP response was received.
- The scraper sent a fake Chrome UA and only retried on 403. It now
  tries browser, plain and crawler UAs and stops early only on 404
  or 410.
- Sites behind bot protection (e.g. DataDome) block servers but not
  browsers. On a 403/429/5xx the preview is built from the latest
  archive.org snapshot when one exists.
- Non-HTML resources such as PDFs get a basic file card instead of
  being parsed as HTML.
- X links ending in /photo/N or /video/N are trimmed before oEmbed.
- Possibly transient errors on recent links are cached for 1h.
- /api/v1/preview reads the preview cache again; the lookup was
  dropped when the rate limiter was removed in 61305fd.

Adds GET /api/v1/preview/diagnose (admin) to probe a URL with each
user agent, report the results, and refresh its cached preview.
@stahnma
stahnma merged commit 2494442 into main Nov 21, 2026
1 check passed
@stahnma
stahnma deleted the fix/preview-false-404s branch November 21, 2026 06:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant