Private
Public Access
Expand direct image links instead of showing nothing (#43 follow-up)
A URL that points straight at an image file (Content-Type: image/*) has no HTML to scrape Open Graph tags from, so the fetch found nothing and the message showed no preview at all -- reported against https://imgs.xkcd.com/comics/creepy.png. link_preview_service now recognizes an allowed image content-type (same list storage.py uses for uploads) before falling through to the HTML/og: path, and returns the URL itself as the preview (LinkPreview.is_image). No need to download the body -- the already-SSRF-validated URL is the image. The frontend renders that case as a real expandable image (message-image + lightbox, same as an actual attachment) instead of the small title+description card, which would have nothing to show anyway. Verified end-to-end against the reported URL. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -23,6 +23,12 @@ class LinkPreview(Base):
|
||||
description: Mapped[str | None] = mapped_column(String(1000))
|
||||
image_url: Mapped[str | None] = mapped_column(String(2048))
|
||||
site_name: Mapped[str | None] = mapped_column(String(200))
|
||||
# A direct link to an image file (Content-Type: image/*, no HTML to
|
||||
# scrape og: tags from) gets image_url = the URL itself and no
|
||||
# title/description/site_name -- this flags that case so the frontend
|
||||
# renders it as an actual expanded image rather than the small
|
||||
# title+description unfurl card.
|
||||
is_image: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)
|
||||
# Cached separately from a "no row yet" state so a URL that genuinely
|
||||
# doesn't unfurl (no title, fetch error, blocked by SSRF checks) isn't
|
||||
# re-fetched on every message that references it within the TTL.
|
||||
|
||||
Reference in New Issue
Block a user