Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2018-07-20 16:35:27 +0300
committerDouwe Maan <douwe@gitlab.com>2018-07-20 16:35:27 +0300
commitf8bedb755f098486503534be872d0851e0bbd061 (patch)
treea8a2ba861f2e430e8d2bceb2df27f8654031ef0e /app/helpers
parent470e526a2053a9a1b726380d851679d30fe46ea7 (diff)
parent3239860f0aea2ff7721f36b4c424e6e8957c51c7 (diff)
Merge branch '23705-add-single-file-download-in-repo' into 'master'
Resolve "Ability to download single file" Closes #23705 See merge request gitlab-org/gitlab-ce!20480
Diffstat (limited to 'app/helpers')
-rw-r--r--app/helpers/blob_helper.rb31
-rw-r--r--app/helpers/workhorse_helper.rb4
2 files changed, 18 insertions, 17 deletions
diff --git a/app/helpers/blob_helper.rb b/app/helpers/blob_helper.rb
index 3db28fd6da3..7eb45ddd117 100644
--- a/app/helpers/blob_helper.rb
+++ b/app/helpers/blob_helper.rb
@@ -114,22 +114,22 @@ module BlobHelper
icon("#{file_type_icon_class('file', mode, name)} fw")
end
- def blob_raw_url(only_path: false)
+ def blob_raw_url(**kwargs)
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, **kwargs)
elsif @snippet
if @snippet.project_id
- raw_project_snippet_url(@project, @snippet, only_path: only_path)
+ raw_project_snippet_url(@project, @snippet, **kwargs)
else
- raw_snippet_url(@snippet, only_path: only_path)
+ raw_snippet_url(@snippet, **kwargs)
end
elsif @blob
- project_raw_url(@project, @id, only_path: only_path)
+ project_raw_url(@project, @id, **kwargs)
end
end
- def blob_raw_path
- blob_raw_url(only_path: true)
+ def blob_raw_path(**kwargs)
+ blob_raw_url(**kwargs, only_path: true)
end
# SVGs can contain malicious JavaScript; only include whitelisted
@@ -226,16 +226,17 @@ module BlobHelper
def open_raw_blob_button(blob)
return if blob.empty?
+ return if blob.raw_binary? || blob.stored_externally?
- if blob.raw_binary? || blob.stored_externally?
- icon = sprite_icon('download')
- title = 'Download'
- else
- icon = icon('file-code-o')
- title = 'Open raw'
- end
+ title = 'Open raw'
+ link_to icon('file-code-o'), blob_raw_path, class: 'btn btn-sm has-tooltip', target: '_blank', rel: 'noopener noreferrer', title: title, data: { container: 'body' }
+ end
+
+ def download_blob_button(blob)
+ return if blob.empty?
- link_to icon, blob_raw_path, class: 'btn btn-sm has-tooltip', target: '_blank', rel: 'noopener noreferrer', title: title, data: { container: 'body' }
+ title = 'Download'
+ link_to sprite_icon('download'), blob_raw_path(inline: false), 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..fd1d78bd9b8 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: true)
headers.store(*Gitlab::Workhorse.send_git_blob(repository, blob))
- headers['Content-Disposition'] = 'inline'
+ headers['Content-Disposition'] = inline ? 'inline' : 'attachment'
headers['Content-Type'] = safe_content_type(blob)
render plain: ""
end