Skip to content

Commit

Permalink
Merge pull request #3 from keitaroinc/download-cache
Browse files Browse the repository at this point in the history
Download cache
  • Loading branch information
blagojabozinovski authored May 14, 2024
2 parents 75cd56d + 9018494 commit d15f28b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ckanext/archiver/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from ckanext.archiver import lib
from ckanext.archiver.model import Archival, aggregate_archivals_for_a_dataset
from ckanext.archiver import cli
from ckanext.archiver.views import s3_archived

log = logging.getLogger(__name__)

Expand All @@ -27,6 +28,7 @@ class ArchiverPlugin(p.SingletonPlugin, p.toolkit.DefaultDatasetForm):
p.implements(p.IAuthFunctions)
p.implements(p.ITemplateHelpers)
p.implements(p.IPackageController, inherit=True)
p.implements(p.IBlueprint)

if p.toolkit.check_ckan_version(min_version='2.9.0'):
p.implements(p.IClick)
Expand Down Expand Up @@ -230,6 +232,12 @@ def before_dataset_index(self, pkg_dict):

def get_commands(self):
return cli.get_commands()

# IBlueprint

def get_blueprint(self):

return s3_archived


class TestIPipePlugin(p.SingletonPlugin):
Expand Down
2 changes: 2 additions & 0 deletions ckanext/archiver/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,8 @@ def archive_resource(context, resource, log, result=None, url_timeout=30):
# delete the file from archive storage
if os.path.isfile(saved_file):
os.remove(saved_file)
# save in database for cachefile_path the path from S3 storage
saved_file = s3_file_path

else:
shutil.move(result['saved_file'], saved_file)
Expand Down
22 changes: 22 additions & 0 deletions ckanext/archiver/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from flask import Blueprint
from ckan import model
from ckanext.archiver.model import Archival
from ckanext.cloudstorage.helpers import generate_download_signed_url_v4
import ckantoolkit as tk


redirect = tk.redirect_to

s3_archived = Blueprint("s3_archived_redirect", __name__)


def s3_archived_redirect(id, resource_id, filename):

q = model.Session.query(Archival).filter_by(resource_id=resource_id)
filepath = model.Session.execute(q).first()[8]
url = generate_download_signed_url_v4(filepath)
return redirect(url)


s3_archived.add_url_rule(u'/tmp/<id>/<resource_id>/<filename>',
view_func=s3_archived_redirect)

0 comments on commit d15f28b

Please sign in to comment.