Project

General

Profile

Patch #29359 » mime_type.rb.patch

Pavel Rosický, 2018-08-10 21:42

View differences:

mime_type.rb (working copy)
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require 'mime/types'
module Redmine
module MimeType
......
# returns mime type for name or nil if unknown
def self.of(name)
return nil unless name.present?
if m = name.to_s.match(/(^|\.)([^\.]+)$/)
extension = m[2].downcase
@known_types ||= Hash.new do |h, ext|
type = EXTENSIONS[ext]
type ||= MIME::Types.type_for(ext).first.to_s.presence
h[ext] = type
ext = File.extname(name)[1..-1].to_s
ext.downcase!
EXTENSIONS[ext] ||
MiniMime::Db::LOCK.synchronize do
db = MiniMime::Db.instance_variable_get(:@db)
db ||= MiniMime::Db.instance_variable_set(:@db, MiniMime::Db.new)
lookup = db.lookup_by_extension(ext)
lookup.content_type if lookup
end
@known_types[extension]
end
end
# Returns the css class associated to
# the mime type of name
def self.css_class_of(name)
mime = of(name)
mime && mime.gsub('/', '-')
mime && mime.tr('/', '-')
end
def self.main_mimetype_of(name)
(2-2/7)