Skip to content

Commit

Permalink
bluesky.to_as1: add support for app.bsky.feed.generator
Browse files Browse the repository at this point in the history
  • Loading branch information
snarfed committed May 3, 2024
1 parent 84e3989 commit 788815b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ Changelog
* `to_as1`:
* Add support for:
* `app.bsky.feed.defs#notFoundPost`
* `app.bsky.feed.generator`
* `app.bsky.graph.block`
* `com.atproto.admin.defs#repoRef`
* `com.atproto.moderation.createReport#input`
Expand Down
10 changes: 8 additions & 2 deletions granary/bluesky.py
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,7 @@ def to_as1(obj, type=None, uri=None, repo_did=None, repo_handle=None,
'app.bsky.actor.defs#profileView',
'app.bsky.actor.defs#profileViewBasic',
'app.bsky.actor.defs#profileViewDetailed',
'app.bsky.feed.generator',
):
images = [{'url': obj.get('avatar')}]
banner = obj.get('banner')
Expand All @@ -863,19 +864,24 @@ def to_as1(obj, type=None, uri=None, repo_did=None, repo_handle=None,
urls.append(f'https://{handle}/')
elif did and did.startswith('did:web:'):
urls.extend([did_web_to_url(did), Bluesky.user_url(did)])
# TODO: feed generators have different URLs, they're in arbitrary repos.
# example:
# https://bsky.app/profile/did:plc:q6kan4oxddhgwnk4yjwvviao/feed/aaamsu44py5vg
# at://did:plc:q6kan4oxddhgwnk4yjwvviao/app.bsky.feed.generator/aaamsu44py5vg

ret = {
'objectType': 'person',
'objectType': 'service' if type == 'app.bsky.feed.generator' else 'person',
'id': did,
'url': urls,
'displayName': obj.get('displayName'),
'username': obj.get('handle') or repo_handle,
'summary': obj.get('description'),
'image': images,
'published': obj.get('createdAt'),
}

# avatar and banner are blobs in app.bsky.actor.profile; convert to URLs
if type == 'app.bsky.actor.profile':
if type in ('app.bsky.actor.profile', 'app.bsky.feed.generator'):
repo_did = repo_did or did
if repo_did and pds:
for img in ret['image']:
Expand Down
26 changes: 26 additions & 0 deletions granary/tests/test_bluesky.py
Original file line number Diff line number Diff line change
Expand Up @@ -1551,6 +1551,32 @@ def test_to_as1_createReport(self):
},
}, repo_did='did:bob'))

def test_to_as1_feed_generator(self):
self.assert_equals({
'objectType': 'service',
'id': 'did:web:skyfeed.me',
'displayName': 'skyfeeeed',
'summary': 'its-a skyfeed a-me',
'image': [{
'url': 'https://bsky.social/xrpc/com.atproto.sync.getBlob?did=did:bob&cid=bafkreim',
}],
'published': '2024-01-09T00:22:39.703Z',
'url': [
'https://skyfeed.me/',
# TODO: this is wrong, feed generators have non-profile URLs in
# arbitrary repos, this should be
# https://bsky.app/profile/did:plc:q6kan4oxddhgwnk4yjwvviao/feed/aaamsu44py5vg
'https://bsky.app/profile/did:web:skyfeed.me',
],
}, to_as1({
'$type': 'app.bsky.feed.generator',
'did': 'did:web:skyfeed.me',
'displayName': 'skyfeeeed',
'description': 'its-a skyfeed a-me',
'avatar': NEW_BLOB,
'createdAt': '2024-01-09T00:22:39.703Z',
}, repo_did='did:bob'))

def test_blob_to_url(self):
self.assertIsNone(blob_to_url(blob={'foo': 'bar'}, repo_did='x', pds='y'))
self.assertEqual(NEW_BLOB_URL, blob_to_url(blob=NEW_BLOB,
Expand Down

0 comments on commit 788815b

Please sign in to comment.