diff options
author | Kia Mei Somabes <kssomabes@up.edu.ph> | 2018-07-12 10:23:00 +0800 |
---|---|---|
committer | Kia Mei Somabes <kssomabes@up.edu.ph> | 2018-07-12 10:23:00 +0800 |
commit | 9f57ae11e935d2a8a2b175d8382ed87020727845 (patch) | |
tree | 87a309a07ce9f1765700bdd062544cb3c9acc398 /app/helpers | |
parent | 50c128944e5e65fb5124aeb790cc0f1ec06049d3 (diff) | |
download | gitlab-ce-9f57ae11e935d2a8a2b175d8382ed87020727845.tar.gz |
Set content-disposition header for single file download in repository
Diffstat (limited to 'app/helpers')
-rw-r--r-- | app/helpers/blob_helper.rb | 16 | ||||
-rw-r--r-- | app/helpers/workhorse_helper.rb | 4 |
2 files changed, 10 insertions, 10 deletions
diff --git a/app/helpers/blob_helper.rb b/app/helpers/blob_helper.rb index 16a8764dc41..0fec8e891b7 100644 --- a/app/helpers/blob_helper.rb +++ b/app/helpers/blob_helper.rb @@ -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') - 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' } + unless blob.raw_binary? || blob.stored_externally? + title = 'Open raw' + 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) diff --git a/app/helpers/workhorse_helper.rb b/app/helpers/workhorse_helper.rb index a82271ce0ee..980d07c8800 100644 --- a/app/helpers/workhorse_helper.rb +++ b/app/helpers/workhorse_helper.rb @@ -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 |