Patch #1023 ยป attachment_thumbs.diff
app/controllers/attachments_controller.rb (working copy) | ||
---|---|---|
21 | 21 | |
22 | 22 |
def download |
23 | 23 |
# images are sent inline |
24 |
send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename), |
|
24 |
send_file params[:thumb] ? @attachment.thumbfile : @attachment.diskfile, |
|
25 |
:filename => filename_for_content_disposition(@attachment.filename), |
|
25 | 26 |
:type => @attachment.content_type, |
26 | 27 |
:disposition => (@attachment.image? ? 'inline' : 'attachment') |
27 | 28 |
rescue |
28 | 29 |
# in case the disk file was deleted |
29 | 30 |
render_404 |
30 | 31 |
end |
31 |
|
|
32 | ||
32 | 33 |
private |
33 | 34 |
def find_project |
34 | 35 |
@attachment = Attachment.find(params[:id]) |
app/views/attachments/_links.rhtml (working copy) | ||
---|---|---|
1 | 1 |
<div class="attachments"> |
2 |
<% for attachment in attachments %> |
|
3 |
<p><%= link_to attachment.filename, {:controller => 'attachments', :action => 'download', :id => attachment }, :class => 'icon icon-attachment' -%> |
|
2 |
<% attachments.each do |attachment| -%> |
|
3 |
<% if attachment.image? and File.exist?(attachment.thumbfile) -%> |
|
4 |
<p><%= link_to image_tag(url_for(:controller => :attachments,:action => :download,:thumb => 1,:id => attachment))+' '+attachment.filename, {:controller => 'attachments', :action => 'download', :id => attachment } -%> |
|
5 |
<% else -%> |
|
6 |
<p><%= link_to attachment.filename, {:controller => 'attachments', :action => 'download', :id => attachment }, :class => 'icon icon-attachment' %> |
|
7 |
<% end -%> |
|
4 | 8 |
<%= h(" - #{attachment.description}") unless attachment.description.blank? %> |
5 | 9 |
<span class="size">(<%= number_to_human_size attachment.filesize %>)</span> |
6 | 10 |
<% if options[:delete_url] %> |
app/models/attachment.rb (working copy) | ||
---|---|---|
51 | 51 |
nil |
52 | 52 |
end |
53 | 53 | |
54 |
def make_thumbnail |
|
55 |
img = Magick::Image.read(diskfile).first |
|
56 |
thumb = img.thumbnail(75,75) |
|
57 |
thumb.write thumbfile |
|
58 |
end |
|
59 | ||
60 |
def thumbfile |
|
61 |
"#{File.dirname(diskfile)}/thumb_#{File.basename(diskfile)}" |
|
62 |
end |
|
63 | ||
54 | 64 |
# Copy temp file to its final location |
55 | 65 |
def before_save |
56 | 66 |
if @temp_file && (@temp_file.size > 0) |
... | ... | |
59 | 69 |
f.write(@temp_file.read) |
60 | 70 |
end |
61 | 71 |
self.digest = Digest::MD5.hexdigest(File.read(diskfile)) |
72 |
make_thumbnail if image? and Object.const_defined?(:Magick) |
|
62 | 73 |
end |
63 | 74 |
# Don't save the content type if it's longer than the authorized length |
64 | 75 |
if self.content_type && self.content_type.length > 255 |