Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
b0a16320
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b0a16320
编写于
5月 15, 2017
作者:
D
Douwe Maan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rename BlobViewer max_size to overridable_max_size and absolute_max_size to max_size
上级
acffc062
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
50 addition
and
42 deletion
+50
-42
app/helpers/blob_helper.rb
app/helpers/blob_helper.rb
+4
-4
app/models/blob_viewer/auxiliary.rb
app/models/blob_viewer/auxiliary.rb
+1
-1
app/models/blob_viewer/base.rb
app/models/blob_viewer/base.rb
+15
-7
app/models/blob_viewer/client_side.rb
app/models/blob_viewer/client_side.rb
+2
-2
app/models/blob_viewer/server_side.rb
app/models/blob_viewer/server_side.rb
+2
-2
app/models/blob_viewer/text.rb
app/models/blob_viewer/text.rb
+2
-2
spec/helpers/blob_helper_spec.rb
spec/helpers/blob_helper_spec.rb
+2
-2
spec/models/blob_viewer/base_spec.rb
spec/models/blob_viewer/base_spec.rb
+20
-20
spec/views/projects/blob/_viewer.html.haml_spec.rb
spec/views/projects/blob/_viewer.html.haml_spec.rb
+2
-2
未找到文件。
app/helpers/blob_helper.rb
浏览文件 @
b0a16320
...
...
@@ -226,7 +226,7 @@ module BlobHelper
def
open_raw_blob_button
(
blob
)
return
if
blob
.
empty?
if
blob
.
raw_binary?
||
blob
.
stored_externally?
icon
=
icon
(
'download'
)
title
=
'Download'
...
...
@@ -242,9 +242,9 @@ module BlobHelper
case
viewer
.
render_error
when
:too_large
max_size
=
if
viewer
.
absolutely_too_larg
e?
viewer
.
absolut
e_max_size
els
if
viewer
.
too_large?
if
viewer
.
can_override_max_siz
e?
viewer
.
overridabl
e_max_size
els
e
viewer
.
max_size
end
"it is larger than
#{
number_to_human_size
(
max_size
)
}
"
...
...
app/models/blob_viewer/auxiliary.rb
浏览文件 @
b0a16320
...
...
@@ -5,8 +5,8 @@ module BlobViewer
included
do
self
.
loading_partial_name
=
'loading_auxiliary'
self
.
type
=
:auxiliary
self
.
overridable_max_size
=
100
.
kilobytes
self
.
max_size
=
100
.
kilobytes
self
.
absolute_max_size
=
100
.
kilobytes
end
end
end
app/models/blob_viewer/base.rb
浏览文件 @
b0a16320
...
...
@@ -2,7 +2,7 @@ module BlobViewer
class
Base
PARTIAL_PATH_PREFIX
=
'projects/blob/viewers'
.
freeze
class_attribute
:partial_name
,
:loading_partial_name
,
:type
,
:extensions
,
:file_types
,
:load_async
,
:binary
,
:switcher_icon
,
:switcher_title
,
:
max_size
,
:absolute_
max_size
class_attribute
:partial_name
,
:loading_partial_name
,
:type
,
:extensions
,
:file_types
,
:load_async
,
:binary
,
:switcher_icon
,
:switcher_title
,
:
overridable_max_size
,
:
max_size
self
.
loading_partial_name
=
'loading'
...
...
@@ -59,16 +59,24 @@ module BlobViewer
self
.
class
.
load_async?
&&
render_error
.
nil?
end
def
too_larg
e?
max_size
&&
blob
.
raw_size
>
max_size
def
exceeds_overridable_max_siz
e?
overridable_max_size
&&
blob
.
raw_size
>
overridable_
max_size
end
def
absolutely_too_larg
e?
absolute_max_size
&&
blob
.
raw_size
>
absolute_
max_size
def
exceeds_max_siz
e?
max_size
&&
blob
.
raw_size
>
max_size
end
def
can_override_max_size?
too_large?
&&
!
absolutely_too_large?
exceeds_overridable_max_size?
&&
!
exceeds_max_size?
end
def
too_large?
if
override_max_size
exceeds_max_size?
else
exceeds_overridable_max_size?
end
end
# This method is used on the server side to check whether we can attempt to
...
...
@@ -83,7 +91,7 @@ module BlobViewer
# binary from `blob_raw_url` and does its own format validation and error
# rendering, especially for potentially large binary formats.
def
render_error
if
override_max_size
?
absolutely_too_large?
:
too_large?
if
too_large?
:too_large
end
end
...
...
app/models/blob_viewer/client_side.rb
浏览文件 @
b0a16320
...
...
@@ -4,8 +4,8 @@ module BlobViewer
included
do
self
.
load_async
=
false
self
.
max_size
=
10
.
megabytes
self
.
absolute_
max_size
=
50
.
megabytes
self
.
overridable_
max_size
=
10
.
megabytes
self
.
max_size
=
50
.
megabytes
end
end
end
app/models/blob_viewer/server_side.rb
浏览文件 @
b0a16320
...
...
@@ -4,8 +4,8 @@ module BlobViewer
included
do
self
.
load_async
=
true
self
.
max_size
=
2
.
megabytes
self
.
absolute_
max_size
=
5
.
megabytes
self
.
overridable_
max_size
=
2
.
megabytes
self
.
max_size
=
5
.
megabytes
end
def
prepare!
...
...
app/models/blob_viewer/text.rb
浏览文件 @
b0a16320
...
...
@@ -5,7 +5,7 @@ module BlobViewer
self
.
partial_name
=
'text'
self
.
binary
=
false
self
.
max_size
=
1
.
megabyte
self
.
absolute_
max_size
=
10
.
megabytes
self
.
overridable_
max_size
=
1
.
megabyte
self
.
max_size
=
10
.
megabytes
end
end
spec/helpers/blob_helper_spec.rb
浏览文件 @
b0a16320
...
...
@@ -118,8 +118,8 @@ describe BlobHelper do
Class
.
new
(
BlobViewer
::
Base
)
do
include
BlobViewer
::
ServerSide
self
.
max_size
=
1
.
megabyte
self
.
absolute_
max_size
=
5
.
megabytes
self
.
overridable_
max_size
=
1
.
megabyte
self
.
max_size
=
5
.
megabytes
self
.
type
=
:rich
end
end
...
...
spec/models/blob_viewer/base_spec.rb
浏览文件 @
b0a16320
...
...
@@ -11,8 +11,8 @@ describe BlobViewer::Base, model: true do
self
.
extensions
=
%w(pdf)
self
.
binary
=
true
self
.
max_size
=
1
.
megabyte
self
.
absolute_
max_size
=
5
.
megabytes
self
.
overridable_
max_size
=
1
.
megabyte
self
.
max_size
=
5
.
megabytes
end
end
...
...
@@ -69,45 +69,45 @@ describe BlobViewer::Base, model: true do
end
end
describe
'#
too_larg
e?'
do
context
'when the blob size is larger than the max size'
do
describe
'#
exceeds_overridable_max_siz
e?'
do
context
'when the blob size is larger than the
overridable
max size'
do
let
(
:blob
)
{
fake_blob
(
path:
'file.pdf'
,
size:
2
.
megabytes
)
}
it
'returns true'
do
expect
(
viewer
.
too_larg
e?
).
to
be_truthy
expect
(
viewer
.
exceeds_overridable_max_siz
e?
).
to
be_truthy
end
end
context
'when the blob size is smaller than the max size'
do
context
'when the blob size is smaller than the
overridable
max size'
do
let
(
:blob
)
{
fake_blob
(
path:
'file.pdf'
,
size:
10
.
kilobytes
)
}
it
'returns false'
do
expect
(
viewer
.
too_larg
e?
).
to
be_falsey
expect
(
viewer
.
exceeds_overridable_max_siz
e?
).
to
be_falsey
end
end
end
describe
'#
absolutely_too_larg
e?'
do
context
'when the blob size is larger than the
absolute
max size'
do
describe
'#
exceeds_max_siz
e?'
do
context
'when the blob size is larger than the max size'
do
let
(
:blob
)
{
fake_blob
(
path:
'file.pdf'
,
size:
10
.
megabytes
)
}
it
'returns true'
do
expect
(
viewer
.
absolutely_too_larg
e?
).
to
be_truthy
expect
(
viewer
.
exceeds_max_siz
e?
).
to
be_truthy
end
end
context
'when the blob size is smaller than the
absolute
max size'
do
context
'when the blob size is smaller than the max size'
do
let
(
:blob
)
{
fake_blob
(
path:
'file.pdf'
,
size:
2
.
megabytes
)
}
it
'returns false'
do
expect
(
viewer
.
absolutely_too_larg
e?
).
to
be_falsey
expect
(
viewer
.
exceeds_max_siz
e?
).
to
be_falsey
end
end
end
describe
'#can_override_max_size?'
do
context
'when the blob size is larger than the max size'
do
context
'when the blob size is larger than the
absolute
max size'
do
context
'when the blob size is larger than the
overridable
max size'
do
context
'when the blob size is larger than the max size'
do
let
(
:blob
)
{
fake_blob
(
path:
'file.pdf'
,
size:
10
.
megabytes
)
}
it
'returns false'
do
...
...
@@ -115,7 +115,7 @@ describe BlobViewer::Base, model: true do
end
end
context
'when the blob size is smaller than the
absolute
max size'
do
context
'when the blob size is smaller than the max size'
do
let
(
:blob
)
{
fake_blob
(
path:
'file.pdf'
,
size:
2
.
megabytes
)
}
it
'returns true'
do
...
...
@@ -124,7 +124,7 @@ describe BlobViewer::Base, model: true do
end
end
context
'when the blob size is smaller than the max size'
do
context
'when the blob size is smaller than the
overridable
max size'
do
let
(
:blob
)
{
fake_blob
(
path:
'file.pdf'
,
size:
10
.
kilobytes
)
}
it
'returns false'
do
...
...
@@ -139,7 +139,7 @@ describe BlobViewer::Base, model: true do
viewer
.
override_max_size
=
true
end
context
'when the blob size is larger than the
absolute
max size'
do
context
'when the blob size is larger than the max size'
do
let
(
:blob
)
{
fake_blob
(
path:
'file.pdf'
,
size:
10
.
megabytes
)
}
it
'returns :too_large'
do
...
...
@@ -147,7 +147,7 @@ describe BlobViewer::Base, model: true do
end
end
context
'when the blob size is smaller than the
absolute
max size'
do
context
'when the blob size is smaller than the max size'
do
let
(
:blob
)
{
fake_blob
(
path:
'file.pdf'
,
size:
2
.
megabytes
)
}
it
'returns nil'
do
...
...
@@ -157,7 +157,7 @@ describe BlobViewer::Base, model: true do
end
context
'when the max size is not overridden'
do
context
'when the blob size is larger than the max size'
do
context
'when the blob size is larger than the
overridable
max size'
do
let
(
:blob
)
{
fake_blob
(
path:
'file.pdf'
,
size:
2
.
megabytes
)
}
it
'returns :too_large'
do
...
...
@@ -165,7 +165,7 @@ describe BlobViewer::Base, model: true do
end
end
context
'when the blob size is smaller than the max size'
do
context
'when the blob size is smaller than the
overridable
max size'
do
let
(
:blob
)
{
fake_blob
(
path:
'file.pdf'
,
size:
10
.
kilobytes
)
}
it
'returns nil'
do
...
...
spec/views/projects/blob/_viewer.html.haml_spec.rb
浏览文件 @
b0a16320
...
...
@@ -10,8 +10,8 @@ describe 'projects/blob/_viewer.html.haml', :view do
include
BlobViewer
::
Rich
self
.
partial_name
=
'text'
self
.
max_size
=
1
.
megabyte
self
.
absolute_
max_size
=
5
.
megabytes
self
.
overridable_
max_size
=
1
.
megabyte
self
.
max_size
=
5
.
megabytes
self
.
load_async
=
true
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录