diff --git a/convert.py b/convert.py index ca6da4b..6377a6a 100644 --- a/convert.py +++ b/convert.py @@ -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///') +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) diff --git a/tests/test_convert.py b/tests/test_convert.py index 112d8f1..461c769 100644 --- a/tests/test_convert.py +++ b/tests/test_convert.py @@ -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')