Mercurial > hg > soundsoftware-site
changeset 968:6b978669cdac live
Merge from branch "bug_521"
author | Chris Cannam |
---|---|
date | Wed, 17 Oct 2012 10:42:37 +0100 |
parents | e89e425134ae (current diff) 19884e9d5eff (diff) |
children | e632838adb35 710921c48f06 |
files | |
diffstat | 2 files changed, 14 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/app/controllers/attachments_controller.rb Tue Oct 16 16:47:51 2012 +0100 +++ b/app/controllers/attachments_controller.rb Wed Oct 17 10:42:37 2012 +0100 @@ -17,6 +17,9 @@ class AttachmentsController < ApplicationController + include AttachmentsHelper + helper :attachments + before_filter :find_project before_filter :file_readable, :read_authorize, :except => :destroy before_filter :delete_authorize, :only => :destroy @@ -50,8 +53,10 @@ def download # cc: formerly this happened only if "@attachment.container.is_a?(Version)" - # or Project. Not good for us, we want to tally all downloads - @attachment.increment_download + # or Project. Not good for us, we want to tally all downloads [by humans] + if not user_is_search_bot? + @attachment.increment_download + end # images are sent inline send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename),
--- a/app/helpers/attachments_helper.rb Tue Oct 16 16:47:51 2012 +0100 +++ b/app/helpers/attachments_helper.rb Wed Oct 17 10:42:37 2012 +0100 @@ -42,4 +42,11 @@ api.created_on attachment.created_on end end + + # Returns true if user agent appears (approximately) to be a search + # bot or crawler + def user_is_search_bot? + agent = request.env['HTTP_USER_AGENT'] + agent and agent =~ /(bot|slurp|crawler|spider)\b/i + end end