From 87038d39157476a526a6bd7ce9f566679dd1fb08 Mon Sep 17 00:00:00 2001 From: Joel Auterson Date: Mon, 30 Oct 2023 18:25:53 +0000 Subject: [PATCH] Canonicalise AT URIs to bsky.app URLs --- bluesky.py | 6 +++++- tests/test_bluesky.py | 7 ++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/bluesky.py b/bluesky.py index 355109f2..1371af51 100644 --- a/bluesky.py +++ b/bluesky.py @@ -75,8 +75,12 @@ def button_html(cls, feature, **kwargs): def canonicalize_url(self, url, **kwargs): """Canonicalizes a post or object URL. - Overrides :class:`Source`'s to convert ``staging.bsky.app`` to ``bsky.app``. + Overrides :class:`Source`'s to convert ``staging.bsky.app`` to ``bsky.app``, + and to convert at:// URIs to bsky.app URLs. """ + if url.startswith('at://'): + url = gr_bluesky.at_uri_to_web_url(url, handle=self.username) + url = url.replace('https://staging.bsky.app/', 'https://bsky.app/') return super().canonicalize_url(url) diff --git a/tests/test_bluesky.py b/tests/test_bluesky.py index 44174af1..edc7c076 100644 --- a/tests/test_bluesky.py +++ b/tests/test_bluesky.py @@ -48,11 +48,6 @@ def test_new(self): def test_format_for_source_url(self): self.assertEqual('at%253A%252F%252Fid', self.bsky.format_for_source_url('at://id')) - def test_canonicalize_url(self): - good = 'https://bsky.app/profile/alice.com' - self.assertEqual(good, self.bsky.canonicalize_url(good)) - self.assertEqual(good, self.bsky.canonicalize_url('http://bsky.app/profile/alice.com')) - def test_post_id(self): good = 'at://did:web:alice.com/app.bsky.feed.post/123' self.assertEqual(good, self.bsky.post_id(good)) @@ -64,5 +59,7 @@ def test_canonicalize_url(self): ('https://bsky.app/foo', 'https://bsky.app/foo'), ('http://bsky.app/foo', 'https://bsky.app/foo'), ('https://staging.bsky.app/foo', 'https://bsky.app/foo'), + ('at://did:web:alice.com', 'https://bsky.app/profile/alice.com'), + ('at://did:web:alice.com/app.bsky.feed.post/123', 'https://bsky.app/profile/alice.com/post/123'), ]: self.assertEqual(expected, self.bsky.canonicalize_url(input))