From 0aa543293f8d6ce71a42a95f855fa54b11d8e715 Mon Sep 17 00:00:00 2001 From: Ryan Barrett Date: Mon, 26 Feb 2024 14:03:19 -0800 Subject: [PATCH] mastodon: prefer `media_attachments.remote_url` when available ...since it may be more long-lived than `url` for remote statuses. fixes snarfed/bridgy#1675 --- README.md | 1 + granary/mastodon.py | 2 +- granary/tests/test_mastodon.py | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b444a5e2..9673f464 100644 --- a/README.md +++ b/README.md @@ -346,6 +346,7 @@ Changelog * `mastodon`: * `get_activities` bug fix: use query params for `/api/v1/notifications` API call, not JSON body. * Convert HTTP 200 responses with `error` JSON field (eg from Sharkey) to 400/401 exceptions. + * Prefer `media_attachments.remote_url` when available since it may be more long-lived than `url` for remote statuses ([bridgy#1675](https://github.com/snarfed/bridgy/issues/1675)). * `microformats2`: * `object_to_json` bug fix: handle singular `inReplyTo`. * `nostr:` diff --git a/granary/mastodon.py b/granary/mastodon.py index aa161703..83255f45 100644 --- a/granary/mastodon.py +++ b/granary/mastodon.py @@ -375,7 +375,7 @@ def status_to_object(self, status): 'objectType': MEDIA_TYPES.get(type), 'displayName': desc, } - url = media.get('url') + url = media.get('remote_url') or media.get('url') if type == 'image': att['image'] = { 'url': url, diff --git a/granary/tests/test_mastodon.py b/granary/tests/test_mastodon.py index 09847376..b3cc4334 100644 --- a/granary/tests/test_mastodon.py +++ b/granary/tests/test_mastodon.py @@ -203,8 +203,9 @@ def tag_uri(name): }, { 'id': '444', 'type': 'gifv', - 'url': 'http://foo.com/video.mp4', + 'url': 'http://use/remote/url/instead', 'preview_url': 'http://foo.com/poster.png', + 'remote_url': 'http://foo.com/video.mp4', 'description': 'a fun video', 'meta': { 'width': 640,