From 9c52f56fa191353dd9f0908f6686bd3fb3cbbde9 Mon Sep 17 00:00:00 2001 From: nar20 <nar20@inf.ufpr.br> Date: Thu, 4 Jul 2024 13:47:01 +0000 Subject: [PATCH] Issue/61 download colections --- .../concerns/downloadable_controller.rb | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/app/controllers/concerns/downloadable_controller.rb b/app/controllers/concerns/downloadable_controller.rb index fd409412d..e7e872cfe 100644 --- a/app/controllers/concerns/downloadable_controller.rb +++ b/app/controllers/concerns/downloadable_controller.rb @@ -22,14 +22,25 @@ module DownloadableController # GET /learning_objects/1/download def download - # Change request.remote_ip to req.env["HTTP_X_REAL_IP"] in production - downloadable.download(current_user, request.remote_ip) - link = downloadable.download_link - if !link.blank? - redirect_to link - else - render status: :internal_server_error - end + object_id = params.values[2] + + object = LearningObject.where(id: object_id).first + attachment_id = object.attachment_id + + attachment = LearningObject::Attachment.where(id: attachment_id).first.as_json + + attachment_name = attachment["name"] + + link = attachment["retrieve_link"] + source = "https://mecdb4.c3sl.ufpr.br:8443" + link + + require 'open-uri' + + data = URI.open(source) + send_data data, :disposition => 'attachment', :filename=>attachment_name + + # https://mecdb4.c3sl.ufpr.br:8443/rest/bitstreams/11104/retrieve + # https://api.portalmec.c3sl.ufpr.br/v1/learning_objects/10943/download end protected -- GitLab