kopia lustrzana https://github.com/snarfed/bridgy-fed
ids.translate_user_id: for Web, normalize home page URLs to domains
rodzic
1f6a227aee
commit
37d8b5d4fc
6
ids.py
6
ids.py
|
@ -4,6 +4,7 @@ https://fed.brid.gy/docs#translate
|
|||
"""
|
||||
import logging
|
||||
import re
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from common import subdomain_wrap, SUPERDOMAIN
|
||||
import models
|
||||
|
@ -25,6 +26,11 @@ def translate_user_id(*, id, from_proto, to_proto):
|
|||
assert id and from_proto and to_proto
|
||||
assert from_proto.owns_id(id) is not False
|
||||
|
||||
parsed = urlparse(id)
|
||||
if from_proto.LABEL == 'web' and parsed.path.strip('/') == '':
|
||||
# home page; replace with domain
|
||||
id = parsed.netloc
|
||||
|
||||
if from_proto == to_proto:
|
||||
return id
|
||||
|
||||
|
|
|
@ -30,9 +30,12 @@ class IdsTest(TestCase):
|
|||
(Fake, 'fake:user', Fake, 'fake:user'),
|
||||
(Fake, 'fake:user', Web, 'fake:user'),
|
||||
(Web, 'user.com', ActivityPub, 'https://fed.brid.gy/user.com'),
|
||||
(Web, 'https://user.com/', ActivityPub, 'https://fed.brid.gy/user.com'),
|
||||
(Web, 'user.com', ATProto, 'did:plc:123'),
|
||||
(Web, 'https://user.com', ATProto, 'did:plc:123'),
|
||||
(Web, 'user.com', Fake, 'fake:u:user.com'),
|
||||
(Web, 'user.com', Web, 'user.com'),
|
||||
(Web, 'https://user.com/', Web, 'user.com'),
|
||||
]:
|
||||
with self.subTest(from_=from_.LABEL, to=to.LABEL):
|
||||
self.assertEqual(expected, translate_user_id(
|
||||
|
|
Ładowanie…
Reference in New Issue