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
Jérome Perrin
gitlab-ce
Commits
0e0c760e
Commit
0e0c760e
authored
Apr 21, 2017
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor overriding max size
parent
a7fd95cd
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
32 additions
and
26 deletions
+32
-26
app/controllers/projects/blob_controller.rb
app/controllers/projects/blob_controller.rb
+2
-0
app/helpers/blob_helper.rb
app/helpers/blob_helper.rb
+8
-2
app/models/blob.rb
app/models/blob.rb
+8
-3
app/models/blob_viewer/base.rb
app/models/blob_viewer/base.rb
+11
-18
app/models/blob_viewer/download.rb
app/models/blob_viewer/download.rb
+1
-1
app/views/projects/blob/_header.html.haml
app/views/projects/blob/_header.html.haml
+1
-1
app/views/projects/blob/_viewer.html.haml
app/views/projects/blob/_viewer.html.haml
+1
-1
No files found.
app/controllers/projects/blob_controller.rb
View file @
0e0c760e
...
...
@@ -35,6 +35,8 @@ class Projects::BlobController < Projects::ApplicationController
end
def
show
@blob
.
override_max_size!
if
params
[
:override_max_size
]
==
'true'
respond_to
do
|
format
|
format
.
html
do
environment_params
=
@repository
.
branch_exists?
(
@ref
)
?
{
ref:
@ref
}
:
{
commit:
@commit
}
...
...
app/helpers/blob_helper.rb
View file @
0e0c760e
...
...
@@ -219,7 +219,13 @@ module BlobHelper
def
blob_render_error_reason
(
viewer
,
error
)
case
error
when
:too_large
"it is larger than
#{
number_to_human_size
(
viewer
.
relevant_max_size
)
}
"
max_size
=
if
viewer
.
absolutely_too_large?
viewer
.
absolute_max_size
elsif
viewer
.
too_large?
viewer
.
max_size
end
"it is larger than
#{
number_to_human_size
(
max_size
)
}
"
when
:server_side_but_stored_in_lfs
"it is stored in LFS"
end
...
...
@@ -232,7 +238,7 @@ module BlobHelper
options
<<
link_to
(
'load it anyway'
,
url_for
(
params
.
merge
(
viewer:
viewer
.
type
,
override_max_size:
true
,
format:
nil
)))
end
if
viewer
.
rich?
&&
viewer
.
blob
.
rendered_as_text?
(
override_max_size:
true
)
if
viewer
.
rich?
&&
viewer
.
blob
.
rendered_as_text?
options
<<
link_to
(
'view the source'
,
'#'
,
class:
'js-blob-viewer-switch-btn'
,
data:
{
viewer:
'simple'
})
end
...
...
app/models/blob.rb
View file @
0e0c760e
...
...
@@ -122,12 +122,17 @@ class Blob < SimpleDelegator
@rich_viewer
||=
rich_viewer_class
&
.
new
(
self
)
end
def
rendered_as_text?
(
override_max_size:
fals
e
)
simple_viewer
.
is_a?
(
BlobViewer
::
Text
)
&&
!
simple_viewer
.
render_error
(
override_max_size:
override_max_size
)
def
rendered_as_text?
(
ignore_errors:
tru
e
)
simple_viewer
.
is_a?
(
BlobViewer
::
Text
)
&&
(
ignore_errors
||
simple_viewer
.
render_error
.
nil?
)
end
def
show_viewer_switcher?
simple_viewer
.
is_a?
(
BlobViewer
::
Text
)
&&
rich_viewer
rendered_as_text?
&&
rich_viewer
end
def
override_max_size!
simple_viewer
&
.
override_max_size
=
true
rich_viewer
&
.
override_max_size
=
true
end
private
...
...
app/models/blob_viewer/base.rb
View file @
0e0c760e
...
...
@@ -5,6 +5,7 @@ module BlobViewer
delegate
:partial_path
,
:rich?
,
:simple?
,
:client_side?
,
:server_side?
,
:text_based?
,
to: :class
attr_reader
:blob
attr_accessor
:override_max_size
def
initialize
(
blob
)
@blob
=
blob
...
...
@@ -38,20 +39,20 @@ module BlobViewer
!
extensions
||
extensions
.
include?
(
blob
.
extension
)
end
def
can_override_max_siz
e?
too_large?
&&
!
too_large?
(
override_max_size:
true
)
def
too_larg
e?
blob
.
raw_size
>
max_size
end
def
relevant_max_size
if
too_large?
(
override_max_size:
true
)
absolute_max_size
elsif
too_large?
max_size
end
def
absolutely_too_large?
blob
.
raw_size
>
absolute_max_size
end
def
can_override_max_size?
too_large?
&&
!
absolutely_too_large?
end
def
render_error
(
override_max_size:
false
)
if
too_large?
(
override_max_size:
override_max_size
)
def
render_error
if
override_max_size
?
absolutely_too_large?
:
too_large?
:too_large
elsif
server_side_but_stored_in_lfs?
:server_side_but_stored_in_lfs
...
...
@@ -66,14 +67,6 @@ module BlobViewer
private
def
too_large?
(
override_max_size:
false
)
if
override_max_size
blob
.
raw_size
>
absolute_max_size
else
blob
.
raw_size
>
max_size
end
end
def
server_side_but_stored_in_lfs?
server_side?
&&
blob
.
valid_lfs_pointer?
end
...
...
app/models/blob_viewer/download.rb
View file @
0e0c760e
...
...
@@ -9,7 +9,7 @@ module BlobViewer
self
.
partial_name
=
'download'
self
.
text_based
=
false
def
render_error
(
*
)
def
render_error
nil
end
end
...
...
app/views/projects/blob/_header.html.haml
View file @
0e0c760e
...
...
@@ -15,7 +15,7 @@
=
render
'projects/blob/viewer_switcher'
,
blob:
blob
unless
blame
.btn-group
{
role:
"group"
}
<
=
copy_blob_source_button
(
blob
)
if
!
blame
&&
blob
.
rendered_as_text?
(
override_max_size:
params
[
:override_max_size
]
)
=
copy_blob_source_button
(
blob
)
if
!
blame
&&
blob
.
rendered_as_text?
(
ignore_errors:
false
)
=
open_raw_file_button
(
namespace_project_raw_path
(
@project
.
namespace
,
@project
,
@id
))
=
view_on_environment_button
(
@commit
.
sha
,
@path
,
@environment
)
if
@environment
...
...
app/views/projects/blob/_viewer.html.haml
View file @
0e0c760e
-
hidden
=
local_assigns
.
fetch
(
:hidden
,
false
)
-
render_error
=
viewer
.
render_error
(
override_max_size:
params
[
:override_max_size
])
-
render_error
=
viewer
.
render_error
-
load_asynchronously
=
local_assigns
.
fetch
(
:load_asynchronously
,
viewer
.
server_side?
)
&&
render_error
.
nil?
-
url
=
url_for
(
params
.
merge
(
viewer:
viewer
.
type
,
format: :json
))
if
load_asynchronously
...
...
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