Class: Hydra::Works::PersistDerivative

Inherits:
Derivatives::PersistOutputFileService
  • Object
show all
Defined in:
lib/hydra/works/services/persist_derivative.rb

Class Method Summary collapse

Class Method Details

.call(stream, directives) ⇒ Object

Persists a derivative to a FileSet This Service conforms to the signature of ‘Hydra::Derivatives::PersistOutputFileService`. The purpose of this Service is for use as an alternative to the default Hydra::Derivatives::PersistOutputFileService. It’s necessary because the default behavior in Hydra::Derivatives assumes that you’re using LDP Basic Containment. Hydra::Works::FileSets use IndirectContainment. This Service handles that case. This service will always update existing and does not do versioning of persisted files.

extract file type symbol (e.g. :thumbnail) from Hydra::Derivatives created destination_name

Parameters:

  • stream (#read)

    the derivative filestream

  • directives (Hash)

Options Hash (directives):

  • :object (FileSet)

    the FileSet object to attach to

  • :label (Symbol)

    the type of derivative



18
19
20
21
22
23
24
# File 'lib/hydra/works/services/persist_derivative.rb', line 18

def self.call(stream, directives)
  file = Hydra::Derivatives::IoDecorator.new(stream)
  file.mime_type = new_mime_type(directives.fetch(:format))
  object = directives.fetch(:object)
  type = directives.fetch(:label)
  Hydra::Works::AddFileToFileSet.call(object, file, type, update_existing: true, versioning: false)
end

.new_mime_type(format) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/hydra/works/services/persist_derivative.rb', line 26

def self.new_mime_type(format)
  case format
  when 'mp4'
    'video/mp4' # default is application/mp4
  when 'webm'
    'video/webm' # default is audio/webm
  else
    MIME::Types.type_for(format).first.to_s
  end
end