kopia lustrzana https://github.com/snarfed/bridgy-fed
bring back the /convert/[src]/[dest]/[url] routes, forgot we'd used them in prod
thanks for reporting @gRegorLove!pull/553/head
rodzic
4778024c7e
commit
501406ab7a
16
convert.py
16
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/<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)
|
||||
|
|
|
@ -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')
|
||||
|
|
Ładowanie…
Reference in New Issue