Revision 967:19884e9d5eff app
| app/controllers/attachments_controller.rb | ||
|---|---|---|
| 17 | 17 |
|
| 18 | 18 |
class AttachmentsController < ApplicationController |
| 19 | 19 |
|
| 20 |
include AttachmentsHelper |
|
| 21 |
helper :attachments |
|
| 22 |
|
|
| 20 | 23 |
before_filter :find_project |
| 21 | 24 |
before_filter :file_readable, :read_authorize, :except => :destroy |
| 22 | 25 |
before_filter :delete_authorize, :only => :destroy |
| ... | ... | |
| 50 | 53 |
|
| 51 | 54 |
def download |
| 52 | 55 |
# cc: formerly this happened only if "@attachment.container.is_a?(Version)" |
| 53 |
# or Project. Not good for us, we want to tally all downloads |
|
| 54 |
@attachment.increment_download |
|
| 56 |
# or Project. Not good for us, we want to tally all downloads [by humans] |
|
| 57 |
if not user_is_search_bot? |
|
| 58 |
@attachment.increment_download |
|
| 59 |
end |
|
| 55 | 60 |
|
| 56 | 61 |
# images are sent inline |
| 57 | 62 |
send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename), |
| app/helpers/attachments_helper.rb | ||
|---|---|---|
| 42 | 42 |
api.created_on attachment.created_on |
| 43 | 43 |
end |
| 44 | 44 |
end |
| 45 |
|
|
| 46 |
# Returns true if user agent appears (approximately) to be a search |
|
| 47 |
# bot or crawler |
|
| 48 |
def user_is_search_bot? |
|
| 49 |
agent = request.env['HTTP_USER_AGENT'] |
|
| 50 |
agent and agent =~ /(bot|slurp|crawler|spider)\b/i |
|
| 51 |
end |
|
| 45 | 52 |
end |
Also available in: Unified diff