kopia lustrzana https://github.com/snarfed/bridgy-fed
drop Object.proxy_url, switch callers to ids.translate_object_id
rodzic
06275324fd
commit
98bb29b333
6
ids.py
6
ids.py
|
@ -26,7 +26,7 @@ def translate_user_id(*, id, from_proto, to_proto):
|
|||
str: the corresponding id in ``to_proto``
|
||||
"""
|
||||
assert id and from_proto and to_proto
|
||||
assert from_proto.owns_id(id) is not False
|
||||
assert from_proto.owns_id(id) is not False or from_proto.LABEL == 'ui'
|
||||
|
||||
parsed = urlparse(id)
|
||||
if from_proto.LABEL == 'web' and parsed.path.strip('/') == '':
|
||||
|
@ -91,7 +91,7 @@ def translate_handle(*, handle, from_proto, to_proto):
|
|||
str: the corresponding handle in ``to_proto``
|
||||
"""
|
||||
assert handle and from_proto and to_proto
|
||||
assert from_proto.owns_handle(handle) is not False
|
||||
assert from_proto.owns_handle(handle) is not False or from_proto.LABEL == 'ui'
|
||||
|
||||
if from_proto == to_proto:
|
||||
return handle
|
||||
|
@ -138,7 +138,7 @@ def translate_object_id(*, id, from_proto, to_proto):
|
|||
str: the corresponding id in ``to_proto``
|
||||
"""
|
||||
assert id and from_proto and to_proto
|
||||
assert from_proto.owns_id(id) is not False
|
||||
assert from_proto.owns_id(id) is not False or from_proto.LABEL == 'ui'
|
||||
|
||||
if from_proto == to_proto:
|
||||
return id
|
||||
|
|
22
models.py
22
models.py
|
@ -705,7 +705,6 @@ class Object(StringIdModel):
|
|||
Only needed for compatibility with historical URL paths, we're now back
|
||||
to URL-encoding ``#``\s instead.
|
||||
https://github.com/snarfed/bridgy-fed/issues/469
|
||||
See :meth:`proxy_url` for the inverse.
|
||||
"""
|
||||
return super().get_by_id(id.replace('^^', '#'))
|
||||
|
||||
|
@ -806,27 +805,6 @@ class Object(StringIdModel):
|
|||
if self.as1 and other_as1
|
||||
else bool(self.as1) != bool(other_as1))
|
||||
|
||||
def proxy_url(self):
|
||||
# TODO: replace with ids.translate_object_id?
|
||||
"""Returns the Bridgy Fed proxy URL to render this post as HTML.
|
||||
|
||||
Note that some webmention receivers are struggling with the ``%23``\s
|
||||
(URL-encoded ``#``\s) in these paths:
|
||||
|
||||
* https://github.com/snarfed/bridgy-fed/issues/469
|
||||
* https://github.com/pfefferle/wordpress-webmention/issues/359
|
||||
|
||||
See :meth:`get_by_id()` for the inverse.
|
||||
"""
|
||||
# TODO: fix this circular import
|
||||
from protocol import Protocol
|
||||
|
||||
id = quote(self.key.id(), safe=':/')
|
||||
if not self.source_protocol:
|
||||
logger.warning(f'!!! No source_protocol for {id} !!!')
|
||||
protocol = PROTOCOLS.get(self.source_protocol) or Protocol
|
||||
return common.subdomain_wrap(protocol, f'convert/web/{id}')
|
||||
|
||||
def actor_link(self, image=True, sized=False):
|
||||
"""Returns a pretty HTML link with the actor's name and picture.
|
||||
|
||||
|
|
|
@ -361,15 +361,6 @@ class ObjectTest(TestCase):
|
|||
self.assertTrue(obj.activity_changed({}))
|
||||
self.assertTrue(obj.activity_changed({'content': 'x'}))
|
||||
|
||||
def test_proxy_url(self):
|
||||
obj = Object(id='abc', source_protocol='activitypub')
|
||||
self.assertEqual('https://ap.brid.gy/convert/web/abc',
|
||||
obj.proxy_url())
|
||||
|
||||
obj = Object(id='ab#c', source_protocol='ui')
|
||||
self.assertEqual('https://fed.brid.gy/convert/web/ab%23c',
|
||||
obj.proxy_url())
|
||||
|
||||
def test_put(self):
|
||||
with self.assertRaises(AssertionError):
|
||||
Object(id='x^^y').put()
|
||||
|
|
|
@ -2225,7 +2225,8 @@ class WebUtilTest(TestCase):
|
|||
|
||||
def test_send_no_endpoint(self, mock_get, mock_post):
|
||||
mock_get.return_value = WEBMENTION_NO_REL_LINK
|
||||
obj = Object(id='http://mas.to/like#ok', as2=test_activitypub.LIKE)
|
||||
obj = Object(id='http://mas.to/like#ok', as2=test_activitypub.LIKE,
|
||||
source_protocol='activitypub')
|
||||
|
||||
self.assertFalse(Web.send(obj, 'https://user.com/post'))
|
||||
|
||||
|
|
7
web.py
7
web.py
|
@ -4,7 +4,7 @@ import difflib
|
|||
import logging
|
||||
import re
|
||||
import urllib.parse
|
||||
from urllib.parse import urlencode, urljoin, urlparse
|
||||
from urllib.parse import quote, urlencode, urljoin, urlparse
|
||||
|
||||
from flask import g, redirect, render_template, request
|
||||
from google.cloud import ndb
|
||||
|
@ -23,6 +23,7 @@ from werkzeug.exceptions import BadGateway, BadRequest, HTTPException, NotFound
|
|||
import common
|
||||
from common import add, DOMAIN_RE
|
||||
from flask_app import app, cache
|
||||
from ids import translate_object_id
|
||||
from models import Follower, Object, PROTOCOLS, Target, User
|
||||
from protocol import Protocol
|
||||
|
||||
|
@ -331,7 +332,9 @@ class Web(User, Protocol):
|
|||
logger.info(f'Skipping sending to blocklisted {url}')
|
||||
return False
|
||||
|
||||
source_url = obj.proxy_url()
|
||||
source_id = translate_object_id(
|
||||
id=obj.key.id(), from_proto=PROTOCOLS[obj.source_protocol], to_proto=Web)
|
||||
source_url = quote(source_id, safe=':/%+')
|
||||
logger.info(f'Sending webmention from {source_url} to {url}')
|
||||
|
||||
endpoint = common.webmention_discover(url).endpoint
|
||||
|
|
Ładowanie…
Reference in New Issue