Skip to content

Commit

Permalink
Fix duplicate extension on export (#260)
Browse files Browse the repository at this point in the history
* Fixes issue where extension on file name could be duplicated

* Used correct value for adding extension when it is missing
  • Loading branch information
sephirothkod authored Nov 24, 2020
1 parent 7a14bb6 commit 1f51be1
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions app/models/concerns/bulkrax/export_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@ def write_files
def filename(file_set)
return if file_set.original_file.blank?
fn = file_set.original_file.file_name.first
ext = Mime::Type.lookup(file_set.original_file.mime_type).to_sym
mime = Mime::Type.lookup(file_set.original_file.mime_type)
ext_mime = MIME::Types.of(file_set.original_file.file_name).first
if fn.include?(file_set.id)
return fn if fn.end_with?(ext.to_s)
return "#{fn}.#{ext}"
return fn if mime.to_s == ext_mime.to_s
return "#{fn}.#{mime.to_sym.to_s}"
else
return "#{file_set.id}_#{fn}" if fn.end_with?(ext.to_s)
return "#{file_set.id}_#{fn}.#{ext}"
return "#{file_set.id}_#{fn}" if mime.to_s == ext_mime.to_s
return "#{file_set.id}_#{fn}.#{mime.to_sym.to_s}"
end
end
end
Expand Down

0 comments on commit 1f51be1

Please sign in to comment.