From 4e188375ef50a6570aaf85399bbc0cb20957c403 Mon Sep 17 00:00:00 2001 From: Alex Kelly Date: Sun, 5 Jan 2020 20:27:51 -0500 Subject: [PATCH] Added handling for ipfs and http in returned json, closes #3 --- chainlink.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/chainlink.py b/chainlink.py index e49f722..896ac28 100755 --- a/chainlink.py +++ b/chainlink.py @@ -44,6 +44,8 @@ def redirectDomain(domain, action=None): body = json.loads(dnslookup.content) print(body) redirect_url = body['ipfs']['redirect_domain'] + if not redirect_url.startswith('http'): + redirect_url = "http://" + redirect_url response.status = 302 response.set_header('Location',redirect_url) else: @@ -56,7 +58,11 @@ def redirectDomain(domain, action=None): body = json.loads(dnslookup.content) print(body) 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': if dnslookup.status_code == 200: body = json.loads(dnslookup.content)