Skip to content

[xExtension-ImageProxy] Proxy the thumbnails shown in the list of articles - #579

Open
NopeCharon wants to merge 1 commit into
FreshRSS:mainfrom
NopeCharon:imageproxy-thumbnails
Open

NopeCharon wants to merge 1 commit into
FreshRSS:mainfrom
NopeCharon:imageproxy-thumbnails

Conversation

@NopeCharon

Copy link
Copy Markdown
Contributor

Summary

With the thumbnail display option enabled, the list of articles still loaded the thumbnails directly from the source, even though the article content was proxied (#200, also mentioned in #206). FreshRSS takes these thumbnails from:

  • the thumbnail attribute of the entry, e.g. an item-level <media:thumbnail>
  • the thumbnails of the enclosures, e.g. <media:thumbnail> inside a <media:group>, as in YouTube feeds
  • the images of the content, which were already proxied

The entry_before_display hook now proxies the first two as well:

  • FreshRSS stores these URLs HTML-encoded, so the new getProxyImageHtmlUri() decodes them, proxies them and encodes the result again (e.g. ?w=1&amp;h=2, or the & of a proxy URL like the nginx example in the README)
  • when the enclosures are displayed, FreshRSS appends the thumbnail to the content unless its URL is already there. So the thumbnail attribute is only proxied when the proxied URL is found in the proxied content, which is the case when the content shows the thumbnail as an image. If the content only links to the image (<a href="…">), the thumbnail keeps its original URL instead of being shown twice. When the enclosures are hidden, the thumbnail is always proxied
  • the thumbnails of the enclosures are not compared to the content, so they are always proxied
  • regression tests for the HTML-encoded URLs, version 1.1.1 and a changelog entry

Image enclosures used as a thumbnail when the feed has no thumbnail are not changed: proxying them would change the enclosure URLs that the APIs return.

Fixes #200

Validation

  • php tests/ImageProxyTest.php on PHP 8.1 and 8.5 (44 assertions). The new test fails on main (getProxyImageHtmlUri() does not exist)
  • end to end with FreshRSS edge (PHP 8.5, SQLite) and the extension enabled. I used a local feed with an item <media:thumbnail> (with &amp; in its URL), a <media:group> thumbnail, a thumbnail that is also a body image, and a thumbnail that the body only links to. Then I fetched the normal view with the landscape thumbnails enabled:
    • on main, all four list thumbnails use the original URLs
    • with this change, the first three use the proxy and the linked one keeps its original URL. The article content is byte-for-byte the same as on main, so no image is duplicated
    • with Show enclosures disabled, all four list thumbnails use the proxy
    • with proxy_url = https://www.example.org/proxy?key=changeme&url=, scheme_include = 1 and url_encode = 0, the thumbnails are proxied and correctly encoded (&amp;), with no duplicates
    • the RSS output (a=rss) now also proxies <media:thumbnail>, like it already proxied the description
  • php-lint, phpcs, phpstan (with ../FreshRSS, on PHP 8.1 and 8.5) and markdownlint

…icles

The thumbnails that FreshRSS shows in the list of articles (when the
"thumbnail" display option is enabled) come from the `thumbnail` attribute
of the entry (e.g. an item-level `<media:thumbnail>`) or from the
thumbnails of its enclosures (e.g. `<media:thumbnail>` inside a
`<media:group>`, as in YouTube feeds). The extension only proxied the
content, so these thumbnails were still loaded directly from the source.

The `entry_before_display` hook now also proxies those URLs. They are
stored HTML-encoded, so the new `getProxyImageHtmlUri()` decodes them
before proxying and encodes the result again.

When the enclosures are displayed, FreshRSS appends the thumbnail to the
content unless its URL is found there. The thumbnail attribute is
therefore only proxied when the proxied URL is part of the proxied content
(which is the case when the content shows the thumbnail as an image), so
that it is never displayed twice. The thumbnails of enclosures are not
compared to the content and are always proxied.

Bump the version to 1.1.1 and add a changelog entry.

Fixes FreshRSS#200
@Alkarex

Alkarex commented Nov 13, 2026

Copy link
Copy Markdown
Member

Let's finalise #578 first

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.

[ImageProxy] Media thumbnails not proxied

2 participants