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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
ea52a81d
Commit
ea52a81d
authored
Dec 03, 2015
by
Marin Jankovski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move the file serving to Raw controller, add a few ifs to view.
parent
0a081e7e
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
36 additions
and
30 deletions
+36
-30
app/controllers/projects/blob_controller.rb
app/controllers/projects/blob_controller.rb
+0
-17
app/controllers/projects/raw_controller.rb
app/controllers/projects/raw_controller.rb
+24
-7
app/views/projects/blob/_actions.html.haml
app/views/projects/blob/_actions.html.haml
+3
-3
app/views/projects/blob/_blob.html.haml
app/views/projects/blob/_blob.html.haml
+4
-2
app/views/projects/blob/_download.html.haml
app/views/projects/blob/_download.html.haml
+5
-1
No files found.
app/controllers/projects/blob_controller.rb
View file @
ea52a81d
...
...
@@ -17,7 +17,6 @@ class Projects::BlobController < Projects::ApplicationController
before_action
:require_branch_head
,
only:
[
:edit
,
:update
]
before_action
:editor_variables
,
except:
[
:show
,
:preview
,
:diff
]
before_action
:after_edit_path
,
only:
[
:edit
,
:update
]
before_action
:show_lfs_object
,
only: :show
def
new
commit
unless
@repository
.
empty?
...
...
@@ -194,20 +193,4 @@ class Projects::BlobController < Projects::ApplicationController
file_content_encoding:
params
[
:encoding
]
}
end
def
show_lfs_object
return
unless
@blob
&&
@blob
.
text?
&&
@blob
.
data
.
present?
if
@blob
.
data
.
starts_with?
(
"version https://git-lfs.github.com/spec"
)
oid
=
@blob
.
data
.
match
(
/
#{
LfsObject
::
MATCH_FROM_POINTER_REGEX
}
/
)
if
oid
&&
oid
[
1
]
lfs_object
=
LfsObject
.
find_by_oid
(
oid
[
1
])
return
nil
unless
lfs_object
&&
lfs_object
.
file
.
exists?
if
lfs_object
.
projects
.
exists?
(
lfs_object
.
storage_project
(
@project
).
id
)
send_file
lfs_object
.
file
.
path
,
filename:
@blob
.
name
,
disposition:
'attachment'
end
end
end
end
end
app/controllers/projects/raw_controller.rb
View file @
ea52a81d
...
...
@@ -10,15 +10,13 @@ class Projects::RawController < Projects::ApplicationController
@blob
=
@repository
.
blob_at
(
@commit
.
id
,
@path
)
if
@blob
type
=
get_blob_type
headers
[
'X-Content-Type-Options'
]
=
'nosniff'
send_data
(
@blob
.
data
,
type:
type
,
disposition:
'inline'
)
if
@blob
.
lfs_pointer?
send_lfs_object
else
stream_data
end
else
render_404
end
...
...
@@ -35,4 +33,23 @@ class Projects::RawController < Projects::ApplicationController
'application/octet-stream'
end
end
def
stream_data
type
=
get_blob_type
send_data
(
@blob
.
data
,
type:
type
,
disposition:
'inline'
)
end
def
send_lfs_object
lfs_object
=
LfsObject
.
find_by_oid
(
@blob
.
lfs_oid
)
return
nil
unless
lfs_object
&&
lfs_object
.
file
.
exists?
if
lfs_object
.
projects
.
exists?
(
lfs_object
.
storage_project
(
@project
).
id
)
send_file
lfs_object
.
file
.
path
,
filename:
@blob
.
name
,
disposition:
'attachment'
end
end
end
app/views/projects/blob/_actions.html.haml
View file @
ea52a81d
.btn-group.tree-btn-group
=
edit_blob_link
(
@project
,
@ref
,
@path
)
=
edit_blob_link
(
@project
,
@ref
,
@path
)
unless
@blob
.
lfs_pointer?
=
link_to
'Raw'
,
namespace_project_raw_path
(
@project
.
namespace
,
@project
,
@id
),
class:
'btn btn-sm'
,
target:
'_blank'
-# only show normal/blame view links for text files
-
if
@blob
.
text?
-
if
@blob
.
text?
&&
!
@blob
.
lfs_pointer?
-
if
current_page?
namespace_project_blame_path
(
@project
.
namespace
,
@project
,
@id
)
=
link_to
'Normal View'
,
namespace_project_blob_path
(
@project
.
namespace
,
@project
,
@id
),
class:
'btn btn-sm'
...
...
@@ -16,7 +16,7 @@
=
link_to
'Permalink'
,
namespace_project_blob_path
(
@project
.
namespace
,
@project
,
tree_join
(
@commit
.
sha
,
@path
)),
class:
'btn btn-sm'
-
if
allowed_tree_edit?
-
if
allowed_tree_edit?
&&
!
@blob
.
lfs_pointer?
.btn-group
{
role:
"group"
}
%button
.btn.btn-default
{
'data-target'
=>
'#modal-upload-blob'
,
'data-toggle'
=>
'modal'
}
Replace
%button
.btn.btn-remove
{
'data-target'
=>
'#modal-remove-blob'
,
'data-toggle'
=>
'modal'
}
Delete
app/views/projects/blob/_blob.html.haml
View file @
ea52a81d
...
...
@@ -29,10 +29,12 @@
%strong
=
blob
.
name
%small
=
number_to_human_size
(
blob
.
size
)
=
number_to_human_size
(
blob
.
size
)
unless
blob
.
lfs_pointer?
.file-actions.hidden-xs
=
render
"actions"
-
if
blob
.
text?
-
if
blob
.
lfs_pointer?
=
render
"download"
,
blob:
blob
-
elsif
blob
.
text?
=
render
"text"
,
blob:
blob
-
elsif
blob
.
image?
=
render
"image"
,
blob:
blob
...
...
app/views/projects/blob/_download.html.haml
View file @
ea52a81d
...
...
@@ -4,4 +4,8 @@
%h1
.light
%i
.fa.fa-download
%h4
Download (
#{
number_to_human_size
blob
.
size
}
)
-
if
blob
.
lfs_pointer?
-
size
=
blob
.
lfs_size
-
else
-
size
=
blob
.
size
Download (
#{
number_to_human_size
size
}
)
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