kopia lustrzana https://github.com/snarfed/bridgy-fed
add Protocol.HAS_COPIES, use to generate ids.COPIES_PROTOCOLS
rodzic
c86c91b25b
commit
0238b46e36
|
@ -96,6 +96,7 @@ class ATProto(User, Protocol):
|
|||
# need to update serviceEndpoint in all users' DID docs. :/
|
||||
PDS_URL = f'https://atproto{common.SUPERDOMAIN}/'
|
||||
CONTENT_TYPE = 'application/json'
|
||||
HAS_COPIES = True
|
||||
DEFAULT_ENABLED_PROTOCOLS = ()
|
||||
|
||||
def _pre_put_hook(self):
|
||||
|
|
4
ids.py
4
ids.py
|
@ -23,8 +23,8 @@ import models
|
|||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Protocols to check User.copies and Object.copies before translating
|
||||
# TODO: move to Protocol
|
||||
COPIES_PROTOCOLS = ('atproto',)
|
||||
# populated in models.reset_protocol_properties
|
||||
COPIES_PROTOCOLS = None
|
||||
|
||||
# Web user domains whose AP actor ids are on fed.brid.gy, not web.brid.gy, for
|
||||
# historical compatibility. Loaded on first call to web_ap_subdomain().
|
||||
|
|
|
@ -120,6 +120,8 @@ def reset_protocol_properties():
|
|||
abbrevs = f'({"|".join(PROTOCOLS.keys())}|fed)'
|
||||
common.SUBDOMAIN_BASE_URL_RE = re.compile(
|
||||
rf'^https?://({abbrevs}\.brid\.gy|localhost(:8080)?)/(convert/|r/)?({abbrevs}/)?(?P<path>.+)')
|
||||
ids.COPIES_PROTOCOLS = tuple(label for label, proto in PROTOCOLS.items()
|
||||
if proto and proto.HAS_COPIES)
|
||||
|
||||
|
||||
class User(StringIdModel, metaclass=ProtocolUserMeta):
|
||||
|
@ -360,6 +362,7 @@ class User(StringIdModel, metaclass=ProtocolUserMeta):
|
|||
Args:
|
||||
to_proto (:class:`protocol.Protocol` subclass)
|
||||
"""
|
||||
logger.info(f'Enabling {to_proto.LABEL} for {self.key}')
|
||||
user = self.key.get()
|
||||
add(user.enabled_protocols, to_proto.LABEL)
|
||||
if to_proto.LABEL in ids.COPIES_PROTOCOLS and not user.get_copy(to_proto):
|
||||
|
@ -375,6 +378,7 @@ class User(StringIdModel, metaclass=ProtocolUserMeta):
|
|||
Args:
|
||||
to_proto (:class:`protocol.Protocol` subclass)
|
||||
"""
|
||||
logger.info(f'Disabling {to_proto.LABEL} for {self.key}')
|
||||
user = self.key.get()
|
||||
remove(user.enabled_protocols, to_proto.LABEL)
|
||||
# TODO: delete copy user
|
||||
|
|
|
@ -80,6 +80,9 @@ class Protocol:
|
|||
appropriate for the ``Content-Type`` HTTP header.
|
||||
HAS_FOLLOW_ACCEPTS (bool): whether this protocol supports explicit
|
||||
accept/reject activities in response to follows, eg ActivityPub
|
||||
HAS_COPIES (bool): whether this protocol is push and needs us to
|
||||
proactively create "copy" users and objects, as opposed to pulling
|
||||
converted objects on demand
|
||||
DEFAULT_ENABLED_PROTOCOLS (list of str): labels of other protocols that
|
||||
are automatically enabled for this protocol to bridge into
|
||||
"""
|
||||
|
@ -89,6 +92,7 @@ class Protocol:
|
|||
LOGO_HTML = ''
|
||||
CONTENT_TYPE = None
|
||||
HAS_FOLLOW_ACCEPTS = False
|
||||
HAS_COPIES = False
|
||||
DEFAULT_ENABLED_PROTOCOLS = ()
|
||||
|
||||
def __init__(self):
|
||||
|
|
|
@ -70,6 +70,7 @@ class Fake(User, protocol.Protocol):
|
|||
ABBREV = 'fa'
|
||||
PHRASE = 'fake-phrase'
|
||||
CONTENT_TYPE = 'fa/ke'
|
||||
HAS_COPIES = True
|
||||
|
||||
# maps string ids to dict AS1 objects that can be fetched
|
||||
fetchable = {}
|
||||
|
@ -231,7 +232,6 @@ class TestCase(unittest.TestCase, testutil.Asserts):
|
|||
cls.created_for = []
|
||||
|
||||
ids._NON_WEB_SUBDOMAIN_SITES = None
|
||||
ids.COPIES_PROTOCOLS = ('atproto', 'fake', 'other', 'eefake')
|
||||
|
||||
# make random test data deterministic
|
||||
arroba.util._clockid = 17
|
||||
|
|
Ładowanie…
Reference in New Issue