Repository navigation
fix(preview): stop flagging live links as broken - #46
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
data.status || 404, so any error without a status became a 404unreachablewhen no HTTP response was receivedContent-Type; HTML reads capped at 2 MB/photo/NURLs/photo/Nand/video/Nbefore oEmbed/api/v1/previewnever read its cache (the lookup was dropped with the rate limiter in 61305fd)PreviewHandlerchecks the cache firstNew 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 inopenapi.json.Still flagged
unreachable.Testing
make test,go vetandgit diff --checkpass. New tests cover the UA fallback, the PDF card, the TTLs, the X URL fix, the snapshot URL rewrite and the diagnose endpoint.