Repository navigation
Conversation
fguillot
left a comment
There was a problem hiding this comment.
Few blockers:
- Fetches block the refresh worker. Each uncached tweet is fetched one at a time with the full HTTP timeout, so a slow syndication endpoint can hold up refreshes for every other feed.
- Nested blockquotes duplicate media. An outer blockquote that wraps a tweet embed matches the same status link, so the media gets appended twice.
Most of this comes from doing network I/O inside a rewrite rule, which runs on every entry at every refresh. Could you move the fetch into the processor and only run it for new entries (entryIsNew || forceRefresh), the way Bilibili/YouTube watch time works? That also removes the need for the in-memory cache.
ac53cf8 to
d4e22c6
Compare
|
Thanks, both fair. I reworked it:
If you'd rather have this as a per-feed setting than an instance-wide option, I'm happy to switch it. |
Documents the FETCH_TWEET_EMBEDS option added in miniflux/v2#4612.
Embedded tweets reach the reader as a bare blockquote: the sanitizer drops X's widget script, so photos and videos are lost and links stay as opaque t.co URLs. When FETCH_TWEET_EMBEDS is enabled, the processor finds blockquotes whose last link points to a tweet, fetches the tweet from the syndication endpoint used by X's embed widget, and: - appends the tweet's photos as <img> and its videos and GIFs as <video>, using the highest bitrate MP4 and the thumbnail as poster - replaces t.co links with the URLs they point to, and drops the media placeholder link As with the crawler and watch times, tweets are only fetched for new entries or on a forced refresh. Existing entries containing an embedded tweet are left out of the update, so they keep the stored media instead of being replaced by the feed's copy without it. Each tweet is fetched at most once per refresh. After a request fails, the rest of the refresh skips the endpoint, so a slow endpoint delays it by one timeout at most. Deleted or protected tweets don't count as failures. If a fetch fails, the content is left unchanged. A link inside a nested blockquote belongs to that blockquote, so a quote wrapping a tweet embed doesn't get the tweet's media a second time.
d4e22c6 to
e41a884
Compare
|
Rebased onto main (a5ff7e7). After 3070c7f, forbidigo flagged the three
The rendered output is unchanged (the existing tests compare full HTML). I added a test for a paragraph that holds only the media's t.co link, since that's the case the node version could get wrong. golangci-lint is clean. |
Have you followed these guidelines?
Embedded tweets show up in Miniflux as a bare blockquote. The sanitizer (correctly) drops X's widget script, so photos and videos are lost and links stay as opaque
t.coURLs. News sites like MacRumors, 9to5Mac and Ars Technica embed tweets often, and the media is usually the point of the embed.This adds an opt-in
FETCH_TWEET_EMBEDSoption. For each blockquote whose last link points to a tweet, the processor fetches the tweet from the syndication endpoint X's own embed widget uses (cdn.syndication.twimg.com/tweet-result), then:<img>, and videos and GIFs as<video>(highest bitrate MP4, thumbnail as poster)t.colinks with the URLs they point to, and drops the media placeholder linkLike the crawler and the watch time fetches, it only runs for new entries or on a forced refresh. Non-crawler feeds update existing entries on every refresh, which would replace the expanded content with the feed's copy, so existing entries with a tweet embed are left out of the update unless the refresh is forced. Other entries update normally.
Each tweet is fetched at most once per refresh. After a failed request (timeout, etc) the rest of the refresh skips the endpoint, so a slow endpoint delays it by one timeout at most; deleted / protected tweets don't count as failures. If a fetch fails, the content is left as it was. Requests go through the fetcher with the configured timeout and proxy rotator, the same way the Bilibili watch time fetch does.
A couple of things reviewers should know:
tokenparameter but doesn't validate it, so Miniflux sends a constant. If X changes or removes the endpoint, entries just stop getting media and nothing else changes.video.twimg.com, which returns 403 when the request has aRefererfrom another site. The web UI sends no referrer, so it plays fine there. API clients that send one need the media proxy withvideoinMEDIA_PROXY_RESOURCE_TYPES. I left the<video>element withoutwidth/heightsince the reader stylesheet doesn't give videosheight: auto, and the attributes leave a tall empty box when the video is scaled down.Testing: unit tests cover photos, videos, non-tweet and nested blockquotes, fetch failures (including skipping the endpoint after a failed request), tweets without media, unsafe URLs, fetching each tweet once, and the
t.coexpansion (including escaping and rejecting non-http(s) destinations).make testpasses with-race. I'd been running the earlier rewrite rule version on my own instance against MacRumors, 9to5Mac and Ars Technica; this version hasn't been deployed there yet.Docs: miniflux/website#139 adds the option to the configuration page.
No breaking changes; nothing runs unless
FETCH_TWEET_EMBEDS=1.