Use the mime-types gem for getting mime types from filenames (#15790).
git-svn-id: http://svn.redmine.org/redmine/trunk@12483 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
1f50862586
commit
e1189c5335
1
Gemfile
1
Gemfile
|
@ -5,6 +5,7 @@ gem "jquery-rails", "~> 2.0.2"
|
||||||
gem "coderay", "~> 1.1.0"
|
gem "coderay", "~> 1.1.0"
|
||||||
gem "fastercsv", "~> 1.5.0", :platforms => [:mri_18, :mingw_18, :jruby]
|
gem "fastercsv", "~> 1.5.0", :platforms => [:mri_18, :mingw_18, :jruby]
|
||||||
gem "builder", "3.0.0"
|
gem "builder", "3.0.0"
|
||||||
|
gem "mime-types"
|
||||||
|
|
||||||
# Optional gem for LDAP authentication
|
# Optional gem for LDAP authentication
|
||||||
group :ldap do
|
group :ldap do
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
# along with this program; if not, write to the Free Software
|
# along with this program; if not, write to the Free Software
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
|
require 'mime/types'
|
||||||
|
|
||||||
module Redmine
|
module Redmine
|
||||||
module MimeType
|
module MimeType
|
||||||
|
|
||||||
|
@ -42,26 +44,8 @@ module Redmine
|
||||||
'image/png' => 'png',
|
'image/png' => 'png',
|
||||||
'image/tiff' => 'tiff,tif',
|
'image/tiff' => 'tiff,tif',
|
||||||
'image/x-ms-bmp' => 'bmp',
|
'image/x-ms-bmp' => 'bmp',
|
||||||
'image/x-xpixmap' => 'xpm',
|
|
||||||
'image/svg+xml'=> 'svg',
|
|
||||||
'application/javascript' => 'js',
|
'application/javascript' => 'js',
|
||||||
'application/pdf' => 'pdf',
|
'application/pdf' => 'pdf',
|
||||||
'application/rtf' => 'rtf',
|
|
||||||
'application/msword' => 'doc',
|
|
||||||
'application/vnd.ms-excel' => 'xls',
|
|
||||||
'application/vnd.ms-powerpoint' => 'ppt,pps',
|
|
||||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'docx',
|
|
||||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'xlsx',
|
|
||||||
'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'pptx',
|
|
||||||
'application/vnd.openxmlformats-officedocument.presentationml.slideshow' => 'ppsx',
|
|
||||||
'application/vnd.oasis.opendocument.spreadsheet' => 'ods',
|
|
||||||
'application/vnd.oasis.opendocument.text' => 'odt',
|
|
||||||
'application/vnd.oasis.opendocument.presentation' => 'odp',
|
|
||||||
'application/x-7z-compressed' => '7z',
|
|
||||||
'application/x-rar-compressed' => 'rar',
|
|
||||||
'application/x-tar' => 'tar',
|
|
||||||
'application/zip' => 'zip',
|
|
||||||
'application/x-gzip' => 'gz',
|
|
||||||
}.freeze
|
}.freeze
|
||||||
|
|
||||||
EXTENSIONS = MIME_TYPES.inject({}) do |map, (type, exts)|
|
EXTENSIONS = MIME_TYPES.inject({}) do |map, (type, exts)|
|
||||||
|
@ -73,7 +57,11 @@ module Redmine
|
||||||
def self.of(name)
|
def self.of(name)
|
||||||
return nil unless name
|
return nil unless name
|
||||||
m = name.to_s.match(/(^|\.)([^\.]+)$/)
|
m = name.to_s.match(/(^|\.)([^\.]+)$/)
|
||||||
EXTENSIONS[m[2].downcase] if m
|
ext = m[2].downcase
|
||||||
|
type = nil
|
||||||
|
type = EXTENSIONS[ext] if m
|
||||||
|
type ||= MIME::Types.find {|type| type.extensions.include?(ext)}.to_s.presence
|
||||||
|
type
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the css class associated to
|
# Returns the css class associated to
|
||||||
|
|
|
@ -58,4 +58,9 @@ class Redmine::MimeTypeTest < ActiveSupport::TestCase
|
||||||
assert_equal expected, Redmine::MimeType.is_type?(*args)
|
assert_equal expected, Redmine::MimeType.is_type?(*args)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_should_default_to_mime_type_gem
|
||||||
|
assert !Redmine::MimeType::EXTENSIONS.keys.include?("zip")
|
||||||
|
assert_equal "application/zip", Redmine::MimeType.of("file.zip")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue