Changeset 041a0df in Klonkt


Ignore:
Timestamp:
06/28/2026 05:38:13 PM (2 months ago)
Author:
Robin Genis <roboburr@…>
Branches:
main
Children:
492fc20
Parents:
3038fc9
Message:

fix(images): downscale remote (federated) covers + feed media via the proxy

thumb() only rewrote LOCAL /media covers; a remote (federated) cover URL passed through
unchanged → loaded full-res from the origin → browser-downscaled jagged (esp. line-art).
Route remote http(s) covers + timeline feed media through the same signed downscale proxy.

  • middleware/render.js — thumb() proxies remote http(s) URLs (like avatar())
  • views/pages/news.ejs — feed media <img> uses thumb(m.url, 640) (link stays the original)
Location:
src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/middleware/render.js

    r3038fc9 r041a0df  
    163163    // Rewrite a local /media/<file> cover to its on-demand downscaled thumbnail
    164164    // (crisp grid/list images). External URLs + already-thumb URLs pass through.
    165     thumb: (url, w) => (typeof url === 'string' && url.startsWith('/media/') && !url.startsWith('/media/thumb/'))
    166       ? `/media/thumb/${w || 480}/${url.slice(7)}`
    167       : url,
     165    thumb: (url, w) => {
     166      if (!url || typeof url !== 'string') return url;
     167      // Local cover → local thumb route; remote (federated) cover → signed downscale
     168      // proxy (same as avatars), so remote line-art covers aren't browser-downscaled jagged.
     169      if (url.startsWith('/media/') && !url.startsWith('/media/thumb/')) return `/media/thumb/${w || 480}/${url.slice(7)}`;
     170      if (/^https?:\/\//i.test(url)) return imgProxyUrl(url, w || 480);
     171      return url;
     172    },
    168173    // Crisp avatars: a local /media avatar goes through the local thumb route; a REMOTE
    169174    // (fediverse) avatar through the signed downscaling proxy. Same downscale, the remote
  • src/views/pages/news.ejs

    r3038fc9 r041a0df  
    118118            <div class="tl-media">
    119119              <% imgs.forEach(function(m){ %>
    120                 <a class="tl-media-img" href="<%= m.url %>" target="_blank" rel="noopener"><img src="<%= m.url %>" alt="" loading="lazy" decoding="async"></a>
     120                <a class="tl-media-img" href="<%= m.url %>" target="_blank" rel="noopener"><img src="<%= thumb(m.url, 640) %>" alt="" loading="lazy" decoding="async"></a>
    121121              <% }); %>
    122122            </div>
Note: See TracChangeset for help on using the changeset viewer.