diff --git a/lib/valkyrie/storage/disk.rb b/lib/valkyrie/storage/disk.rb index 87975ea7..2461260b 100644 --- a/lib/valkyrie/storage/disk.rb +++ b/lib/valkyrie/storage/disk.rb @@ -21,6 +21,16 @@ def upload(file:, original_filename:, resource: nil, **_extra_arguments) find_by(id: Valkyrie::ID.new("disk://#{new_path}")) end + # @param file [IO] + # @param original_filename [String] + # @param resource [Valkyrie::Resource] + # @param _extra_arguments [Hash] additional arguments which may be passed to other adapters + # @return [Valkyrie::ID] + def id_for(file:, original_filename:, resource: nil, **_extra_arguments) + new_path = path_generator.generate(resource: resource, file: file, original_filename: original_filename) + Valkyrie::ID.new("disk://#{new_path}") + end + # @param id [Valkyrie::ID] # @return [Boolean] true if this adapter can handle this type of identifer def handles?(id:) diff --git a/lib/valkyrie/storage/fedora.rb b/lib/valkyrie/storage/fedora.rb index 6957942c..8c56e157 100644 --- a/lib/valkyrie/storage/fedora.rb +++ b/lib/valkyrie/storage/fedora.rb @@ -51,6 +51,19 @@ def upload(file:, original_filename:, resource:, content_type: "application/octe find_by(id: Valkyrie::ID.new(identifier.to_s.sub(/^.+\/\//, PROTOCOL))) end + # @param file [IO] + # @param original_filename [String] + # @param resource [Valkyrie::Resource] + # @param content_type [String] content type of file (e.g. 'image/tiff') (default='application/octet-stream') + # @param resource_uri_transformer [Lambda] transforms the resource's id (e.g. 'DDS78RK') into a uri (optional) + # @param extra_arguments [Hash] additional arguments which may be passed to other adapters + # @return [Valkyrie::StorageAdapter::StreamFile] + def id_for(file:, original_filename:, resource:, content_type: "application/octet-stream", # rubocop:disable Metrics/ParameterLists + resource_uri_transformer: default_resource_uri_transformer, **_extra_arguments) + identifier = resource_uri_transformer.call(resource, base_url) + '/original' + Valkyrie::ID.new(identifier.to_s.sub(/^.+\/\//, PROTOCOL)) + end + # Delete the file in Fedora associated with the given identifier. # @param id [Valkyrie::ID] def delete(id:) diff --git a/lib/valkyrie/storage/memory.rb b/lib/valkyrie/storage/memory.rb index 6f102b16..ee5c7928 100644 --- a/lib/valkyrie/storage/memory.rb +++ b/lib/valkyrie/storage/memory.rb @@ -20,6 +20,15 @@ def upload(file:, original_filename:, resource: nil, **_extra_arguments) cache[identifier] = Valkyrie::StorageAdapter::StreamFile.new(id: identifier, io: file) end + # @param file [IO] + # @param original_filename [String] + # @param resource [Valkyrie::Resource] + # @param _extra_arguments [Hash] additional arguments which may be passed to other adapters + # @return [Valkyrie::StorageAdapter::StreamFile] + def id_for(file:, original_filename:, resource: nil, **_extra_arguments) + Valkyrie::ID.new("memory://#{resource.id}") + end + # Return the file associated with the given identifier # @param id [Valkyrie::ID] # @return [Valkyrie::StorageAdapter::StreamFile]