shrine 3.0.1 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of shrine might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -0
- data/LICENSE.txt +1 -1
- data/README.md +7 -2
- data/doc/advantages.md +29 -12
- data/doc/carrierwave.md +54 -22
- data/doc/changing_derivatives.md +39 -39
- data/doc/getting_started.md +63 -58
- data/doc/multiple_files.md +5 -3
- data/doc/paperclip.md +92 -33
- data/doc/plugins/activerecord.md +1 -1
- data/doc/plugins/data_uri.md +2 -2
- data/doc/plugins/derivation_endpoint.md +26 -28
- data/doc/plugins/derivatives.md +170 -142
- data/doc/plugins/determine_mime_type.md +2 -2
- data/doc/plugins/infer_extension.md +2 -2
- data/doc/plugins/instrumentation.md +1 -1
- data/doc/plugins/metadata_attributes.md +21 -10
- data/doc/plugins/persistence.md +1 -0
- data/doc/plugins/refresh_metadata.md +5 -4
- data/doc/plugins/remote_url.md +2 -2
- data/doc/plugins/signature.md +11 -2
- data/doc/plugins/store_dimensions.md +2 -2
- data/doc/plugins/upload_endpoint.md +7 -11
- data/doc/plugins/validation_helpers.md +3 -3
- data/doc/processing.md +5 -5
- data/doc/refile.md +30 -9
- data/doc/release_notes/2.19.0.md +1 -1
- data/doc/release_notes/3.0.1.md +4 -0
- data/doc/release_notes/3.1.0.md +73 -0
- data/doc/securing_uploads.md +1 -1
- data/doc/storage/file_system.md +1 -1
- data/doc/storage/s3.md +1 -5
- data/doc/upgrading_to_3.md +4 -2
- data/doc/validation.md +3 -2
- data/lib/shrine.rb +1 -2
- data/lib/shrine/attacher.rb +4 -4
- data/lib/shrine/attachment.rb +3 -3
- data/lib/shrine/plugins/add_metadata.rb +1 -5
- data/lib/shrine/plugins/default_storage.rb +6 -6
- data/lib/shrine/plugins/derivatives.rb +4 -3
- data/lib/shrine/plugins/signature.rb +7 -6
- data/lib/shrine/plugins/store_dimensions.rb +18 -9
- data/lib/shrine/uploaded_file.rb +0 -1
- data/lib/shrine/version.rb +2 -2
- metadata +3 -2
data/doc/securing_uploads.md
CHANGED
@@ -151,7 +151,7 @@ processing:
|
|
151
151
|
```rb
|
152
152
|
class ImageUploader < Shrine
|
153
153
|
# ...
|
154
|
-
Attacher.
|
154
|
+
Attacher.derivatives do |original|
|
155
155
|
width, height = Shrine.dimensions(original)
|
156
156
|
|
157
157
|
fail ImageBombError if width > 5000 || height > 5000
|
data/doc/storage/file_system.md
CHANGED
data/doc/storage/s3.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
---
|
2
|
-
title:
|
2
|
+
title: AWS S3
|
3
3
|
---
|
4
4
|
|
5
5
|
The S3 storage handles uploads to Amazon S3 service, using the [aws-sdk-s3]
|
@@ -232,10 +232,6 @@ When downloading encrypted S3 objects, the same server-side encryption
|
|
232
232
|
parameters need to be passed in.
|
233
233
|
|
234
234
|
```rb
|
235
|
-
s3.download("key", sse_customer_algorithm: "AES256",
|
236
|
-
sse_customer_key: "secret_key",
|
237
|
-
sse_customer_key_md5: "secret_key_md5")
|
238
|
-
|
239
235
|
s3.open("key", sse_customer_algorithm: "AES256",
|
240
236
|
sse_customer_key: "secret_key",
|
241
237
|
sse_customer_key_md5: "secret_key_md5")
|
data/doc/upgrading_to_3.md
CHANGED
@@ -283,7 +283,7 @@ attacher.destroy_background # calls destroy block
|
|
283
283
|
## Versions
|
284
284
|
|
285
285
|
The `versions`, `processing`, `recache`, and `delete_raw` plugins have been
|
286
|
-
deprecated in favour of the new [`derivatives`][derivatives] plugin. Let's
|
286
|
+
deprecated in favour of the new **[`derivatives`][derivatives]** plugin. Let's
|
287
287
|
assume you have the following `versions` code:
|
288
288
|
|
289
289
|
```rb
|
@@ -318,7 +318,8 @@ else
|
|
318
318
|
end
|
319
319
|
```
|
320
320
|
|
321
|
-
With `derivatives
|
321
|
+
With `derivatives`, the original file is automatically downloaded and retained,
|
322
|
+
so the code is now much simpler:
|
322
323
|
|
323
324
|
```rb
|
324
325
|
Shrine.plugin :derivatives, versions_compatibility: true # handle versions column format
|
@@ -328,6 +329,7 @@ class ImageUploader < Shrine
|
|
328
329
|
Attacher.derivatives_processor do |original|
|
329
330
|
magick = ImageProcessing::MiniMagick.source(original)
|
330
331
|
|
332
|
+
# the :original file should NOT be included anymore
|
331
333
|
{
|
332
334
|
large: magick.resize_to_limit!(800, 800),
|
333
335
|
medium: magick.resize_to_limit!(500, 500),
|
data/doc/validation.md
CHANGED
@@ -88,10 +88,11 @@ when defining more validations:
|
|
88
88
|
class ApplicationUploader < Shrine
|
89
89
|
Attacher.validate { validate_max_size 5*1024*1024 }
|
90
90
|
end
|
91
|
-
|
91
|
+
```
|
92
|
+
```rb
|
92
93
|
class ImageUploader < ApplicationUploader
|
93
94
|
Attacher.validate do
|
94
|
-
super() # empty
|
95
|
+
super() # empty parentheses are required
|
95
96
|
validate_mime_type %w[image/jpeg image/png image/webp]
|
96
97
|
end
|
97
98
|
end
|
data/lib/shrine.rb
CHANGED
@@ -11,8 +11,7 @@ require "json"
|
|
11
11
|
require "tempfile"
|
12
12
|
require "logger"
|
13
13
|
|
14
|
-
# Core class that
|
15
|
-
# Base implementation is defined in InstanceMethods and ClassMethods.
|
14
|
+
# Core class that handles uploading files to specified storage.
|
16
15
|
class Shrine
|
17
16
|
# A generic exception used by Shrine.
|
18
17
|
class Error < StandardError; end
|
data/lib/shrine/attacher.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class Shrine
|
4
|
-
# Core class
|
5
|
-
#
|
4
|
+
# Core class that handles attaching files. It uses Shrine and
|
5
|
+
# Shrine::UploadedFile objects internally.
|
6
6
|
class Attacher
|
7
7
|
@shrine_class = ::Shrine
|
8
8
|
|
@@ -46,9 +46,9 @@ class Shrine
|
|
46
46
|
end
|
47
47
|
|
48
48
|
# Returns the temporary storage identifier.
|
49
|
-
def cache_key; @cache; end
|
49
|
+
def cache_key; @cache.to_sym; end
|
50
50
|
# Returns the permanent storage identifier.
|
51
|
-
def store_key; @store; end
|
51
|
+
def store_key; @store.to_sym; end
|
52
52
|
|
53
53
|
# Returns the uploader that is used for the temporary storage.
|
54
54
|
def cache; shrine_class.new(cache_key); end
|
data/lib/shrine/attachment.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class Shrine
|
4
|
-
# Core class
|
5
|
-
#
|
6
|
-
#
|
4
|
+
# Core class that provides an attachment interface for a specified attribute
|
5
|
+
# name, which can be added to model/entity classes. The model/entity plugins
|
6
|
+
# define the main interface, which delegates to a Shrine::Attacher object.
|
7
7
|
class Attachment < Module
|
8
8
|
@shrine_class = ::Shrine
|
9
9
|
|
@@ -22,7 +22,7 @@ class Shrine
|
|
22
22
|
private
|
23
23
|
|
24
24
|
def _metadata_method(name)
|
25
|
-
|
25
|
+
self::UploadedFile.send(:define_method, name) do
|
26
26
|
metadata[name.to_s]
|
27
27
|
end
|
28
28
|
end
|
@@ -54,10 +54,6 @@ class Shrine
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
57
|
-
|
58
|
-
module FileMethods
|
59
|
-
# methods will be dynamically defined here through `Shrine.add_metadata`
|
60
|
-
end
|
61
57
|
end
|
62
58
|
|
63
59
|
register_plugin(:add_metadata, AddMetadata)
|
@@ -34,12 +34,12 @@ class Shrine
|
|
34
34
|
if @cache.respond_to?(:call)
|
35
35
|
if @cache.arity == 2
|
36
36
|
Shrine.deprecation("Passing record & name argument to default storage block is deprecated and will be removed in Shrine 4. Use a block without arguments instead.")
|
37
|
-
@cache.call(record, name)
|
37
|
+
@cache.call(record, name).to_sym
|
38
38
|
else
|
39
|
-
instance_exec(&@cache)
|
39
|
+
instance_exec(&@cache).to_sym
|
40
40
|
end
|
41
41
|
else
|
42
|
-
|
42
|
+
super
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
@@ -47,12 +47,12 @@ class Shrine
|
|
47
47
|
if @store.respond_to?(:call)
|
48
48
|
if @store.arity == 2
|
49
49
|
Shrine.deprecation("Passing record & name argument to default storage block is deprecated and will be removed in Shrine 4. Use a block without arguments instead.")
|
50
|
-
@store.call(record, name)
|
50
|
+
@store.call(record, name).to_sym
|
51
51
|
else
|
52
|
-
instance_exec(&@store)
|
52
|
+
instance_exec(&@store).to_sym
|
53
53
|
end
|
54
54
|
else
|
55
|
-
|
55
|
+
super
|
56
56
|
end
|
57
57
|
end
|
58
58
|
end
|
@@ -64,6 +64,7 @@ class Shrine
|
|
64
64
|
processor
|
65
65
|
end
|
66
66
|
end
|
67
|
+
alias derivatives derivatives_processor
|
67
68
|
|
68
69
|
# Specifies default storage to which derivatives will be uploaded.
|
69
70
|
#
|
@@ -179,9 +180,9 @@ class Shrine
|
|
179
180
|
# end
|
180
181
|
#
|
181
182
|
# attacher.create_derivatives(:my_processor)
|
182
|
-
def create_derivatives(*args)
|
183
|
-
files = process_derivatives(*args)
|
184
|
-
add_derivatives(files)
|
183
|
+
def create_derivatives(*args, storage: nil, **options)
|
184
|
+
files = process_derivatives(*args, **options)
|
185
|
+
add_derivatives(files, storage: storage)
|
185
186
|
end
|
186
187
|
|
187
188
|
# Uploads given hash of files and adds uploaded files to the
|
@@ -21,10 +21,13 @@ class Shrine
|
|
21
21
|
module ClassMethods
|
22
22
|
# Calculates `algorithm` hash of the contents of the IO object, and
|
23
23
|
# encodes it into `format`.
|
24
|
-
def calculate_signature(io, algorithm, format: :hex)
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
def calculate_signature(io, algorithm, format: :hex, rewind: true)
|
25
|
+
calculator = SignatureCalculator.new(algorithm.downcase, format: format)
|
26
|
+
|
27
|
+
signature = instrument_signature(io, algorithm, format) { calculator.call(io) }
|
28
|
+
io.rewind if rewind
|
29
|
+
|
30
|
+
signature
|
28
31
|
end
|
29
32
|
alias signature calculate_signature
|
30
33
|
|
@@ -62,8 +65,6 @@ class Shrine
|
|
62
65
|
|
63
66
|
def call(io)
|
64
67
|
hash = send(:"calculate_#{algorithm}", io)
|
65
|
-
io.rewind
|
66
|
-
|
67
68
|
send(:"encode_#{format}", hash)
|
68
69
|
end
|
69
70
|
|
@@ -113,23 +113,32 @@ class Shrine
|
|
113
113
|
|
114
114
|
def extract_with_fastimage(io)
|
115
115
|
require "fastimage"
|
116
|
-
|
117
|
-
|
118
|
-
|
116
|
+
|
117
|
+
begin
|
118
|
+
FastImage.size(io, raise_on_failure: true)
|
119
|
+
rescue FastImage::FastImageException => error
|
120
|
+
on_error(error)
|
121
|
+
end
|
119
122
|
end
|
120
123
|
|
121
124
|
def extract_with_mini_magick(io)
|
122
125
|
require "mini_magick"
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
+
|
127
|
+
begin
|
128
|
+
Shrine.with_file(io) { |file| MiniMagick::Image.new(file.path).dimensions }
|
129
|
+
rescue MiniMagick::Error => error
|
130
|
+
on_error(error)
|
131
|
+
end
|
126
132
|
end
|
127
133
|
|
128
134
|
def extract_with_ruby_vips(io)
|
129
135
|
require "vips"
|
130
|
-
|
131
|
-
|
132
|
-
|
136
|
+
|
137
|
+
begin
|
138
|
+
Shrine.with_file(io) { |file| Vips::Image.new_from_file(file.path).size }
|
139
|
+
rescue Vips::Error => error
|
140
|
+
on_error(error)
|
141
|
+
end
|
133
142
|
end
|
134
143
|
|
135
144
|
def on_error(error)
|
data/lib/shrine/uploaded_file.rb
CHANGED
data/lib/shrine/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shrine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0
|
4
|
+
version: 3.1.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: 2019-
|
11
|
+
date: 2019-11-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: down
|
@@ -467,6 +467,7 @@ files:
|
|
467
467
|
- doc/release_notes/2.9.0.md
|
468
468
|
- doc/release_notes/3.0.0.md
|
469
469
|
- doc/release_notes/3.0.1.md
|
470
|
+
- doc/release_notes/3.1.0.md
|
470
471
|
- doc/retrieving_uploads.md
|
471
472
|
- doc/securing_uploads.md
|
472
473
|
- doc/storage/file_system.md
|