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
59 59
      # images are sent inline
60 60
      send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename),
61 61
                                      :type => detect_content_type(@attachment),
62
                                      :disposition => (@attachment.image? ? 'inline' : 'attachment')
62
                                      :disposition => disposition(@attachment)
63 63
    end
64 64
  end
65 65

  
......
191 191
    end
192 192
    content_type.to_s
193 193
  end
194

  
195
  def disposition(attachment)
196
    if attachment.is_image? || attachment.is_pdf?
197
      'inline'
198
    else
199
      'attachment'
200
    end
201
  end
194 202
end
app/controllers/repositories_controller.rb
173 173
      send_opt = { :filename => filename_for_content_disposition(@path.split('/').last) }
174 174
      send_type = Redmine::MimeType.of(@path)
175 175
      send_opt[:type] = send_type.to_s if send_type
176
      send_opt[:disposition] = (Redmine::MimeType.is_type?('image', @path) ? 'inline' : 'attachment')
176
      send_opt[:disposition] = disposition(@path)
177 177
      send_data @repository.cat(@path, @rev), send_opt
178 178
    else
179 179
      if !@entry.size || @entry.size <= Setting.file_max_size_displayed.to_i.kilobyte
......
441 441
    )
442 442
    graph.burn
443 443
  end
444

  
445
  def disposition(path)
446
    if Redmine::MimeType.is_type?('image', @path) || Redmine::MimeType.of(@path) == "application/pdf"
447
      'inline'
448
    else
449
      'attachment'
450
    end
451
  end
444 452
end
app/models/attachment.rb
245 245
    self.filename =~ /\.(patch|diff)$/i
246 246
  end
247 247

  
248
  def is_pdf?
249
    Redmine::MimeType.of(filename) == "application/pdf"
250
  end
251

  
248 252
  # Returns true if the file is readable
249 253
  def readable?
250 254
    File.readable?(diskfile)
(2-2/6)