Class: Hyrax::Actors::CreateWithRemoteFilesActor::IngestRemoteFilesService
- Inherits:
-
Object
- Object
- Hyrax::Actors::CreateWithRemoteFilesActor::IngestRemoteFilesService
- Defined in:
- app/actors/hyrax/actors/create_with_remote_files_actor.rb
Instance Attribute Summary collapse
-
#curation_concern ⇒ Object
readonly
rubocop:enable Metrics/ParameterLists.
-
#file_set_actor_class ⇒ Object
readonly
rubocop:enable Metrics/ParameterLists.
-
#ordered ⇒ Object
readonly
rubocop:enable Metrics/ParameterLists.
-
#ordered_members ⇒ Object
readonly
rubocop:enable Metrics/ParameterLists.
-
#remote_files ⇒ Object
readonly
rubocop:enable Metrics/ParameterLists.
-
#user ⇒ Object
readonly
rubocop:enable Metrics/ParameterLists.
Class Method Summary collapse
Instance Method Summary collapse
-
#attach! ⇒ Object
True.
-
#initialize(user:, curation_concern:, remote_files:, file_set_actor_class:, ordered_members: [], ordered: false) ⇒ IngestRemoteFilesService
constructor
rubocop:disable Metrics/ParameterLists.
Constructor Details
#initialize(user:, curation_concern:, remote_files:, file_set_actor_class:, ordered_members: [], ordered: false) ⇒ IngestRemoteFilesService
rubocop:disable Metrics/ParameterLists
45 46 47 48 49 50 51 52 |
# File 'app/actors/hyrax/actors/create_with_remote_files_actor.rb', line 45 def initialize(user:, curation_concern:, remote_files:, file_set_actor_class:, ordered_members: [], ordered: false) @remote_files = remote_files @user = user @curation_concern = curation_concern @file_set_actor_class = file_set_actor_class @ordered_members = ordered_members @ordered = ordered end |
Instance Attribute Details
#curation_concern ⇒ Object (readonly)
rubocop:enable Metrics/ParameterLists
54 55 56 |
# File 'app/actors/hyrax/actors/create_with_remote_files_actor.rb', line 54 def curation_concern @curation_concern end |
#file_set_actor_class ⇒ Object (readonly)
rubocop:enable Metrics/ParameterLists
54 55 56 |
# File 'app/actors/hyrax/actors/create_with_remote_files_actor.rb', line 54 def file_set_actor_class @file_set_actor_class end |
#ordered ⇒ Object (readonly)
rubocop:enable Metrics/ParameterLists
54 55 56 |
# File 'app/actors/hyrax/actors/create_with_remote_files_actor.rb', line 54 def ordered @ordered end |
#ordered_members ⇒ Object (readonly)
rubocop:enable Metrics/ParameterLists
54 55 56 |
# File 'app/actors/hyrax/actors/create_with_remote_files_actor.rb', line 54 def ordered_members @ordered_members end |
#remote_files ⇒ Object (readonly)
rubocop:enable Metrics/ParameterLists
54 55 56 |
# File 'app/actors/hyrax/actors/create_with_remote_files_actor.rb', line 54 def remote_files @remote_files end |
#user ⇒ Object (readonly)
rubocop:enable Metrics/ParameterLists
54 55 56 |
# File 'app/actors/hyrax/actors/create_with_remote_files_actor.rb', line 54 def user @user end |
Class Method Details
.registered_ingest_dirs ⇒ Object
75 76 77 |
# File 'app/actors/hyrax/actors/create_with_remote_files_actor.rb', line 75 def self.registered_ingest_dirs Hyrax.config.registered_ingest_dirs end |
.validate_remote_url(uri) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 |
# File 'app/actors/hyrax/actors/create_with_remote_files_actor.rb', line 80 def self.validate_remote_url(uri) if uri.scheme == 'file' path = File.absolute_path(CGI.unescape(uri.path)) registered_ingest_dirs.any? do |dir| path.start_with?(dir) && path.length > dir.length end else Rails.logger.debug "Assuming #{uri.scheme} uri is valid without a serious attempt to validate: #{uri}" true end end |
Instance Method Details
#attach! ⇒ Object
Returns true.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/actors/hyrax/actors/create_with_remote_files_actor.rb', line 58 def attach! return true unless remote_files remote_files.each do |file_info| next if file_info.blank? || file_info[:url].blank? # Escape any space characters, so that this is a legal URI uri = URI.parse(Addressable::URI.escape(file_info[:url])) unless self.class.validate_remote_url(uri) Rails.logger.error "User #{user.user_key} attempted to ingest file from url #{file_info[:url]}, which doesn't pass validation" return false end auth_header = file_info.fetch(:auth_header, {}) create_file_from_url(uri, file_info[:file_name], auth_header) end add_ordered_members! if ordered true end |