Skip to content

Commit

Permalink
redirect to IPFS only (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
luizirber committed Jul 22, 2020
1 parent 94e6b09 commit ad5ef1e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion wort/api.yaml
Expand Up @@ -42,7 +42,7 @@ paths:
'/view/{public_db}/{dataset_id}':
get:
summary: Return a signature
operationId: wort.blueprints.viewer.views.view_s3
operationId: wort.blueprints.viewer.views.view
parameters:
- $ref: '#/components/parameters/public_db'
- $ref: '#/components/parameters/dataset_id'
Expand Down
24 changes: 23 additions & 1 deletion wort/blueprints/viewer/views.py
@@ -1,4 +1,4 @@
from flask import Blueprint, jsonify, redirect, render_template
from flask import Blueprint, current_app, jsonify, redirect, render_template

viewer = Blueprint("viewer", __name__, template_folder="templates")

Expand All @@ -25,3 +25,25 @@ def view_s3(public_db, dataset_id):
url = conn.generate_presigned_url("get_object", Params=params, ExpiresIn=100)

return redirect(url)

# @viewer.route("/view/<db>/<dataset_id>")
def view(public_db, dataset_id):

if public_db not in ("sra", "img"):
return "Database not supported", 404

dataset_info = current_app.cache.get(f"{public_db}/{dataset_id}")

if dataset_info is None:
# Not in cache, let's check DB
dataset = Dataset.query.filter_by(id=dataset_id).first()

if dataset is not None:
# Found a hit in DB
if dataset.ipfs is not None:
return redirect(f"https://cloudflare-ipfs.com/ipfs/{dataset.ipfs}")
else:
# Found in cache, redirect
return redirect(f"https://cloudflare-ipfs.com/ipfs/{dataset_info['ipfs']}")

return "Dataset not found", 404

0 comments on commit ad5ef1e

Please sign in to comment.