shrine-fog 1.1.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +30 -10
- data/lib/shrine/storage/fog.rb +10 -10
- data/shrine-fog.gemspec +3 -3
- metadata +19 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b3228745b8294ae999e783d9e5547be47cf31c67d5dd9ad40f98133b5739ff9
|
4
|
+
data.tar.gz: b5882ca2581c9adf8ec8570c4f758d9ec89f1c958a5c8a657f4fdf3b70b5d54d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a82144eeb24089ea7a6b4d9e9b96b226a305e52459982e183647ba8068fe62d29409e2616a0a2f40740501c76fda704cd25c1538aff39e1028008f4c8aef30d
|
7
|
+
data.tar.gz: '087f8ca4c9325a74eb5a13fc428be94cd7094023914ae7c394265b58d462d7c2cb8b81429cd3ac960390b39dd3dd9e0a60a1ab73b32ba5989a99510ff536b058'
|
data/README.md
CHANGED
@@ -52,23 +52,43 @@ instead of reuploaded.
|
|
52
52
|
|
53
53
|
### URLs
|
54
54
|
|
55
|
-
By default
|
56
|
-
to change that tell Fog not to store files publicly, you can set `:public` to
|
57
|
-
false:
|
55
|
+
By default shrine-fog will generate signed expiring URLs.
|
58
56
|
|
59
57
|
```rb
|
60
|
-
|
61
|
-
|
58
|
+
uploaded_file.url("image.jpg") #=> "https://my-bucket.s3-eu-west-1.amazonaws.com/foo?X-Amz-Expires=3600&X-Amz-Date=20151217T102105Z&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIJF55TMZZY45UT6Q/20151217/eu-west-1/s3/aws4_request&X-Amz-SignedHeaders=host&X-Amz-Signature=6908d8cd85ce4469f141a36955611f26d29ae7919eb8a6cba28f9194a92d96c3"
|
59
|
+
```
|
60
|
+
|
61
|
+
You can modify the URL expiration date via `:expires` (the default is `3600`):
|
62
|
+
|
63
|
+
```rb
|
64
|
+
uploaded_file.url("image.jpg", expires: 90) #=> "https://my-bucket.s3-eu-west-1.amazonaws.com/foo?X-Amz-Expires=90&X-Amz-Date=20151217T102105Z&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIJF55TMZZY45UT6Q/20151217/eu-west-1/s3/aws4_request&X-Amz-SignedHeaders=host&X-Amz-Signature=6908d8cd85ce4469f141a36955611f26d29ae7919eb8a6cba28f9194a92d96c3"
|
65
|
+
```
|
66
|
+
|
67
|
+
If the files you're uploading are public readable (e.g. you're passing the
|
68
|
+
correct ACL on upload, `acl: "publicRead"` for fog-google), and you want to
|
69
|
+
generate public URLs, you can pass `public: true` to `#url`:
|
70
|
+
|
71
|
+
```rb
|
72
|
+
uploaded_file.url("image.jpg", public: true) #=> "https://my-bucket.s3-eu-west-1.amazonaws.com/image.jpg"
|
73
|
+
```
|
74
|
+
|
75
|
+
Any additional URL options will be forwarded directly to the provider's
|
76
|
+
`File#url` method.
|
77
|
+
|
78
|
+
You can use the `default_url_options` Shrine plugin to set default URL options.
|
62
79
|
|
63
|
-
|
64
|
-
|
80
|
+
### Upload options
|
81
|
+
|
82
|
+
Dynamic upload options can be passed via the `upload_options` plugin:
|
83
|
+
|
84
|
+
```rb
|
85
|
+
Shrine.plugin :upload_options, store: { acl: "publicRead" }
|
65
86
|
```
|
66
87
|
|
67
|
-
|
68
|
-
seconds you want the URL to expire:
|
88
|
+
You can also specify default upload options on storage initialization:
|
69
89
|
|
70
90
|
```rb
|
71
|
-
Shrine::Storage::Fog.new(
|
91
|
+
Shrine::Storage::Fog.new(upload_options: { acl: "publicRead" }, **options)
|
72
92
|
```
|
73
93
|
|
74
94
|
### S3 or Filesystem
|
data/lib/shrine/storage/fog.rb
CHANGED
@@ -7,12 +7,11 @@ class Shrine
|
|
7
7
|
class Fog
|
8
8
|
attr_reader :connection, :directory, :prefix
|
9
9
|
|
10
|
-
def initialize(directory:, prefix: nil,
|
10
|
+
def initialize(directory:, prefix: nil, connection: nil, upload_options: {}, **options)
|
11
11
|
@connection = connection || ::Fog::Storage.new(options)
|
12
12
|
@directory = @connection.directories.new(key: directory)
|
13
13
|
@prefix = prefix
|
14
|
-
@
|
15
|
-
@expires = expires
|
14
|
+
@upload_options = upload_options
|
16
15
|
end
|
17
16
|
|
18
17
|
def upload(io, id, **upload_options)
|
@@ -35,10 +34,11 @@ class Shrine
|
|
35
34
|
file(id).destroy
|
36
35
|
end
|
37
36
|
|
38
|
-
def url(id, **options)
|
39
|
-
signed_url = file(id).url(Time.now +
|
40
|
-
|
41
|
-
|
37
|
+
def url(id, public: false, expires: 3600, **options)
|
38
|
+
signed_url = file(id).url(Time.now.utc + expires, *[**options])
|
39
|
+
|
40
|
+
if public
|
41
|
+
uri = URI.parse(signed_url)
|
42
42
|
uri.query = nil
|
43
43
|
uri.to_s
|
44
44
|
else
|
@@ -79,11 +79,11 @@ class Shrine
|
|
79
79
|
end
|
80
80
|
|
81
81
|
def put(io, id, shrine_metadata: {}, **upload_options)
|
82
|
-
options = {
|
83
|
-
options
|
82
|
+
options = { content_type: shrine_metadata["mime_type"] }
|
83
|
+
options.update(@upload_options)
|
84
84
|
options.update(upload_options)
|
85
85
|
|
86
|
-
directory.files.create(options)
|
86
|
+
directory.files.create(key: path(id), body: io, **options)
|
87
87
|
end
|
88
88
|
|
89
89
|
def copy(io, id, **upload_options)
|
data/shrine-fog.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |gem|
|
2
2
|
gem.name = "shrine-fog"
|
3
|
-
gem.version = "
|
3
|
+
gem.version = "2.0.0"
|
4
4
|
|
5
5
|
gem.required_ruby_version = ">= 2.1"
|
6
6
|
|
@@ -14,9 +14,9 @@ Gem::Specification.new do |gem|
|
|
14
14
|
gem.files = Dir["README.md", "LICENSE.txt", "lib/**/*.rb", "*.gemspec"]
|
15
15
|
gem.require_path = "lib"
|
16
16
|
|
17
|
-
gem.add_dependency "shrine", "
|
17
|
+
gem.add_dependency "shrine", ">= 2.2", "< 4"
|
18
18
|
gem.add_dependency "down", "~> 4.4"
|
19
|
-
gem.add_dependency "http", "
|
19
|
+
gem.add_dependency "http", ">= 3.2", "< 5"
|
20
20
|
|
21
21
|
gem.add_development_dependency "rake"
|
22
22
|
gem.add_development_dependency "fog-aws"
|
metadata
CHANGED
@@ -1,29 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shrine-fog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Janko Marohnić
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-09-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: shrine
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '2.2'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '4'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: '2.2'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '4'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: down
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -42,16 +48,22 @@ dependencies:
|
|
42
48
|
name: http
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
44
50
|
requirements:
|
45
|
-
- - "
|
51
|
+
- - ">="
|
46
52
|
- !ruby/object:Gem::Version
|
47
53
|
version: '3.2'
|
54
|
+
- - "<"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '5'
|
48
57
|
type: :runtime
|
49
58
|
prerelease: false
|
50
59
|
version_requirements: !ruby/object:Gem::Requirement
|
51
60
|
requirements:
|
52
|
-
- - "
|
61
|
+
- - ">="
|
53
62
|
- !ruby/object:Gem::Version
|
54
63
|
version: '3.2'
|
64
|
+
- - "<"
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '5'
|
55
67
|
- !ruby/object:Gem::Dependency
|
56
68
|
name: rake
|
57
69
|
requirement: !ruby/object:Gem::Requirement
|
@@ -152,8 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
152
164
|
- !ruby/object:Gem::Version
|
153
165
|
version: '0'
|
154
166
|
requirements: []
|
155
|
-
|
156
|
-
rubygems_version: 2.7.6
|
167
|
+
rubygems_version: 3.0.3
|
157
168
|
signing_key:
|
158
169
|
specification_version: 4
|
159
170
|
summary: Provides Fog storage for Shrine.
|