Add web link preview unfurling#367
Merged
Merged
Conversation
Reviewer's GuideAdds a server-side link unfurling pipeline (with SSRF-aware URL validation) and wires it into the web app as the primary link preview provider, introduces hover preview cards for external-link mentions while deferring fetches until in-view, ensures the sidebar auto-expands to reveal the selected view on load, and refines image loading logic so slow external images do not appear as upload-pending. Sequence diagram for server-side link preview unfurling with SSRF-aware redirectssequenceDiagram
participant UserBrowser
participant MentionExternalLink
participant link_preview as fetchLinkPreviewData
participant provider as appflowyLinkPreviewProvider
participant ApiRoute as api_link_preview_handler
participant Unfurl as unfurl
participant FetchHtml as fetchHtmlFollowingAllowedRedirects
participant UrlSafety as isAllowedHttpUrl
participant ExternalSite
UserBrowser->>MentionExternalLink: hover external-link mention
MentionExternalLink->>link_preview: fetchLinkPreviewData(url)
link_preview->>provider: appflowyLinkPreviewProvider.fetch(context)
provider->>ApiRoute: GET /api/link-preview?url=normalizedUrl
ApiRoute->>UrlSafety: isAllowedHttpUrl(parsedUrl)
UrlSafety-->>ApiRoute: allowed / blocked
alt url blocked
ApiRoute-->>provider: 400 Blocked host
provider-->>link_preview: undefined (fallback to other providers)
else url allowed
ApiRoute->>Unfurl: unfurl(url)
Unfurl->>FetchHtml: fetchHtmlFollowingAllowedRedirects(initialUrl, signal)
loop redirects <= MAX_REDIRECTS
FetchHtml->>UrlSafety: isAllowedHttpUrl(currentUrl)
UrlSafety-->>FetchHtml: allow / block
alt redirect response
FetchHtml->>ExternalSite: fetch(nextUrl, redirect=manual)
else final response
FetchHtml-->>Unfurl: {response, url}
end
end
Unfurl-->>ApiRoute: UnfurlResult (title, description, image, logo)
ApiRoute-->>provider: 200 JSON
provider-->>link_preview: LinkPreviewData
link_preview-->>MentionExternalLink: LinkPreviewData
MentionExternalLink-->>UserBrowser: Show MentionLinkPreviewCard in Popover
end
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In
appflowyLinkPreviewProvider.fetch, consider wrapping thefetchcall in a try/catch and returningundefinedon network errors so this provider consistently fails open and allows lower-priority providers to run, matching the behavior you already implemented for non-OK responses and invalid JSON.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `appflowyLinkPreviewProvider.fetch`, consider wrapping the `fetch` call in a try/catch and returning `undefined` on network errors so this provider consistently fails open and allows lower-priority providers to run, matching the behavior you already implemented for non-OK responses and invalid JSON.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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.
Summary
Review
Tests
Summary by Sourcery
Add a server-side link unfurling endpoint and wire it into web link previews while improving sidebar reveal behavior and upload status handling.
New Features:
Enhancements:
Tests: