Skip to content

Commit

Permalink
Merge pull request #2475 from pulibrary/2420-audio-reserves-filenames
Browse files Browse the repository at this point in the history
BulkIngestService now preserves file names for WAV
  • Loading branch information
escowles committed Jan 24, 2019
2 parents 87e6e12 + 215a937 commit 3ff0186
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def pdf
redirect_to download_path(redirect_path_args)
end

# API endpoint for asking where a folder to save and ingest from is located.
def save_and_ingest
authorize! :create, resource_class
respond_to do |f|
Expand Down
50 changes: 35 additions & 15 deletions app/services/bulk_ingest_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,22 +159,42 @@ def files(path:, file_filters: [])
file_paths.reject! { |x| x.basename.to_s.start_with?(".") }
file_paths.reject! { |x| blacklisted_file_names.include?(x.basename.to_s) }

nodes = []
file_paths.sort.each_with_index do |f, idx|
basename = File.basename(f)
mime_types = MIME::Types.type_for(basename)
mime_type = mime_types.first
nodes << IngestableFile.new(
file_path: f,
mime_type: mime_type.content_type,
original_filename: basename,
copyable: true,
container_attributes: {
title: (idx + 1).to_s
}
)
BulkFilePathConverter.new(file_paths: file_paths).to_a
end

class BulkFilePathConverter
attr_reader :file_paths
def initialize(file_paths:)
@file_paths = file_paths.sort
end

def to_a
nodes = []
file_paths.each_with_index do |f, idx|
basename = File.basename(f)
mime_types = MIME::Types.type_for(basename)
mime_type = mime_types.first
title = if preserved_file_name_mime_types.include?(mime_type.content_type)
basename
else
(idx + 1).to_s
end
nodes << IngestableFile.new(
file_path: f,
mime_type: mime_type.content_type,
original_filename: basename,
copyable: true,
container_attributes: {
title: title
}
)
end
nodes
end

def preserved_file_name_mime_types
["audio/x-wav"]
end
nodes
end

def blacklisted_file_names
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@
resource = find_resource(id)

expect(resource.member_ids.length).to eq 2
members = query_service.find_members(resource: resource)
expect(members.flat_map(&:title)).to eq ["1", "2"]
end

it "can create and import a MVW" do
Expand Down Expand Up @@ -135,6 +137,7 @@
expect(resource.member_ids.length).to eq 1
file_set = find_resource(resource.member_ids.first)
expect(file_set.file_metadata.length).to eq 2
expect(file_set.title).to eq ["1791261_0701.wav"]
expect(file_set.original_file).not_to be nil
expect(file_set.original_file.label).to eq ["1791261_0701.wav"]
expect(file_set.original_file.mime_type).to eq ["audio/x-wav"]
Expand Down

0 comments on commit 3ff0186

Please sign in to comment.