Added handling for ipfs and http in returned json, closes #3

This commit is contained in:
Alex Kelly 2020-01-05 20:27:51 -05:00
parent b5d344c9fe
commit 4e188375ef

View file

@ -44,6 +44,8 @@ def redirectDomain(domain, action=None):
body = json.loads(dnslookup.content) body = json.loads(dnslookup.content)
print(body) print(body)
redirect_url = body['ipfs']['redirect_domain'] redirect_url = body['ipfs']['redirect_domain']
if not redirect_url.startswith('http'):
redirect_url = "http://" + redirect_url
response.status = 302 response.status = 302
response.set_header('Location',redirect_url) response.set_header('Location',redirect_url)
else: else:
@ -56,7 +58,11 @@ def redirectDomain(domain, action=None):
body = json.loads(dnslookup.content) body = json.loads(dnslookup.content)
print(body) print(body)
response.status = 302 response.status = 302
response.set_header('Location', f"https://cloudflare-ipfs.com/ipfs/{body['ipfs']['html']}") if not body['ipfs']['html'].startswith('ip'):
ipfshash = "ipfs/" + body['ipfs']['html']
else:
ipfshash = body['ipfs']['html']
response.set_header('Location', f"https://cloudflare-ipfs.com/{ipfshash}")
elif action == 'raw': elif action == 'raw':
if dnslookup.status_code == 200: if dnslookup.status_code == 200:
body = json.loads(dnslookup.content) body = json.loads(dnslookup.content)