Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
7409bb2f
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
7409bb2f
编写于
7月 04, 2017
作者:
D
David Heinemeier Hansson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Actually #url needs to deal with the disposition
上级
9b9d69b3
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
17 addition
and
10 deletion
+17
-10
lib/active_file/blob.rb
lib/active_file/blob.rb
+2
-2
lib/active_file/site.rb
lib/active_file/site.rb
+1
-1
lib/active_file/site/disk_site.rb
lib/active_file/site/disk_site.rb
+3
-3
lib/active_file/site/s3_site.rb
lib/active_file/site/s3_site.rb
+3
-2
test/blob_test.rb
test/blob_test.rb
+8
-2
未找到文件。
lib/active_file/blob.rb
浏览文件 @
7409bb2f
...
@@ -33,8 +33,8 @@ def filename
...
@@ -33,8 +33,8 @@ def filename
ActiveFile
::
Filename
.
new
(
self
[
:filename
])
ActiveFile
::
Filename
.
new
(
self
[
:filename
])
end
end
def
url
(
expires_in:
5
.
minutes
)
def
url
(
expires_in:
5
.
minutes
,
disposition: :inline
)
site
.
url
key
,
expires_in:
expires_in
site
.
url
key
,
expires_in:
expires_in
,
disposition:
disposition
,
filename:
filename
end
end
...
...
lib/active_file/site.rb
浏览文件 @
7409bb2f
...
@@ -27,7 +27,7 @@ def exist?(key)
...
@@ -27,7 +27,7 @@ def exist?(key)
end
end
def
url
(
key
,
expires_in:
nil
)
def
url
(
key
,
expires_in
:
,
disposition
:,
filename
:
)
raise
NotImplementedError
raise
NotImplementedError
end
end
...
...
lib/active_file/site/disk_site.rb
浏览文件 @
7409bb2f
...
@@ -37,13 +37,13 @@ def exist?(key)
...
@@ -37,13 +37,13 @@ def exist?(key)
end
end
def
url
(
key
,
expires_in:
nil
)
def
url
(
key
,
expires_in
:
,
disposition
:,
filename
:
)
verified_key_with_expiration
=
ActiveFile
::
VerifiedKeyWithExpiration
.
encode
(
key
,
expires_in:
expires_in
)
verified_key_with_expiration
=
ActiveFile
::
VerifiedKeyWithExpiration
.
encode
(
key
,
expires_in:
expires_in
)
if
defined?
(
Rails
)
if
defined?
(
Rails
)
Rails
.
application
.
routes
.
url_helpers
.
rails_disk_blob_path
(
verified_key_with_expiration
)
Rails
.
application
.
routes
.
url_helpers
.
rails_disk_blob_path
(
verified_key_with_expiration
,
disposition:
disposition
)
else
else
"/rails/blobs/
#{
verified_key_with_expiration
}
"
"/rails/blobs/
#{
verified_key_with_expiration
}
?disposition=
#{
disposition
}
"
end
end
end
end
...
...
lib/active_file/site/s3_site.rb
浏览文件 @
7409bb2f
...
@@ -29,8 +29,9 @@ def exist?(key)
...
@@ -29,8 +29,9 @@ def exist?(key)
end
end
def
url
(
key
,
expires_in:
nil
)
def
url
(
key
,
expires_in
:,
disposition
:,
filename
:)
object_for
(
key
).
presigned_url
(
:get
,
expires_in:
expires_in
)
object_for
(
key
).
presigned_url
:get
,
expires_in:
expires_in
,
response_content_disposition:
"
#{
disposition
}
; filename=
#{
filename
}
"
end
end
def
byte_size
(
key
)
def
byte_size
(
key
)
...
...
test/blob_test.rb
浏览文件 @
7409bb2f
...
@@ -12,16 +12,22 @@ class ActiveFile::BlobTest < ActiveSupport::TestCase
...
@@ -12,16 +12,22 @@ class ActiveFile::BlobTest < ActiveSupport::TestCase
assert_equal
Digest
::
MD5
.
hexdigest
(
data
),
blob
.
checksum
assert_equal
Digest
::
MD5
.
hexdigest
(
data
),
blob
.
checksum
end
end
test
"url expiring in 5 minutes"
do
test
"url
s
expiring in 5 minutes"
do
blob
=
create_blob
blob
=
create_blob
travel_to
Time
.
now
do
travel_to
Time
.
now
do
assert_equal
"/rails/blobs/
#{
ActiveFile
::
VerifiedKeyWithExpiration
.
encode
(
blob
.
key
,
expires_in:
5
.
minutes
)
}
"
,
blob
.
url
assert_equal
expected_url_for
(
blob
),
blob
.
url
assert_equal
expected_url_for
(
blob
,
disposition: :attachment
),
blob
.
url
(
disposition: :attachment
)
end
end
end
end
private
private
def
create_blob
(
data:
"Hello world!"
,
filename:
"hello.txt"
,
content_type:
"text/plain"
)
def
create_blob
(
data:
"Hello world!"
,
filename:
"hello.txt"
,
content_type:
"text/plain"
)
ActiveFile
::
Blob
.
create_after_upload!
io:
StringIO
.
new
(
data
),
filename:
filename
,
content_type:
content_type
ActiveFile
::
Blob
.
create_after_upload!
io:
StringIO
.
new
(
data
),
filename:
filename
,
content_type:
content_type
end
end
def
expected_url_for
(
blob
,
disposition: :inline
)
"/rails/blobs/
#{
ActiveFile
::
VerifiedKeyWithExpiration
.
encode
(
blob
.
key
,
expires_in:
5
.
minutes
)
}
?disposition=
#{
disposition
}
"
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录