bridgy-fed/xrpc_actor.py

65 wiersze
1.7 KiB
Python
Czysty Zwykły widok Historia

"""app.bsky.actor.* XRPC methods."""
2022-12-28 17:27:42 +00:00
import logging
import json
import re
from flask import g
noop, lint fixes from flake8 remaining: $ flake8 --extend-ignore=E501 *.py tests/*.py "pyflakes" failed during execution due to "'FlakesChecker' object has no attribute 'NAMEDEXPR'" Run flake8 with greater verbosity to see more details activitypub.py:15:1: F401 'oauth_dropins.webutil.util.json_loads' imported but unused activitypub.py:36:1: F401 'web' imported but unused activitypub.py:48:1: E302 expected 2 blank lines, found 1 activitypub.py:51:9: F811 redefinition of unused 'web' from line 36 app.py:6:1: F401 'flask_app.app' imported but unused app.py:9:1: F401 'activitypub' imported but unused app.py:9:1: F401 'convert' imported but unused app.py:9:1: F401 'follow' imported but unused app.py:9:1: F401 'pages' imported but unused app.py:9:1: F401 'redirect' imported but unused app.py:9:1: F401 'superfeedr' imported but unused app.py:9:1: F401 'ui' imported but unused app.py:9:1: F401 'webfinger' imported but unused app.py:9:1: F401 'web' imported but unused app.py:9:1: F401 'xrpc_actor' imported but unused app.py:9:1: F401 'xrpc_feed' imported but unused app.py:9:1: F401 'xrpc_graph' imported but unused app.py:9:19: E401 multiple imports on one line models.py:19:1: F401 'oauth_dropins.webutil.util.json_loads' imported but unused models.py:364:31: E114 indentation is not a multiple of four (comment) models.py:364:31: E116 unexpected indentation (comment) protocol.py:17:1: F401 'oauth_dropins.webutil.util.json_loads' imported but unused redirect.py:26:1: F401 'oauth_dropins.webutil.util.json_loads' imported but unused web.py:18:1: F401 'oauth_dropins.webutil.util.json_loads' imported but unused webfinger.py:13:1: F401 'oauth_dropins.webutil.util.json_loads' imported but unused webfinger.py:110:13: E122 continuation line missing indentation or outdented webfinger.py:111:13: E122 continuation line missing indentation or outdented webfinger.py:131:13: E122 continuation line missing indentation or outdented webfinger.py:132:13: E122 continuation line missing indentation or outdented webfinger.py:133:13: E122 continuation line missing indentation or outdented webfinger.py:134:13: E122 continuation line missing indentation or outdented tests/__init__.py:2:1: F401 'oauth_dropins.webutil.tests' imported but unused tests/test_follow.py:11:1: F401 'oauth_dropins.webutil.util.json_dumps' imported but unused tests/test_follow.py:14:1: F401 '.testutil.Fake' imported but unused tests/test_models.py:156:15: E122 continuation line missing indentation or outdented tests/test_models.py:157:15: E122 continuation line missing indentation or outdented tests/test_models.py:158:11: E122 continuation line missing indentation or outdented tests/test_web.py:12:1: F401 'oauth_dropins.webutil.util.json_dumps' imported but unused tests/test_web.py:17:1: F401 '.testutil' imported but unused tests/test_web.py:1513:13: E128 continuation line under-indented for visual indent tests/test_web.py:1514:9: E124 closing bracket does not match visual indentation tests/testutil.py:106:1: E402 module level import not at top of file tests/testutil.py:107:1: E402 module level import not at top of file tests/testutil.py:108:1: E402 module level import not at top of file tests/testutil.py:109:1: E402 module level import not at top of file tests/testutil.py:110:1: E402 module level import not at top of file tests/testutil.py:301:24: E203 whitespace before ':' tests/testutil.py:301:25: E701 multiple statements on one line (colon) tests/testutil.py:301:25: E231 missing whitespace after ':'
2023-06-20 18:22:54 +00:00
from granary import bluesky
2022-12-28 17:27:42 +00:00
from oauth_dropins.webutil import util
from flask_app import xrpc_server
from web import Web
2022-12-28 17:27:42 +00:00
logger = logging.getLogger(__name__)
2022-12-25 05:08:12 +00:00
@xrpc_server.method('app.bsky.actor.getProfile')
2022-12-28 17:27:42 +00:00
def getProfile(input, actor=None):
2022-12-25 05:08:12 +00:00
"""
lexicons/app/bsky/actor/getProfile.json
"""
2022-12-28 17:27:42 +00:00
# TODO: actor is either handle or DID
# see actorWhereClause in atproto/packages/pds/src/db/util.ts
if not actor or not re.match(util.DOMAIN_RE, actor):
2022-12-28 17:27:42 +00:00
raise ValueError(f'{actor} is not a domain')
g.user = Web.get_by_id(actor)
if not g.user:
raise ValueError(f'User {actor} not found')
elif not g.user.obj.as1:
return ValueError(f'User {actor} not fully set up')
2022-12-28 17:27:42 +00:00
actor_as1 = g.user.obj.as1
logger.info(f'AS1 actor: {json.dumps(actor_as1, indent=2)}')
2022-12-28 17:27:42 +00:00
profile = bluesky.from_as1(actor_as1)
2022-12-28 17:27:42 +00:00
logger.info(f'Bluesky profile: {json.dumps(profile, indent=2)}')
return profile
2022-12-25 05:08:12 +00:00
2022-12-25 05:08:12 +00:00
@xrpc_server.method('app.bsky.actor.getSuggestions')
2022-12-28 17:27:42 +00:00
def getSuggestions(input):
2022-12-25 05:08:12 +00:00
"""
lexicons/app/bsky/actor/getSuggestions.json
"""
# TODO based on stored users
return {'actors': []}
2022-12-25 05:08:12 +00:00
@xrpc_server.method('app.bsky.actor.searchActors')
def searchActors(input, term=None, limit=None, before=None):
2022-12-25 05:08:12 +00:00
"""
lexicons/app/bsky/actor/searchActors.json
2022-12-25 05:08:12 +00:00
"""
2022-12-28 21:11:11 +00:00
# TODO based on stored users
return {'actors': []}
2022-12-28 21:11:11 +00:00
2022-12-25 05:08:12 +00:00
@xrpc_server.method('app.bsky.actor.searchActorsTypeahead')
def searchActorsTypeahead(input, term=None, limit=None):
2022-12-25 05:08:12 +00:00
"""
lexicons/app/bsky/actor/searchActorsTypeahead.json
2022-12-25 05:08:12 +00:00
"""
2022-12-28 21:11:11 +00:00
# TODO based on stored users
return {'actors': []}