Skip to content

Commit

Permalink
Save derivative pcdm_use when creating derivatives via valkyrie
Browse files Browse the repository at this point in the history
closes #6294

Co-authored-by: Trey Pendragon <tpendragon@users.noreply.github.com>
Co-authored-by: Eliot Jordan <eliotjordan@users.noreply.github.com>
Co-authored-by: Shaun Ellis <sdellis@users.noreply.github.com>
  • Loading branch information
4 people committed Sep 6, 2023
1 parent 28b32fb commit f9b2fd0
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
1 change: 1 addition & 0 deletions app/models/hyrax/file_metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ module Use
ORIGINAL_FILE = ::Valkyrie::Vocab::PCDMUse.OriginalFile
EXTRACTED_TEXT = ::Valkyrie::Vocab::PCDMUse.ExtractedText
THUMBNAIL = ::Valkyrie::Vocab::PCDMUse.ThumbnailImage
SERVICE_FILE = ::Valkyrie::Vocab::PCDMUse.ServiceFile

##
# @param use [RDF::URI, Symbol]
Expand Down
8 changes: 4 additions & 4 deletions app/services/hyrax/file_set_derivatives_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ def create_office_document_derivatives(filename)

def create_audio_derivatives(filename)
Hydra::Derivatives::AudioDerivatives.create(filename,
outputs: [{ label: 'mp3', format: 'mp3', url: derivative_url('mp3'), mime_type: 'audio/mpeg' },
{ label: 'ogg', format: 'ogg', url: derivative_url('ogg'), mime_type: 'audio/ogg' }])
outputs: [{ label: 'mp3', format: 'mp3', url: derivative_url('mp3'), mime_type: 'audio/mpeg', container: 'service_file' },
{ label: 'ogg', format: 'ogg', url: derivative_url('ogg'), mime_type: 'audio/ogg', container: 'service_file' }])
end

def create_video_derivatives(filename)
Hydra::Derivatives::VideoDerivatives.create(filename,
outputs: [{ label: :thumbnail, format: 'jpg', url: derivative_url('thumbnail'), mime_type: 'image/jpeg' },
{ label: 'webm', format: 'webm', url: derivative_url('webm'), mime_type: 'video/webm' },
{ label: 'mp4', format: 'mp4', url: derivative_url('mp4'), mime_type: 'video/mp4' }])
{ label: 'webm', format: 'webm', url: derivative_url('webm'), mime_type: 'video/webm', container: 'service_file' },
{ label: 'mp4', format: 'mp4', url: derivative_url('mp4'), mime_type: 'video/mp4', container: 'service_file' }])
end

def create_image_derivatives(filename)
Expand Down
2 changes: 2 additions & 0 deletions app/services/hyrax/valkyrie_upload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ def set_file_use_ids(file_set, file_metadata)
file_set.thumbnail_id = file_metadata.id
when Hyrax::FileMetadata::Use::EXTRACTED_TEXT
file_set.extracted_text_id = file_metadata.id
when Hyrax::FileMetadata::Use::SERVICE_FILE
# do nothing
else
Hyrax.logger.warn "Unknown file use #{file_metadata.type} specified for #{file_metadata.file_identifier}"
end
Expand Down
14 changes: 10 additions & 4 deletions spec/services/hyrax/file_set_derivatives_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,16 @@
FactoryBot.valkyrie_create(:hyrax_file_metadata, :audio_file, file_set_id: SecureRandom.uuid)
end

it "passes a mime-type to the audio derivatives service" do
it "passes a mime-type and container to the audio derivatives service" do
allow(Hydra::Derivatives::AudioDerivatives).to receive(:create)
described_class.new(valid_file_set).create_derivatives('foo')
expect(Hydra::Derivatives::AudioDerivatives).to have_received(:create).with('foo', outputs: contain_exactly(hash_including(mime_type: 'audio/mpeg'), hash_including(mime_type: 'audio/ogg')))
expect(Hydra::Derivatives::AudioDerivatives).to have_received(:create).with(
'foo',
outputs: contain_exactly(
hash_including(mime_type: 'audio/mpeg', container: 'service_file'),
hash_including(mime_type: 'audio/ogg', container: 'service_file')
)
)
end
end

Expand All @@ -47,8 +53,8 @@
expect(Hydra::Derivatives::VideoDerivatives).to have_received(:create).with(
'foo',
outputs: contain_exactly(
hash_including(mime_type: 'video/mp4'),
hash_including(mime_type: 'video/webm'),
hash_including(mime_type: 'video/mp4', container: 'service_file'),
hash_including(mime_type: 'video/webm', container: 'service_file'),
hash_including(mime_type: 'image/jpeg')
)
)
Expand Down
9 changes: 6 additions & 3 deletions spec/services/hyrax/valkyrie_persist_derivatives_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@

context "when given a mime_type directive" do
let(:directives) do
{ url: "file:///app/samvera/hyrax-webapp/derivatives/#{id}-webm.webm",
mime_type: 'video/webm' }
{ url: "file:///app/samvera/hyrax-webapp/derivatives/#{id}-mp4.mp4",
mime_type: 'video/webm',
container: 'service_file'}
end

it 'adds the mime_type to the file metadata' do
described_class.call(stream, directives)
files = Hyrax.custom_queries.find_files(file_set: file_set)
expect(files.first.mime_type).to eq 'video/webm'
file = files.first
expect(file.mime_type).to eq 'video/webm'
expect(file.pcdm_use).to eq [Hyrax::FileMetadata::Use::SERVICE_FILE]
end
end
end
Expand Down

0 comments on commit f9b2fd0

Please sign in to comment.