Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download cache #3

Merged
merged 2 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading