Skip to content

Commit

Permalink
bluesky.to_as1: embed external bug fix for thumb blob vs URL
Browse files Browse the repository at this point in the history
confusing that it's blob in some places, string URL in others :/
  • Loading branch information
snarfed committed Apr 17, 2024
1 parent 738e231 commit a14c80a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
9 changes: 7 additions & 2 deletions granary/bluesky.py
Expand Up @@ -989,8 +989,13 @@ def to_as1(obj, type=None, uri=None, repo_did=None, repo_handle=None,
'displayName': obj.get('title'),
'summary': obj.get('description'),
}
if repo_did and pds:
ret['image'] = blob_to_url(blob=obj.get('thumb'), repo_did=repo_did, pds=pds)

thumb = obj.get('thumb')
if type == 'app.bsky.embed.external#external':
if repo_did and pds:
ret['image'] = blob_to_url(blob=thumb, repo_did=repo_did, pds=pds)
else:
ret['image'] = thumb

elif type == 'app.bsky.embed.record':
return None
Expand Down
21 changes: 8 additions & 13 deletions granary/tests/test_bluesky.py
Expand Up @@ -1334,21 +1334,16 @@ def test_to_as1_embed(self):
def test_to_as1_embed_post_view(self):
self.assert_equals(POST_AS_EMBED, to_as1(POST_VIEW_BSKY_EMBED))

def test_to_as1_embed_post_view_thumb_blob(self):
post_bsky = copy.deepcopy(POST_BSKY_EMBED)
post_bsky['embed']['external']['thumb'] = NEW_BLOB
def test_to_as1_embed_post_view_thumb_url(self):
post_bsky = copy.deepcopy(POST_VIEW_BSKY_EMBED)
post_bsky['embed']['external']['thumb'] = 'http://thu/mb'

# without repo_did/repo_handle
self.assert_equals(POST_AS_EMBED, to_as1(POST_VIEW_BSKY_EMBED))

# with repo_did/repo_handle
post_as = copy.deepcopy(POST_AS_EMBED)
del post_as['id']
del post_as['url']
post_as['author'] = 'did:plc:foo'
post_as['attachments'][0]['image'] = 'https://bsky.social/xrpc/com.atproto.sync.getBlob?did=did:plc:foo&cid=bafkreim'
self.assert_equals(
post_as, to_as1(post_bsky, repo_did='did:plc:foo', repo_handle='han.dull'))
post_as['attachments'][0]['image'] = 'http://thu/mb'
self.assert_equals(post_as, to_as1(post_bsky))
self.assert_equals(post_as, to_as1(post_bsky, repo_did='did:plc:foo',
repo_handle='han.dull'),
ignore=['author'])

def test_to_as1_embed_with_blobs(self):
post_bsky = copy.deepcopy(POST_BSKY_EMBED)
Expand Down

0 comments on commit a14c80a

Please sign in to comment.