Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
b21f50d8
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,体验更适合开发者的 AI 搜索 >>
提交
b21f50d8
编写于
6月 21, 2018
作者:
G
George Claghorn
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Permit configuring the default service URL expiry
上级
9ee74265
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
17 addition
and
10 deletion
+17
-10
activestorage/app/controllers/active_storage/blobs_controller.rb
...torage/app/controllers/active_storage/blobs_controller.rb
+1
-1
activestorage/app/controllers/active_storage/representations_controller.rb
.../controllers/active_storage/representations_controller.rb
+1
-1
activestorage/app/models/active_storage/blob.rb
activestorage/app/models/active_storage/blob.rb
+2
-2
activestorage/app/models/active_storage/variant.rb
activestorage/app/models/active_storage/variant.rb
+1
-1
activestorage/lib/active_storage.rb
activestorage/lib/active_storage.rb
+1
-0
activestorage/lib/active_storage/engine.rb
activestorage/lib/active_storage/engine.rb
+1
-0
activestorage/lib/active_storage/service.rb
activestorage/lib/active_storage/service.rb
+0
-2
activestorage/test/models/blob_test.rb
activestorage/test/models/blob_test.rb
+3
-3
guides/source/configuring.md
guides/source/configuring.md
+7
-0
未找到文件。
activestorage/app/controllers/active_storage/blobs_controller.rb
浏览文件 @
b21f50d8
...
...
@@ -8,7 +8,7 @@ class ActiveStorage::BlobsController < ActiveStorage::BaseController
include
ActiveStorage
::
SetBlob
def
show
expires_in
ActiveStorage
::
Blob
.
service
.
url_expires
_in
expires_in
ActiveStorage
.
service_urls_expire
_in
redirect_to
@blob
.
service_url
(
disposition:
params
[
:disposition
])
end
end
activestorage/app/controllers/active_storage/representations_controller.rb
浏览文件 @
b21f50d8
...
...
@@ -8,7 +8,7 @@ class ActiveStorage::RepresentationsController < ActiveStorage::BaseController
include
ActiveStorage
::
SetBlob
def
show
expires_in
ActiveStorage
::
Blob
.
service
.
url_expires
_in
expires_in
ActiveStorage
.
service_urls_expire
_in
redirect_to
@blob
.
representation
(
params
[
:variation_key
]).
processed
.
service_url
(
disposition:
params
[
:disposition
])
end
end
activestorage/app/models/active_storage/blob.rb
浏览文件 @
b21f50d8
...
...
@@ -121,7 +121,7 @@ def text?
# with users. Instead, the +service_url+ should only be exposed as a redirect from a stable, possibly authenticated URL.
# Hiding the +service_url+ behind a redirect also gives you the power to change services without updating all URLs. And
# it allows permanent URLs that redirect to the +service_url+ to be cached in the view.
def
service_url
(
expires_in:
service
.
url_expires
_in
,
disposition: :inline
,
filename:
nil
,
**
options
)
def
service_url
(
expires_in:
ActiveStorage
.
service_urls_expire
_in
,
disposition: :inline
,
filename:
nil
,
**
options
)
filename
=
ActiveStorage
::
Filename
.
wrap
(
filename
||
self
.
filename
)
service
.
url
key
,
expires_in:
expires_in
,
filename:
filename
,
content_type:
content_type
,
...
...
@@ -130,7 +130,7 @@ def service_url(expires_in: service.url_expires_in, disposition: :inline, filena
# Returns a URL that can be used to directly upload a file for this blob on the service. This URL is intended to be
# short-lived for security and only generated on-demand by the client-side JavaScript responsible for doing the uploading.
def
service_url_for_direct_upload
(
expires_in:
service
.
url_expires
_in
)
def
service_url_for_direct_upload
(
expires_in:
ActiveStorage
.
service_urls_expire
_in
)
service
.
url_for_direct_upload
key
,
expires_in:
expires_in
,
content_type:
content_type
,
content_length:
byte_size
,
checksum:
checksum
end
...
...
activestorage/app/models/active_storage/variant.rb
浏览文件 @
b21f50d8
...
...
@@ -79,7 +79,7 @@ def key
# Use <tt>url_for(variant)</tt> (or the implied form, like +link_to variant+ or +redirect_to variant+) to get the stable URL
# for a variant that points to the ActiveStorage::RepresentationsController, which in turn will use this +service_call+ method
# for its redirection.
def
service_url
(
expires_in:
service
.
url_expires
_in
,
disposition: :inline
)
def
service_url
(
expires_in:
ActiveStorage
.
service_urls_expire
_in
,
disposition: :inline
)
service
.
url
key
,
expires_in:
expires_in
,
disposition:
disposition
,
filename:
filename
,
content_type:
content_type
end
...
...
activestorage/lib/active_storage.rb
浏览文件 @
b21f50d8
...
...
@@ -49,4 +49,5 @@ module ActiveStorage
mattr_accessor
:paths
,
default:
{}
mattr_accessor
:variable_content_types
,
default:
[]
mattr_accessor
:content_types_to_serve_as_binary
,
default:
[]
mattr_accessor
:service_urls_expire_in
,
default:
5
.
minutes
end
activestorage/lib/active_storage/engine.rb
浏览文件 @
b21f50d8
...
...
@@ -54,6 +54,7 @@ class Engine < Rails::Engine # :nodoc:
ActiveStorage
.
variable_content_types
=
app
.
config
.
active_storage
.
variable_content_types
||
[]
ActiveStorage
.
content_types_to_serve_as_binary
=
app
.
config
.
active_storage
.
content_types_to_serve_as_binary
||
[]
ActiveStorage
.
service_urls_expire_in
=
app
.
config
.
active_storage
.
service_urls_expire_in
||
5
.
minutes
end
end
...
...
activestorage/lib/active_storage/service.rb
浏览文件 @
b21f50d8
...
...
@@ -39,8 +39,6 @@ class Service
extend
ActiveSupport
::
Autoload
autoload
:Configurator
class_attribute
:url_expires_in
,
default:
5
.
minutes
class
<<
self
# Configure an Active Storage service by name from a set of configurations,
# typically loaded from a YAML file. The Active Storage engine uses this
...
...
activestorage/test/models/blob_test.rb
浏览文件 @
b21f50d8
...
...
@@ -151,16 +151,16 @@ class UserWithHasOneAttachedDependentFalse < User
test
"urls allow for custom options"
do
blob
=
create_blob
(
filename:
"original.txt"
)
option
s
=
[
argument
s
=
[
blob
.
key
,
expires_in:
blob
.
service
.
url_expires
_in
,
expires_in:
ActiveStorage
.
service_urls_expire
_in
,
disposition: :inline
,
content_type:
blob
.
content_type
,
filename:
blob
.
filename
,
thumb_size:
"300x300"
,
thumb_mode:
"crop"
]
assert_called_with
(
blob
.
service
,
:url
,
option
s
)
do
assert_called_with
(
blob
.
service
,
:url
,
argument
s
)
do
blob
.
service_url
(
thumb_size:
"300x300"
,
thumb_mode:
"crop"
)
end
end
...
...
guides/source/configuring.md
浏览文件 @
b21f50d8
...
...
@@ -822,6 +822,13 @@ text/javascript image/svg+xml application/postscript application/x-shockwave-fla
config
.
active_storage
.
logger
=
ActiveSupport
::
Logger
.
new
(
STDOUT
)
```
*
`config.active_storage.service_urls_expire_in`
determines the default expiry of URLs generated by:
*
`ActiveStorage::Blob#service_url`
*
`ActiveStorage::Blob#service_url_for_direct_upload`
*
`ActiveStorage::Variant#service_url`
The default is 5 minutes.
### Configuring a Database
Just about every Rails application will interact with a database. You can connect to the database by setting an environment variable
`ENV['DATABASE_URL']`
or by using a configuration file called
`config/database.yml`
.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录