Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
1e0f0de3
Commit
1e0f0de3
authored
Jul 13, 2018
by
Kia Mei Somabes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor code for single file download in repository
parent
9f57ae11
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
17 additions
and
18 deletions
+17
-18
app/controllers/projects/raw_controller.rb
app/controllers/projects/raw_controller.rb
+1
-1
app/helpers/blob_helper.rb
app/helpers/blob_helper.rb
+11
-12
app/helpers/workhorse_helper.rb
app/helpers/workhorse_helper.rb
+2
-2
app/views/projects/artifacts/file.html.haml
app/views/projects/artifacts/file.html.haml
+1
-1
changelogs/unreleased/23705-add-single-file-download-in-repo.yml
...ogs/unreleased/23705-add-single-file-download-in-repo.yml
+2
-2
No files found.
app/controllers/projects/raw_controller.rb
View file @
1e0f0de3
...
@@ -18,7 +18,7 @@ class Projects::RawController < Projects::ApplicationController
...
@@ -18,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
,
params
[
:inline
]
send_git_blob
@repository
,
@blob
,
inline:
(
params
[
:inline
]
!=
'false'
)
end
end
else
else
render_404
render_404
...
...
app/helpers/blob_helper.rb
View file @
1e0f0de3
...
@@ -114,22 +114,22 @@ module BlobHelper
...
@@ -114,22 +114,22 @@ 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
,
inline:
nil
)
def
blob_raw_url
(
**
kwargs
)
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
,
**
kwargs
)
elsif
@snippet
elsif
@snippet
if
@snippet
.
project_id
if
@snippet
.
project_id
raw_project_snippet_url
(
@project
,
@snippet
,
only_path:
only_path
)
raw_project_snippet_url
(
@project
,
@snippet
,
**
kwargs
)
else
else
raw_snippet_url
(
@snippet
,
only_path:
only_path
)
raw_snippet_url
(
@snippet
,
**
kwargs
)
end
end
elsif
@blob
elsif
@blob
project_raw_url
(
@project
,
@id
,
only_path:
only_path
,
inline:
inline
)
project_raw_url
(
@project
,
@id
,
**
kwargs
)
end
end
end
end
def
blob_raw_path
def
blob_raw_path
(
**
kwargs
)
blob_raw_url
(
only_path:
true
)
blob_raw_url
(
**
kwargs
,
only_path:
true
)
end
end
# SVGs can contain malicious JavaScript; only include whitelisted
# SVGs can contain malicious JavaScript; only include whitelisted
...
@@ -226,16 +226,15 @@ module BlobHelper
...
@@ -226,16 +226,15 @@ module BlobHelper
def
open_raw_blob_button
(
blob
)
def
open_raw_blob_button
(
blob
)
return
if
blob
.
empty?
return
if
blob
.
empty?
unless
blob
.
raw_binary?
||
blob
.
stored_externally?
return
if
blob
.
raw_binary?
||
blob
.
stored_externally?
title
=
'Open raw'
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'
}
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
end
end
def
download_blob_button
(
blob
)
def
download_blob_button
(
blob
)
return
if
blob
.
empty?
return
if
blob
.
empty?
title
=
'Download'
title
=
'Download'
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'
}
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
end
def
blob_render_error_reason
(
viewer
)
def
blob_render_error_reason
(
viewer
)
...
...
app/helpers/workhorse_helper.rb
View file @
1e0f0de3
...
@@ -2,9 +2,9 @@
...
@@ -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
,
inline
)
def
send_git_blob
(
repository
,
blob
,
inline
:
true
)
headers
.
store
(
*
Gitlab
::
Workhorse
.
send_git_blob
(
repository
,
blob
))
headers
.
store
(
*
Gitlab
::
Workhorse
.
send_git_blob
(
repository
,
blob
))
inline
?
(
headers
[
'Content-Disposition'
]
=
'inline'
)
:
(
headers
[
'Content-Disposition'
]
=
'attachment'
)
headers
[
'Content-Disposition'
]
=
inline
?
'inline'
:
'attachment'
headers
[
'Content-Type'
]
=
safe_content_type
(
blob
)
headers
[
'Content-Type'
]
=
safe_content_type
(
blob
)
render
plain:
""
render
plain:
""
end
end
...
...
app/views/projects/artifacts/file.html.haml
View file @
1e0f0de3
...
@@ -27,6 +27,6 @@
...
@@ -27,6 +27,6 @@
.btn-group
{
role:
"group"
}
<
.btn-group
{
role:
"group"
}
<
=
copy_blob_source_button
(
blob
)
=
copy_blob_source_button
(
blob
)
=
open_raw
_blob_button
(
blob
)
=
download
_blob_button
(
blob
)
=
render
'projects/blob/content'
,
blob:
blob
=
render
'projects/blob/content'
,
blob:
blob
changelogs/unreleased/23705-add-single-file-download-in-repo.yml
View file @
1e0f0de3
---
---
title
:
Add download button for single file (including raw files) in repository
title
:
Add download button for single file (including raw files) in repository
merge_request
:
merge_request
:
20480
author
:
author
:
Kia Mei Somabes
type
:
added
type
:
added
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment