Project

General

Profile

Feature #22483 » 0001-Don-t-force-download-of-PDFs-but-show-in-browser-pre.patch

Gregor Schmidt, 2016-05-09 11:08

View differences:

app/controllers/attachments_controller.rb
# images are sent inline
send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename),
:type => detect_content_type(@attachment),
:disposition => (@attachment.image? ? 'inline' : 'attachment')
:disposition => disposition(@attachment)
end
end
......
end
content_type.to_s
end
def disposition(attachment)
if attachment.is_image? || attachment.is_pdf?
'inline'
else
'attachment'
end
end
end
app/controllers/repositories_controller.rb
send_opt = { :filename => filename_for_content_disposition(@path.split('/').last) }
send_type = Redmine::MimeType.of(@path)
send_opt[:type] = send_type.to_s if send_type
send_opt[:disposition] = (Redmine::MimeType.is_type?('image', @path) ? 'inline' : 'attachment')
send_opt[:disposition] = disposition(@path)
send_data @repository.cat(@path, @rev), send_opt
else
if !@entry.size || @entry.size <= Setting.file_max_size_displayed.to_i.kilobyte
......
)
graph.burn
end
def disposition(path)
if Redmine::MimeType.is_type?('image', @path) || Redmine::MimeType.of(@path) == "application/pdf"
'inline'
else
'attachment'
end
end
end
app/models/attachment.rb
self.filename =~ /\.(patch|diff)$/i
end
def is_pdf?
Redmine::MimeType.of(filename) == "application/pdf"
end
# Returns true if the file is readable
def readable?
File.readable?(diskfile)
(2-2/8)