Skip to content

Commit

Permalink
Muck weird mime types that are extremely unlikely to be encountered
Browse files Browse the repository at this point in the history
  • Loading branch information
vjt authored and tagliala committed Sep 13, 2024
1 parent d044b4a commit 35a6f71
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/heathen/filename.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,23 @@ module Filename
# Suggests a new file name base on the old one and the mime_type provided
# @return [String] a new file name, with an appropriate extension
def self.suggest(filename, mime_type)
mime_type = muck_mime_type(mime_type)
ext = File.extname(filename)
temp_file = filename[0..-(ext.length + 1)]
ext = MIME::Types[mime_type].first.preferred_extension rescue 'txt' # FIXME use a saner extension
"#{temp_file}.#{ext}"
end

## Changes weird mime types to saner ones...
def self.muck_mime_type(mime_type)
case mime_type
when 'text/x-c++', 'text/x-c'
'text/plain'
else
mime_type
end
end

# Suggests a new file name base on the old one and the mime_type provided
# The new file name will be positioned correctly in the new dir, so for
# example:
Expand Down

0 comments on commit 35a6f71

Please sign in to comment.