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
|
def show
|
||||||
@blob = @repository.blob_at(@commit.id, @path)
|
@blob = @repository.blob_at(@commit.id, @path)
|
||||||
|
|
||||||
if @blob
|
if @blob
|
||||||
headers['X-Content-Type-Options'] = 'nosniff'
|
headers['X-Content-Type-Options'] = 'nosniff'
|
||||||
|
|
||||||
|
@ -19,7 +18,7 @@ class Projects::RawController < Projects::ApplicationController
|
||||||
if @blob.stored_externally?
|
if @blob.stored_externally?
|
||||||
send_lfs_object
|
send_lfs_object
|
||||||
else
|
else
|
||||||
send_git_blob @repository, @blob
|
send_git_blob @repository, @blob, params[:inline]
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
render_404
|
render_404
|
||||||
|
|
|
@ -114,7 +114,7 @@ module BlobHelper
|
||||||
icon("#{file_type_icon_class('file', mode, name)} fw")
|
icon("#{file_type_icon_class('file', mode, name)} fw")
|
||||||
end
|
end
|
||||||
|
|
||||||
def blob_raw_url(only_path: false)
|
def blob_raw_url(only_path: false, inline: nil)
|
||||||
if @build && @entry
|
if @build && @entry
|
||||||
raw_project_job_artifacts_url(@project, @build, path: @entry.path, only_path: only_path)
|
raw_project_job_artifacts_url(@project, @build, path: @entry.path, only_path: only_path)
|
||||||
elsif @snippet
|
elsif @snippet
|
||||||
|
@ -124,7 +124,7 @@ module BlobHelper
|
||||||
raw_snippet_url(@snippet, only_path: only_path)
|
raw_snippet_url(@snippet, only_path: only_path)
|
||||||
end
|
end
|
||||||
elsif @blob
|
elsif @blob
|
||||||
project_raw_url(@project, @id, only_path: only_path)
|
project_raw_url(@project, @id, only_path: only_path, inline: inline)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -226,16 +226,16 @@ module BlobHelper
|
||||||
|
|
||||||
def open_raw_blob_button(blob)
|
def open_raw_blob_button(blob)
|
||||||
return if blob.empty?
|
return if blob.empty?
|
||||||
icon = icon('file-code-o')
|
unless blob.raw_binary? || blob.stored_externally?
|
||||||
title = 'Open raw'
|
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
|
end
|
||||||
|
|
||||||
def download_button(blob)
|
def download_blob_button(blob)
|
||||||
return if blob.empty?
|
return if blob.empty?
|
||||||
icon = sprite_icon('download')
|
|
||||||
title = '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
|
end
|
||||||
|
|
||||||
def blob_render_error_reason(viewer)
|
def blob_render_error_reason(viewer)
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
# Workhorse will also serve files when using `send_file`.
|
# Workhorse will also serve files when using `send_file`.
|
||||||
module WorkhorseHelper
|
module WorkhorseHelper
|
||||||
# Send a Git blob through Workhorse
|
# 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.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)
|
headers['Content-Type'] = safe_content_type(blob)
|
||||||
render plain: ""
|
render plain: ""
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,9 +7,8 @@
|
||||||
|
|
||||||
.btn-group{ role: "group" }<
|
.btn-group{ role: "group" }<
|
||||||
= copy_blob_source_button(blob) unless blame
|
= copy_blob_source_button(blob) unless blame
|
||||||
- if !(blob.raw_binary? || blob.stored_externally?)
|
= open_raw_blob_button(blob)
|
||||||
= open_raw_blob_button(blob)
|
= download_blob_button(blob)
|
||||||
= download_button(blob)
|
|
||||||
= view_on_environment_button(@commit.sha, @path, @environment) if @environment
|
= view_on_environment_button(@commit.sha, @path, @environment) if @environment
|
||||||
.btn-group{ role: "group" }<
|
.btn-group{ role: "group" }<
|
||||||
= render_if_exists 'projects/blob/header_file_locks_link'
|
= render_if_exists 'projects/blob/header_file_locks_link'
|
||||||
|
|
Loading…
Reference in a new issue