snarfed / bridgy

📣 Connects your web site to social media. Likes, retweets, mentions, cross-posting, and more...
https://brid.gy
Creative Commons Zero v1.0 Universal
702 stars 51 forks source link

Images in backfed replies from Mastodon are unreliable #1675

Closed davidcelis closed 4 months ago

davidcelis commented 4 months ago

I've been backfeeding interactions from Mastodon back to my personal site for a while now, but I only started showing them off today. For the most part, everything is working great! However, if people reply to my post with an image, they pretty much never seem to load. An example can be seen on this post:

https://davidcel.is/notes/1756777068221628308

I was expecting this to happen for posts that get deleted (I have some friends/followers that auto-delete their posts after a certain amount of time). However, this happens regardless of whether or not the original post still exists. In this case, it does:

https://xoxo.zone/@danilo@hachyderm.io/111914757048130741

It looks like, at least at the time of this writing, that image lives here: https://xoxo-media.sfo2.cdn.digitaloceanspaces.com/cache/media_attachments/files/111/914/756/845/002/235/original/42975a5a216beae9.jpeg

My webmention, however, included this URL: https://xoxo-media.sfo2.cdn.digitaloceanspaces.com/cache/media_attachments/files/111/914/756/845/002/235/original/530f9cc4f42661f2.jpeg

My assumption is that this is because cached images in Mastodon typically have a retention period and that they're being destroyed, then re-cached whenever they're viewed again. This makes me wonder if it'd be better (if possible) for Bridgy to fetch the image from the post's server of origin? That way Bridgy users would get a persistent URL.

snarfed commented 4 months ago

Thanks for filing, and for the sleuthing! I think your guess is right.

Bridgy currently pulls image URL from media_attachments.url in the Mastodon API's status object: https://docs.joinmastodon.org/entities/MediaAttachment/ . This generally works, but you're right, if they're cached with a short expiration, and your webmention receiver doesn't have its own image cache, that's a problem.

Looks like remote_url, https://docs.joinmastodon.org/entities/MediaAttachment/#remote_url , is the source instance's URL. Hopefully it's more long lived? Definitely worth a try!

$ curl -v -H 'Authorization: Bearer ...' https://xoxo.zone/api/v1/statuses/111914757048130741
  ...
  "media_attachments": [
    {
      "id": "111914756845002235",
      "type": "image",
      "url": "https://xoxo-media.sfo2.cdn.digitaloceanspaces.com/cache/media_attachments/files/111/914/756/845/002/235/original/42975a5a216beae9.jpeg",
      "preview_url": "https://xoxo-media.sfo2.cdn.digitaloceanspaces.com/cache/media_attachments/files/111/914/756/845/002/235/small/42975a5a216beae9.jpeg",
      "remote_url": "https://media.hachyderm.io/media_attachments/files/111/914/756/560/090/313/original/e2c36af5ef792bba.jpeg",
   ...
snarfed commented 4 months ago

Deployed that fix. Thanks again for reporting @davidcelis!

davidcelis commented 4 months ago

thanks for the quick fix, @snarfed! it's always a joy to open issues on bridgy (truly, no sarcasm 😄)