bring back the /convert/[src]/[dest]/[url] routes, forgot we'd used them in prod

thanks for reporting @gRegorLove!
pull/553/head
Ryan Barrett 2023-06-17 13:48:23 -07:00
rodzic 4778024c7e
commit 501406ab7a
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
2 zmienionych plików z 20 dodań i 2 usunięć

Wyświetl plik

@ -22,8 +22,10 @@ from web import Web
logger = logging.getLogger(__name__)
SOURCES = frozenset((
ActivityPub,
Web,
ActivityPub.ABBREV,
ActivityPub.LABEL,
Web.ABBREV,
Web.LABEL,
))
DESTS = frozenset((
ActivityPub.ABBREV,
@ -94,3 +96,13 @@ def render_redirect():
"""Redirect from old /render?id=... endpoint to /convert/..."""
id = flask_util.get_required_param('id')
return redirect(ActivityPub.subdomain_url(f'/convert/web/{id}'), code=301)
@app.get(f'/convert/<any({",".join(SOURCES)}):src>/<any({",".join(DESTS)}):dest>/<path:_>')
def convert_source_path_redirect(src, dest, _):
"""Old route that included source protocol in path instead of subdomain."""
if Protocol.for_request() not in (None, 'web'): # no per-protocol subdomains
error(f'Try again on fed.brid.gy', status=404)
new_path = request.full_path.replace(f'/{src}/', '/')
return redirect(PROTOCOLS[src].subdomain_url(new_path), code=301)

Wyświetl plik

@ -225,6 +225,12 @@ A ☕ reply
self.assertEqual(f'https://ap.brid.gy/convert/web/http://foo?bar',
resp.headers['Location'])
def test_convert_source_path_redirect(self):
resp = self.client.get('/convert/ap/web/http://foo?bar')
self.assertEqual(301, resp.status_code)
self.assertEqual(f'https://ap.brid.gy/convert/web/http://foo?bar',
resp.headers['Location'])
def test_web_to_activitypub_object(self):
url = 'https://user.com/bar?baz=baj&biff'
self.make_user('user.com')