carrierwave 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of carrierwave might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/README.md +14 -5
- data/lib/carrierwave.rb +4 -0
- data/lib/carrierwave/orm/activerecord.rb +5 -5
- data/lib/carrierwave/processing/mini_magick.rb +13 -0
- data/lib/carrierwave/processing/rmagick.rb +14 -1
- data/lib/carrierwave/sanitized_file.rb +1 -1
- data/lib/carrierwave/storage/fog.rb +1 -1
- data/lib/carrierwave/uploader/configuration.rb +1 -1
- data/lib/carrierwave/uploader/download.rb +5 -1
- data/lib/carrierwave/uploader/extension_whitelist.rb +2 -1
- data/lib/carrierwave/uploader/file_size.rb +4 -2
- data/lib/carrierwave/utilities/uri.rb +2 -0
- data/lib/carrierwave/validations/active_model.rb +3 -3
- data/lib/carrierwave/version.rb +1 -1
- metadata +10 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c51659746450241013cc16a8d099f4867824f70d
|
4
|
+
data.tar.gz: b86e8ff278383c7b8e8277368f127a2d1914cd5a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2396711ec0083bdc6c197eae0ec9d388024affb1590b6d244d19f50b46494baa9e553ab6182c2efdd2ed53ca80d8618e683d6dff4618ef9700b12f97ef7e8a7c
|
7
|
+
data.tar.gz: 34cdc30925d1fca9092b35834584e4b97ec977b0603c4c9f7854c0db74a24adc60ab380e8b97a96941f305e87faed6b57ca9e5d1a4bc1a3bfcf84f3db273b595
|
data/README.md
CHANGED
@@ -308,7 +308,7 @@ and cropped to exactly 200 by 200 pixels. The uploader could be used like this:
|
|
308
308
|
uploader = AvatarUploader.new
|
309
309
|
uploader.store!(my_file) # size: 1024x768
|
310
310
|
|
311
|
-
uploader.url # => '/url/to/my_file.png' # size:
|
311
|
+
uploader.url # => '/url/to/my_file.png' # size: 800x800
|
312
312
|
uploader.thumb.url # => '/url/to/thumb_my_file.png' # size: 200x200
|
313
313
|
```
|
314
314
|
|
@@ -901,19 +901,28 @@ mount_uploader :avatar, AvatarUploader, mount_on: :avatar_file_name
|
|
901
901
|
|
902
902
|
## I18n
|
903
903
|
|
904
|
-
The Active Record validations use the Rails i18n framework. Add these keys to
|
904
|
+
The Active Record validations use the Rails `i18n` framework. Add these keys to
|
905
905
|
your translations file:
|
906
906
|
|
907
907
|
```yaml
|
908
908
|
errors:
|
909
909
|
messages:
|
910
|
-
carrierwave_processing_error:
|
911
|
-
carrierwave_integrity_error:
|
912
|
-
carrierwave_download_error:
|
910
|
+
carrierwave_processing_error: failed to be processed
|
911
|
+
carrierwave_integrity_error: is not of an allowed file type
|
912
|
+
carrierwave_download_error: could not be downloaded
|
913
913
|
extension_whitelist_error: "You are not allowed to upload %{extension} files, allowed types: %{allowed_types}"
|
914
914
|
extension_blacklist_error: "You are not allowed to upload %{extension} files, prohibited types: %{prohibited_types}"
|
915
|
+
content_type_whitelist_error: "You are not allowed to upload %{content_type} files"
|
916
|
+
content_type_blacklist_error: "You are not allowed to upload %{content_type} files"
|
917
|
+
rmagick_processing_error: "Failed to manipulate with rmagick, maybe it is not an image?"
|
918
|
+
mini_magick_processing_error: "Failed to manipulate with MiniMagick, maybe it is not an image? Original Error: %{e}"
|
919
|
+
min_size_error: "File size should be greater than %{min_size}"
|
920
|
+
max_size_error: "File size should be less than %{max_size}"
|
915
921
|
```
|
916
922
|
|
923
|
+
The [`carrierwave-i18n`](https://github.com/carrierwaveuploader/carrierwave-i18n)
|
924
|
+
library adds support for additional locales.
|
925
|
+
|
917
926
|
## Large files
|
918
927
|
|
919
928
|
By default, CarrierWave copies an uploaded file twice, first copying the file into the cache, then
|
data/lib/carrierwave.rb
CHANGED
@@ -41,6 +41,10 @@ elsif defined?(Rails)
|
|
41
41
|
initializer "carrierwave.setup_paths" do |app|
|
42
42
|
CarrierWave.root = Rails.root.join(Rails.public_path).to_s
|
43
43
|
CarrierWave.base_path = ENV['RAILS_RELATIVE_URL_ROOT']
|
44
|
+
available_locales = app.config.i18n.available_locales
|
45
|
+
if available_locales.blank? || available_locales.include?(:en)
|
46
|
+
I18n.load_path.prepend(File.join(File.dirname(__FILE__), 'carrierwave', 'locale', "en.yml"))
|
47
|
+
end
|
44
48
|
end
|
45
49
|
|
46
50
|
initializer "carrierwave.active_record" do
|
@@ -15,7 +15,7 @@ module CarrierWave
|
|
15
15
|
class_eval <<-RUBY, __FILE__, __LINE__+1
|
16
16
|
def remote_#{column}_url=(url)
|
17
17
|
column = _mounter(:#{column}).serialization_column
|
18
|
-
|
18
|
+
__send__(:"\#{column}_will_change!")
|
19
19
|
super
|
20
20
|
end
|
21
21
|
RUBY
|
@@ -30,7 +30,7 @@ module CarrierWave
|
|
30
30
|
class_eval <<-RUBY, __FILE__, __LINE__+1
|
31
31
|
def remote_#{column}_urls=(url)
|
32
32
|
column = _mounter(:#{column}).serialization_column
|
33
|
-
|
33
|
+
__send__(:"\#{column}_will_change!")
|
34
34
|
super
|
35
35
|
end
|
36
36
|
RUBY
|
@@ -63,8 +63,8 @@ module CarrierWave
|
|
63
63
|
class_eval <<-RUBY, __FILE__, __LINE__+1
|
64
64
|
def #{column}=(new_file)
|
65
65
|
column = _mounter(:#{column}).serialization_column
|
66
|
-
if !(new_file.blank? &&
|
67
|
-
|
66
|
+
if !(new_file.blank? && __send__(:#{column}).blank?)
|
67
|
+
__send__(:"\#{column}_will_change!")
|
68
68
|
end
|
69
69
|
|
70
70
|
super
|
@@ -72,7 +72,7 @@ module CarrierWave
|
|
72
72
|
|
73
73
|
def remove_#{column}=(value)
|
74
74
|
column = _mounter(:#{column}).serialization_column
|
75
|
-
|
75
|
+
__send__(:"\#{column}_will_change!")
|
76
76
|
super
|
77
77
|
end
|
78
78
|
|
@@ -127,6 +127,8 @@ module CarrierWave
|
|
127
127
|
# [MiniMagick::Image] additional manipulations to perform
|
128
128
|
#
|
129
129
|
def resize_to_limit(width, height, combine_options: {})
|
130
|
+
width = dimension_from width
|
131
|
+
height = dimension_from height
|
130
132
|
manipulate! do |img|
|
131
133
|
img.combine_options do |cmd|
|
132
134
|
cmd.resize "#{width}x#{height}>"
|
@@ -152,6 +154,8 @@ module CarrierWave
|
|
152
154
|
# [MiniMagick::Image] additional manipulations to perform
|
153
155
|
#
|
154
156
|
def resize_to_fit(width, height, combine_options: {})
|
157
|
+
width = dimension_from width
|
158
|
+
height = dimension_from height
|
155
159
|
manipulate! do |img|
|
156
160
|
img.combine_options do |cmd|
|
157
161
|
cmd.resize "#{width}x#{height}"
|
@@ -178,6 +182,8 @@ module CarrierWave
|
|
178
182
|
# [MiniMagick::Image] additional manipulations to perform
|
179
183
|
#
|
180
184
|
def resize_to_fill(width, height, gravity = 'Center', combine_options: {})
|
185
|
+
width = dimension_from width
|
186
|
+
height = dimension_from height
|
181
187
|
manipulate! do |img|
|
182
188
|
cols, rows = img[:dimensions]
|
183
189
|
img.combine_options do |cmd|
|
@@ -225,6 +231,8 @@ module CarrierWave
|
|
225
231
|
# [MiniMagick::Image] additional manipulations to perform
|
226
232
|
#
|
227
233
|
def resize_and_pad(width, height, background=:transparent, gravity='Center', combine_options: {})
|
234
|
+
width = dimension_from width
|
235
|
+
height = dimension_from height
|
228
236
|
manipulate! do |img|
|
229
237
|
img.combine_options do |cmd|
|
230
238
|
cmd.thumbnail "#{width}x#{height}>"
|
@@ -319,6 +327,11 @@ module CarrierWave
|
|
319
327
|
end
|
320
328
|
end
|
321
329
|
|
330
|
+
def dimension_from(value)
|
331
|
+
return value unless value.instance_of?(Proc)
|
332
|
+
value.arity >= 1 ? value.call(self) : value.call
|
333
|
+
end
|
334
|
+
|
322
335
|
def mini_magick_image
|
323
336
|
if url
|
324
337
|
::MiniMagick::Image.open(url)
|
@@ -133,6 +133,8 @@ module CarrierWave
|
|
133
133
|
# [Magick::Image] additional manipulations to perform
|
134
134
|
#
|
135
135
|
def resize_to_limit(width, height)
|
136
|
+
width = dimension_from width
|
137
|
+
height = dimension_from height
|
136
138
|
manipulate! do |img|
|
137
139
|
geometry = Magick::Geometry.new(width, height, 0, 0, Magick::GreaterGeometry)
|
138
140
|
new_img = img.change_geometry(geometry) do |new_width, new_height|
|
@@ -162,6 +164,8 @@ module CarrierWave
|
|
162
164
|
# [Magick::Image] additional manipulations to perform
|
163
165
|
#
|
164
166
|
def resize_to_fit(width, height)
|
167
|
+
width = dimension_from width
|
168
|
+
height = dimension_from height
|
165
169
|
manipulate! do |img|
|
166
170
|
img.resize_to_fit!(width, height)
|
167
171
|
img = yield(img) if block_given?
|
@@ -186,6 +190,8 @@ module CarrierWave
|
|
186
190
|
# [Magick::Image] additional manipulations to perform
|
187
191
|
#
|
188
192
|
def resize_to_fill(width, height, gravity=::Magick::CenterGravity)
|
193
|
+
width = dimension_from width
|
194
|
+
height = dimension_from height
|
189
195
|
manipulate! do |img|
|
190
196
|
img.crop_resized!(width, height, gravity)
|
191
197
|
img = yield(img) if block_given?
|
@@ -211,6 +217,8 @@ module CarrierWave
|
|
211
217
|
# [Magick::Image] additional manipulations to perform
|
212
218
|
#
|
213
219
|
def resize_and_pad(width, height, background=:transparent, gravity=::Magick::CenterGravity)
|
220
|
+
width = dimension_from width
|
221
|
+
height = dimension_from height
|
214
222
|
manipulate! do |img|
|
215
223
|
img.resize_to_fit!(width, height)
|
216
224
|
new_img = ::Magick::Image.new(width, height) { self.background_color = background == :transparent ? 'rgba(255,255,255,0)' : background.to_s }
|
@@ -371,8 +379,13 @@ module CarrierWave
|
|
371
379
|
image.try(:destroy!)
|
372
380
|
end
|
373
381
|
|
382
|
+
def dimension_from(value)
|
383
|
+
return value unless value.instance_of?(Proc)
|
384
|
+
value.arity >= 1 ? value.call(self) : value.call
|
385
|
+
end
|
386
|
+
|
374
387
|
def rmagick_image
|
375
|
-
::Magick::Image.read
|
388
|
+
::Magick::Image.from_blob(self.read).first
|
376
389
|
end
|
377
390
|
|
378
391
|
end # RMagick
|
@@ -197,7 +197,7 @@ module CarrierWave
|
|
197
197
|
#
|
198
198
|
def move!(new_path)
|
199
199
|
if exists?
|
200
|
-
FileUtils.mv(path, new_path) unless new_path
|
200
|
+
FileUtils.mv(path, new_path) unless File.identical?(new_path, path)
|
201
201
|
else
|
202
202
|
File.open(new_path, "wb") { |f| f.write(read) }
|
203
203
|
end
|
@@ -129,7 +129,7 @@ module CarrierWave
|
|
129
129
|
eager_load_fog(value) if value && '#{name}' == 'fog_credentials'
|
130
130
|
return @#{name} if self.object_id == #{self.object_id} || defined?(@#{name})
|
131
131
|
name = superclass.#{name}
|
132
|
-
return nil if name.nil? && !instance_variable_defined?(
|
132
|
+
return nil if name.nil? && !instance_variable_defined?(:@#{name})
|
133
133
|
@#{name} = name && !name.is_a?(Module) && !name.is_a?(Symbol) && !name.is_a?(Numeric) && !name.is_a?(TrueClass) && !name.is_a?(FalseClass) ? name.dup : name
|
134
134
|
end
|
135
135
|
|
@@ -16,7 +16,7 @@ module CarrierWave
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def original_filename
|
19
|
-
filename = filename_from_header ||
|
19
|
+
filename = filename_from_header || filename_from_uri
|
20
20
|
mime_type = MIME::Types[file.content_type].first
|
21
21
|
unless File.extname(filename).present? || mime_type.blank?
|
22
22
|
filename = "#{filename}.#{mime_type.extensions.first}"
|
@@ -55,6 +55,10 @@ module CarrierWave
|
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
+
def filename_from_uri
|
59
|
+
URI.decode(File.basename(file.base_uri.path))
|
60
|
+
end
|
61
|
+
|
58
62
|
def method_missing(*args, &block)
|
59
63
|
file.send(*args, &block)
|
60
64
|
end
|
@@ -43,7 +43,8 @@ module CarrierWave
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def whitelisted_extension?(extension)
|
46
|
-
|
46
|
+
downcase_extension = extension.downcase
|
47
|
+
Array(extension_whitelist).any? { |item| downcase_extension =~ /\A#{item}\z/i }
|
47
48
|
end
|
48
49
|
|
49
50
|
end # ExtensionWhitelist
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
|
1
3
|
module CarrierWave
|
2
4
|
module Uploader
|
3
5
|
module FileSize
|
@@ -29,9 +31,9 @@ module CarrierWave
|
|
29
31
|
expected_size_range = size_range
|
30
32
|
if expected_size_range.is_a?(::Range)
|
31
33
|
if size < expected_size_range.min
|
32
|
-
raise CarrierWave::IntegrityError, I18n.translate(:"errors.messages.min_size_error", :min_size => expected_size_range.min)
|
34
|
+
raise CarrierWave::IntegrityError, I18n.translate(:"errors.messages.min_size_error", :min_size => ActiveSupport::NumberHelper.number_to_human_size(expected_size_range.min))
|
33
35
|
elsif size > expected_size_range.max
|
34
|
-
raise CarrierWave::IntegrityError, I18n.translate(:"errors.messages.max_size_error", :max_size => expected_size_range.max)
|
36
|
+
raise CarrierWave::IntegrityError, I18n.translate(:"errors.messages.max_size_error", :max_size => ActiveSupport::NumberHelper.number_to_human_size(expected_size_range.max))
|
35
37
|
end
|
36
38
|
end
|
37
39
|
end
|
@@ -11,7 +11,7 @@ module CarrierWave
|
|
11
11
|
class ProcessingValidator < ::ActiveModel::EachValidator
|
12
12
|
|
13
13
|
def validate_each(record, attribute, value)
|
14
|
-
if e = record.
|
14
|
+
if e = record.__send__("#{attribute}_processing_error")
|
15
15
|
message = (e.message == e.class.to_s) ? :carrierwave_processing_error : e.message
|
16
16
|
record.errors.add(attribute, message)
|
17
17
|
end
|
@@ -21,7 +21,7 @@ module CarrierWave
|
|
21
21
|
class IntegrityValidator < ::ActiveModel::EachValidator
|
22
22
|
|
23
23
|
def validate_each(record, attribute, value)
|
24
|
-
if e = record.
|
24
|
+
if e = record.__send__("#{attribute}_integrity_error")
|
25
25
|
message = (e.message == e.class.to_s) ? :carrierwave_integrity_error : e.message
|
26
26
|
record.errors.add(attribute, message)
|
27
27
|
end
|
@@ -31,7 +31,7 @@ module CarrierWave
|
|
31
31
|
class DownloadValidator < ::ActiveModel::EachValidator
|
32
32
|
|
33
33
|
def validate_each(record, attribute, value)
|
34
|
-
if e = record.
|
34
|
+
if e = record.__send__("#{attribute}_download_error")
|
35
35
|
message = (e.message == e.class.to_s) ? :carrierwave_download_error : e.message
|
36
36
|
record.errors.add(attribute, message)
|
37
37
|
end
|
data/lib/carrierwave/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: carrierwave
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonas Nicklas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -86,28 +86,28 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 2.3
|
89
|
+
version: '2.3'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: 2.3
|
96
|
+
version: '2.3'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: rspec
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: 3.4
|
103
|
+
version: '3.4'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: 3.4
|
110
|
+
version: '3.4'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: webmock
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -164,34 +164,20 @@ dependencies:
|
|
164
164
|
- - ">="
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '0'
|
167
|
-
- !ruby/object:Gem::Dependency
|
168
|
-
name: nokogiri
|
169
|
-
requirement: !ruby/object:Gem::Requirement
|
170
|
-
requirements:
|
171
|
-
- - "~>"
|
172
|
-
- !ruby/object:Gem::Version
|
173
|
-
version: 1.6.3
|
174
|
-
type: :development
|
175
|
-
prerelease: false
|
176
|
-
version_requirements: !ruby/object:Gem::Requirement
|
177
|
-
requirements:
|
178
|
-
- - "~>"
|
179
|
-
- !ruby/object:Gem::Version
|
180
|
-
version: 1.6.3
|
181
167
|
- !ruby/object:Gem::Dependency
|
182
168
|
name: timecop
|
183
169
|
requirement: !ruby/object:Gem::Requirement
|
184
170
|
requirements:
|
185
|
-
- -
|
171
|
+
- - ">="
|
186
172
|
- !ruby/object:Gem::Version
|
187
|
-
version: 0
|
173
|
+
version: '0'
|
188
174
|
type: :development
|
189
175
|
prerelease: false
|
190
176
|
version_requirements: !ruby/object:Gem::Requirement
|
191
177
|
requirements:
|
192
|
-
- -
|
178
|
+
- - ">="
|
193
179
|
- !ruby/object:Gem::Version
|
194
|
-
version: 0
|
180
|
+
version: '0'
|
195
181
|
- !ruby/object:Gem::Dependency
|
196
182
|
name: generator_spec
|
197
183
|
requirement: !ruby/object:Gem::Requirement
|