kopia lustrzana https://github.com/snarfed/bridgy-fed
rodzic
6796b47a9f
commit
cb5e7bf8c7
4
pages.py
4
pages.py
|
@ -43,11 +43,11 @@ def load_user(protocol, id):
|
||||||
Raises:
|
Raises:
|
||||||
:class:`werkzeug.exceptions.HTTPException` on error or redirect
|
:class:`werkzeug.exceptions.HTTPException` on error or redirect
|
||||||
"""
|
"""
|
||||||
|
assert id
|
||||||
cls = PROTOCOLS[protocol]
|
cls = PROTOCOLS[protocol]
|
||||||
g.user = cls.get_by_id(id)
|
g.user = cls.get_by_id(id)
|
||||||
|
|
||||||
# TODO(#512): generalize across protocols
|
if protocol != 'web':
|
||||||
if protocol == 'activitypub':
|
|
||||||
if not g.user:
|
if not g.user:
|
||||||
g.user = cls.query(cls.readable_id == id).get()
|
g.user = cls.query(cls.readable_id == id).get()
|
||||||
if g.user and g.user.use_instead:
|
if g.user and g.user.use_instead:
|
||||||
|
|
16
protocol.py
16
protocol.py
|
@ -45,6 +45,7 @@ objects_cache_lock = threading.Lock()
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: merge Protocol and User classes?
|
||||||
class Protocol:
|
class Protocol:
|
||||||
"""Base protocol class. Not to be instantiated; classmethods only.
|
"""Base protocol class. Not to be instantiated; classmethods only.
|
||||||
|
|
||||||
|
@ -173,8 +174,8 @@ class Protocol:
|
||||||
error(f'Undo of Follow requires actor id and object id. Got: {actor_id} {inner_obj_id} {obj.as1}')
|
error(f'Undo of Follow requires actor id and object id. Got: {actor_id} {inner_obj_id} {obj.as1}')
|
||||||
|
|
||||||
# deactivate Follower
|
# deactivate Follower
|
||||||
# TODO(#512): generalize across protocols
|
# TODO(#512): generalize across protocols. use inner_obj_id's
|
||||||
# TODO(#512): merge Protocol and User
|
# brid.gy subdomain to determine protocol?
|
||||||
followee_domain = util.domain_from_link(inner_obj_id, minimize=False)
|
followee_domain = util.domain_from_link(inner_obj_id, minimize=False)
|
||||||
from web import Web
|
from web import Web
|
||||||
follower = Follower.query(
|
follower = Follower.query(
|
||||||
|
@ -372,17 +373,16 @@ class Protocol:
|
||||||
|
|
||||||
# TODO(#512): generalize protocol
|
# TODO(#512): generalize protocol
|
||||||
from web import Web
|
from web import Web
|
||||||
recip = Web(id=domain).key
|
recip = Web(id=domain)
|
||||||
if recip not in obj.users:
|
if recip.key not in obj.users:
|
||||||
if not recip.get():
|
if not recip.key.get():
|
||||||
logger.info(f'No Web user for {domain}; skipping {target.uri}')
|
logger.info(f'No Web user for {domain}; skipping {target.uri}')
|
||||||
no_user_domains.add(domain)
|
no_user_domains.add(domain)
|
||||||
continue
|
continue
|
||||||
obj.users.append(recip)
|
obj.users.append(recip.key)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# TODO(#512): generalize protocol
|
if recip.send(obj, target.uri):
|
||||||
if Web.send(obj, target.uri):
|
|
||||||
obj.delivered.append(target)
|
obj.delivered.append(target)
|
||||||
if 'notification' not in obj.labels:
|
if 'notification' not in obj.labels:
|
||||||
obj.labels.append('notification')
|
obj.labels.append('notification')
|
||||||
|
|
12
redirect.py
12
redirect.py
|
@ -1,14 +1,18 @@
|
||||||
"""Simple conneg endpoint that serves AS2 or redirects to to the original post.
|
"""Simple conneg endpoint that serves AS2 or redirects to to the original post.
|
||||||
|
|
||||||
Serves /r/https://foo.com/bar URL paths, where https://foo.com/bar is an
|
Only for Web users. Other protocols (including Web sometimes) use /convert/ in
|
||||||
original post. Needed for Mastodon interop, they require that AS2 object ids and
|
convert.py instead.
|
||||||
urls are on the same domain that serves them. Background:
|
|
||||||
|
Serves /r/https://foo.com/bar URL paths, where https://foo.com/bar is a original
|
||||||
|
post for a Web user. Needed for Mastodon interop, they require that AS2 object
|
||||||
|
ids and urls are on the same domain that serves them. Background:
|
||||||
|
|
||||||
https://github.com/snarfed/bridgy-fed/issues/16#issuecomment-424799599
|
https://github.com/snarfed/bridgy-fed/issues/16#issuecomment-424799599
|
||||||
https://github.com/tootsuite/mastodon/pull/6219#issuecomment-429142747
|
https://github.com/tootsuite/mastodon/pull/6219#issuecomment-429142747
|
||||||
|
|
||||||
The conneg makes these /r/ URLs searchable in Mastodon:
|
The conneg makes these /r/ URLs searchable in Mastodon:
|
||||||
https://github.com/snarfed/bridgy-fed/issues/352
|
https://github.com/snarfed/bridgy-fed/issues/352
|
||||||
|
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
|
@ -76,8 +80,6 @@ def redir(to):
|
||||||
to_domain))
|
to_domain))
|
||||||
for domain in domains:
|
for domain in domains:
|
||||||
if domain:
|
if domain:
|
||||||
# TODO(#512): do we need to parameterize this by protocol? or is it
|
|
||||||
# only for web?
|
|
||||||
g.user = Web.get_by_id(domain)
|
g.user = Web.get_by_id(domain)
|
||||||
if g.user:
|
if g.user:
|
||||||
logger.info(f'Found web user for domain {domain}')
|
logger.info(f'Found web user for domain {domain}')
|
||||||
|
|
|
@ -163,7 +163,7 @@ class TestCase(unittest.TestCase, testutil.Asserts):
|
||||||
result.failures = prune(result.failures)
|
result.failures = prune(result.failures)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
# TODO(#512): switch default to Fake, start using that more
|
# TODO: switch default to Fake, start using that more
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def make_user(id, cls=Web, **kwargs):
|
def make_user(id, cls=Web, **kwargs):
|
||||||
"""Reuse RSA key across Users because generating it is expensive."""
|
"""Reuse RSA key across Users because generating it is expensive."""
|
||||||
|
|
Ładowanie…
Reference in New Issue