Set content-disposition header for single file download in repository
This commit is contained in:
parent
50c128944e
commit
9f57ae11e9
4 changed files with 13 additions and 15 deletions
|
@ -10,7 +10,6 @@ class Projects::RawController < Projects::ApplicationController
|
|||
|
||||
def show
|
||||
@blob = @repository.blob_at(@commit.id, @path)
|
||||
|
||||
if @blob
|
||||
headers['X-Content-Type-Options'] = 'nosniff'
|
||||
|
||||
|
@ -19,7 +18,7 @@ class Projects::RawController < Projects::ApplicationController
|
|||
if @blob.stored_externally?
|
||||
send_lfs_object
|
||||
else
|
||||
send_git_blob @repository, @blob
|
||||
send_git_blob @repository, @blob, params[:inline]
|
||||
end
|
||||
else
|
||||
render_404
|
||||
|
|
|
@ -114,7 +114,7 @@ module BlobHelper
|
|||
icon("#{file_type_icon_class('file', mode, name)} fw")
|
||||
end
|
||||
|
||||
def blob_raw_url(only_path: false)
|
||||
def blob_raw_url(only_path: false, inline: nil)
|
||||
if @build && @entry
|
||||
raw_project_job_artifacts_url(@project, @build, path: @entry.path, only_path: only_path)
|
||||
elsif @snippet
|
||||
|
@ -124,7 +124,7 @@ module BlobHelper
|
|||
raw_snippet_url(@snippet, only_path: only_path)
|
||||
end
|
||||
elsif @blob
|
||||
project_raw_url(@project, @id, only_path: only_path)
|
||||
project_raw_url(@project, @id, only_path: only_path, inline: inline)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -226,16 +226,16 @@ module BlobHelper
|
|||
|
||||
def open_raw_blob_button(blob)
|
||||
return if blob.empty?
|
||||
icon = icon('file-code-o')
|
||||
unless blob.raw_binary? || blob.stored_externally?
|
||||
title = 'Open raw'
|
||||
link_to icon, blob_raw_path, class: 'btn btn-sm has-tooltip', target: '_blank', rel: 'noopener noreferrer', title: title, data: { container: 'body' }
|
||||
link_to icon('file-code-o'), blob_raw_url(:inline => true), class: 'btn btn-sm has-tooltip', target: '_blank', rel: 'noopener noreferrer', title: title, data: { container: 'body' }
|
||||
end
|
||||
end
|
||||
|
||||
def download_button(blob)
|
||||
def download_blob_button(blob)
|
||||
return if blob.empty?
|
||||
icon = sprite_icon('download')
|
||||
title = 'Download'
|
||||
link_to icon, blob_raw_path, download: '', class: 'btn btn-sm has-tooltip', target: '_blank', rel: 'noopener noreferrer', title: title, data: { container: 'body' }
|
||||
link_to sprite_icon('download'), blob_raw_url, download: @path, class: 'btn btn-sm has-tooltip', target: '_blank', rel: 'noopener noreferrer', title: title, data: { container: 'body' }
|
||||
end
|
||||
|
||||
def blob_render_error_reason(viewer)
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
# Workhorse will also serve files when using `send_file`.
|
||||
module WorkhorseHelper
|
||||
# Send a Git blob through Workhorse
|
||||
def send_git_blob(repository, blob)
|
||||
def send_git_blob(repository, blob, inline)
|
||||
headers.store(*Gitlab::Workhorse.send_git_blob(repository, blob))
|
||||
headers['Content-Disposition'] = 'inline'
|
||||
inline ? (headers['Content-Disposition'] = 'inline') : (headers['Content-Disposition'] = 'attachment')
|
||||
headers['Content-Type'] = safe_content_type(blob)
|
||||
render plain: ""
|
||||
end
|
||||
|
|
|
@ -7,9 +7,8 @@
|
|||
|
||||
.btn-group{ role: "group" }<
|
||||
= copy_blob_source_button(blob) unless blame
|
||||
- if !(blob.raw_binary? || blob.stored_externally?)
|
||||
= open_raw_blob_button(blob)
|
||||
= download_button(blob)
|
||||
= download_blob_button(blob)
|
||||
= view_on_environment_button(@commit.sha, @path, @environment) if @environment
|
||||
.btn-group{ role: "group" }<
|
||||
= render_if_exists 'projects/blob/header_file_locks_link'
|
||||
|
|
Loading…
Reference in a new issue