end
end
+ def raw
+ entry_and_raw(true)
+ end
+
def entry
+ entry_and_raw(false)
+ end
+
+ def entry_and_raw(is_raw)
@entry = @repository.entry(@path, @rev)
(show_error_not_found; return) unless @entry
@content = @repository.cat(@path, @rev)
(show_error_not_found; return) unless @content
- if 'raw' == params[:format] ||
+ if is_raw ||
(@content.size && @content.size > Setting.file_max_size_displayed.to_i.kilobyte) ||
! is_entry_text_data?(@content, @path)
# Force the download
@changeset = @repository.find_changeset_by_name(@rev)
end
end
+ private :entry_and_raw
def is_entry_text_data?(ent, path)
# UTF-16 contains "\x00".
<% if @repository.supports_annotate? %>
<%= link_to_if action_name != 'annotate', l(:button_annotate), {:action => 'annotate', :id => @project, :repository_id => @repository.identifier_param, :path => to_path_param(@path), :rev => @rev } %> |
<% end %>
-<%= link_to(l(:button_download), {:action => 'entry', :id => @project, :repository_id => @repository.identifier_param, :path => to_path_param(@path), :rev => @rev, :format => 'raw' }) if @repository.supports_cat? %>
+<%= link_to(l(:button_download),
+ {:action => 'raw', :id => @project,
+ :repository_id => @repository.identifier_param,
+ :path => to_path_param(@path),
+ :rev => @rev}) if @repository.supports_cat? %>
<%= "(#{number_to_human_size(@entry.size)})" if @entry.size %>
</p>
post 'projects/:id/repository/:repository_id/revisions/:rev/issues', :to => 'repositories#add_related_issue'
delete 'projects/:id/repository/:repository_id/revisions/:rev/issues/:issue_id', :to => 'repositories#remove_related_issue'
get 'projects/:id/repository/:repository_id/revisions', :to => 'repositories#revisions'
- get 'projects/:id/repository/:repository_id/revisions/:rev/:format(/*path(.:ext))',
- :to => 'repositories#entry',
- :constraints => {
- :format => 'raw',
- :rev => /[a-z0-9\.\-_]+/
- }
get 'projects/:id/repository/:repository_id/revisions/:rev/:action(/*path(.:ext))',
:controller => 'repositories',
:constraints => {
- :action => /(browse|show|entry|annotate|diff)/,
+ :action => /(browse|show|entry|raw|annotate|diff)/,
:rev => /[a-z0-9\.\-_]+/
}
get 'projects/:id/repository/revision', :to => 'repositories#revision'
post 'projects/:id/repository/revisions/:rev/issues', :to => 'repositories#add_related_issue'
delete 'projects/:id/repository/revisions/:rev/issues/:issue_id', :to => 'repositories#remove_related_issue'
- get 'projects/:id/repository/revisions/:rev/:format(/*path(.:ext))',
- :to => 'repositories#entry',
- :constraints => {
- :format => 'raw',
- :rev => /[a-z0-9\.\-_]+/
- }
get 'projects/:id/repository/revisions/:rev/:action(/*path(.:ext))',
:controller => 'repositories',
:constraints => {
- :action => /(browse|show|entry|annotate|diff)/,
+ :action => /(browse|show|entry|raw|annotate|diff)/,
:rev => /[a-z0-9\.\-_]+/
}
- get 'projects/:id/repository/:repository_id/:format(/*path(.:ext))', :to => 'repositories#entry', :format => /raw/
- get 'projects/:id/repository/:repository_id/:action(/*path(.:ext))', :controller => 'repositories', :action => /(browse|show|entry|changes|annotate|diff)/
+ get 'projects/:id/repository/:repository_id/:action(/*path(.:ext))',
+ :controller => 'repositories',
+ :action => /(browse|show|entry|raw|changes|annotate|diff)/
get 'projects/:id/repository/:repository_id', :to => 'repositories#show', :path => nil
- get 'projects/:id/repository/:format(/*path(.:ext))', :to => 'repositories#entry', :format => /raw/
- get 'projects/:id/repository/:action(/*path(.:ext))', :controller => 'repositories', :action => /(browse|show|entry|changes|annotate|diff)/
+ get 'projects/:id/repository/:action(/*path(.:ext))',
+ :controller => 'repositories',
+ :action => /(browse|show|entry|raw|changes|annotate|diff)/
get 'projects/:id/repository', :to => 'repositories#show', :path => nil
# additional routes for having the file name at the end of url
map.project_module :repository do |map|
map.permission :manage_repository, {:repositories => [:new, :create, :edit, :update, :committers, :destroy]}, :require => :member
- map.permission :browse_repository, :repositories => [:show, :browse, :entry, :annotate, :changes, :diff, :stats, :graph]
+ map.permission :browse_repository, :repositories => [:show, :browse, :entry, :raw, :annotate, :changes, :diff, :stats, :graph]
map.permission :view_changesets, :repositories => [:show, :revisions, :revision]
map.permission :commit_access, {}
map.permission :manage_related_issues, {:repositories => [:add_related_issue, :remove_related_issue]}
end
def test_entry_download_no_extension
- get :entry, :id => PRJ_ID, :path => repository_path_hash(['test'])[:param],
- :format => 'raw'
+ get :raw, :id => PRJ_ID, :path => repository_path_hash(['test'])[:param]
assert_response :success
assert_equal 'application/octet-stream', @response.content_type
end
@repository.fetch_changesets
@project.reload
assert_equal NUM_REV, @repository.changesets.count
- get :entry, :id => PRJ_ID,
- :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param],
- :format => 'raw'
+ get :raw, :id => PRJ_ID,
+ :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param]
assert_response :success
assert_equal 'attachment; filename="helloworld.c"', @response.headers['Content-Disposition']
end
assert_routing(
{ :method => 'get',
:path => "/projects/redmine/repository/revisions/2/raw/#{@path_hash[:path]}" },
- { :controller => 'repositories', :action => 'entry', :id => 'redmine',
- :path => @path_hash[:param], :rev => '2', :format => 'raw' }
+ { :controller => 'repositories', :action => 'raw', :id => 'redmine',
+ :path => @path_hash[:param], :rev => '2' }
)
assert_routing(
{ :method => 'get',
assert_routing(
{ :method => 'get',
:path => "/projects/redmine/repository/foo/revisions/2/raw/#{@path_hash[:path]}" },
- { :controller => 'repositories', :action => 'entry', :id => 'redmine', :repository_id => 'foo',
- :path => @path_hash[:param], :rev => '2', :format => 'raw' }
+ { :controller => 'repositories', :action => 'raw', :id => 'redmine', :repository_id => 'foo',
+ :path => @path_hash[:param], :rev => '2' }
)
assert_routing(
{ :method => 'get',
assert_routing(
{ :method => 'get',
:path => "/projects/redmine/repository/raw/#{@path_hash[:path]}" },
- { :controller => 'repositories', :action => 'entry', :id => 'redmine',
- :path => @path_hash[:param], :format => 'raw' }
+ { :controller => 'repositories', :action => 'raw', :id => 'redmine',
+ :path => @path_hash[:param] }
)
assert_routing(
{ :method => 'get',
assert_routing(
{ :method => 'get',
:path => "/projects/redmine/repository/foo/raw/#{@path_hash[:path]}" },
- { :controller => 'repositories', :action => 'entry', :id => 'redmine', :repository_id => 'foo',
- :path => @path_hash[:param], :format => 'raw' }
+ { :controller => 'repositories', :action => 'raw', :id => 'redmine', :repository_id => 'foo',
+ :path => @path_hash[:param] }
)
assert_routing(
{ :method => 'get',